Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

5.24 The derivative of a continuous function f(x) in a sampled function is f \'

ID: 1858655 • Letter: 5

Question

5.24



The derivative of a continuous function f(x) in a sampled function is


f ' (xi) = (f(xi+1 ) - f(xi))/ delta x



where delta x = xi+1 - xi. Assume that a vector vect contains nsamp samples of a function taken at a

spacing of dx per sample. Write a function that will calculate the derivative of this vector from the given equation. the function should check to make sure that dx is greather than zero to prevent divide by zero errors in the function.


To check your function, you should generate a data set whose derivative is known and compare the result of the function with the known correct answer. A good choice for a test function is sin(x). From elementary calculus we know that dsin(x)/dx = cos(x). Generate an input vector containing 100 values of the function sin(x) starting at x = 0 and using a step size delta x of 0.05. Take the derivative of the vector with your function and then compare the resulting answers to the known correct answer. How close did your function come to calculating the correct value for the dervative.



Explanation / Answer

for i=1 : 100

f(i)=sin(.05*i) ; % Generates Function

end

% now calculating Derivative

for i=1 : 99

m(i)=i;

fdash(i)=(f(i+1)-f(i))/.05 ; ýashash is the calculated derivative

fdashact(i)=cos(0.5i); % fdashact is the actual derivative which is cosx

end

plot(fdash,m,fdashact,m)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote