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 f(x), and x
You derivative function will now look something like this my_der_calc( f,x,N,eps, 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, x(1-x)
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 df.vs 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 1\times 10^(-3) of the given function derivative add more points until the calculated derivative is less
than or equal to 1\times 10^(-3) 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 |dj+(x;) d^3(xi)|. j +1 refers to the finer grid where the j +1 grid would use twice as many points as the j grid. For example, j =1(the starting grid) would have N =10 points, and the j +1 grid would use 2N =20 points, the j +2 grid would use 40 points and so on. Now for the 1st pass through the while-loop 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, f(x)= x logx

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!