HW2 phy 286

0 comments

  • All code must be uploaded via canvas.
    • You can ONLY upload files with specified (allowed) filename extensions
    • Only one submission needed per team (One member can upload)
  • Grading will consist of using the following criteria:
    • Accuracy and correctness of code input/output: 30%
    • Clarity and legibility of code: 20%
    • Use of comments, annotation and help provided to use the code: 20%
    • Logic, computational approach or design used: 30%
  • Uploading code that does not work, needs manual corrections for execution, or code with invalid MATLAB variable names, scripts or functions will lose at least 40-50% of assigned points.
  • Label plots clearly so it is easy/obvious to understand what is being done
  • Comment your code
  • Display calculations and/or output (in Command Window) so it is easily readable.
  • Test your code before submitting.

===================================================================

Problem 1 [50 points]: Calculating second derivatives.

In class, we examined how it is possible to compute forward, backward or central differences to calculate the derivatives of a function with one variable. Here, you will extend that approach to calculate the second derivative of a given function.

For a given set of vector inputs LaTeX: left[x,:fleft(xright)right][ x , f ( x ) ], construct a script (HW2problem1.m) that calculates the absolute mean error in LaTeX: f''left(xright)f ( x ) for a specified range of values LaTeX: xx. Calculate LaTeX: f''left(xright)f ( x ) by calling functions forward_fprime.m, backward_fprime.m and/or central_fprime.m, twice. There are 9 possible ways to then numerically calculate the second derivative of LaTeX: fleft(xright)f ( x ).

Your script should output the mean absolute error LaTeX: left|f''_{true}left(xright)-f''_{num}left(xright)right|| f t r u e ( x ) f n u m ( x ) | when LaTeX: fleft(xright)=logleft(xright)f ( x ) = log ( x ) and for LaTeX: xx defined in MATLAB as:

>> x = linspace(1, 2, 20);

For each of the 9 methods, display clearly how the second derivative was computed and the mean absolute errors computed. For e.g. your display can read:

Second derivative: Forward, Forward, |mean error| = xx.yy;
Second derivative: Forward, Backward: |mean error| = mm.nn;
...

Remember to pay close and careful attention to the range of the returned LaTeX: xx vectors and the first derivatives, while using these functions.

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}