Question: Take you same derivate function from last week and let's make it more general by passing in f ( x ) , and x You
Take you same derivate function from last week and let's make it more general by passing in fx and x
You derivative function will now look something like this mydercalc fxNeps, option
eps is a tolerance for determining the accuracy of your derivatives. We will use this later
To test, let's use our function from last laboratory class, xx
The output argument, df should be the numerical derivatives computed for x according to the method
defined by the input argument, option
Remember, the forward difference method "loses" the last point, the backward difference method loses the
first point, and the central difference method loses the first and last points. So you have use some
interpolation to get these points. Try linear
By obtaining the derivative at the first and last point, you will have the exact same number of values for
both df and x Although, you could set them to same value as well, however, your plot will only be linear
for the interior points
Plot dfvs x notice the functional form of your plot.
Compare with the actual form with the derivative of the given function, if the calculated derivative is not
within times of the given function derivative add more points until the calculated derivative is less
than or equal to times of the given function's derivative
Next, add to you derivative function the capability to check for accuracy by comparing maximum errors between successive calculations of the derivative. You will need a while loop that checks when the maximum error is eps. To find the maximum array create a numpy array in your derivative function. Call it "maxe" where each element of the array would contain djx; dxi j refers to the finer grid where the j grid would use twice as many points as the j grid. For example, j the starting grid would have N points, and the j grid would use N points, the j grid would use points and so on Now for the st pass through the whileloop you cannot converge you haven't started the comparison. So construct you code to avoid this situation. For this part of the laboratory, let's use for our function, fx x logx
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
