I have a given formmula: Yprimenum(i) = (Y(i+1) – Y(i)) / ∆X, where ∆X is the X step length, or equivallently X(i) – X(i-1). And I also have two given functions: X= [0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 ] Y= [5 6 7 7.5 7.5 7.5 6.5 2.5 -5 -6 -6]
Now my task is to plot this function, Y, and calculate and plot the corresponding Yprimenum in the same graph. This is what I tried:
x= [0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 ] y= [5 6 7 7.5 7.5 7.5 6.5 2.5 -5 -6 -6] yprime=2.*x; Yprimenum=zeros(1, length(x)-1); for i= 1:length(x)-1; Yprimenum(i)=(y(i+1)-y(i))./(x(i+1)-x(i)); end figure; hold on; plot(x,y); plot(x,yprime); plot(x,Yprimenum(i)); hold off; shg;
Best Answer