2nd 3rd derivatives
Show older comments
trying to plot first 3 derrivatives for the following function: y = exp(-3.*x)
x = [-2:0.01:1];
y = exp(-3.*x);
dy=diff(y)./diff(x);
d2ydx2=diff(y,2)./diff(x,2);
plot (x(3:end),d2ydx2)
it plots the original function and first derrivative but gives a weird graph for 2nd derrivative
any help would be appriciated
Accepted Answer
More Answers (1)
x = [-2:0.01:1];
y = exp(-3.*x);
dydx = diff(y)./diff(x);
d2ydx2 = diff(dydx)./diff((x(1:end-1)+x(2:end))/2);
d3ydx3 = diff(d2ydx2)./diff(x(2:end-1));
figure(1)
hold on
plot((x(1:end-1)+x(2:end))/2,dydx)
plot((x(1:end-1)+x(2:end))/2,-3*exp(-3*(x(1:end-1)+x(2:end))/2))
hold off
figure(2)
hold on
plot(x(2:end-1),d2ydx2)
plot(x(2:end-1),9*exp(-3*x(2:end-1)))
hold off
figure(3)
hold on
plot((x(2:end-2)+x(3:end-1))/2,d3ydx3)
plot((x(2:end-2)+x(3:end-1))/2,-27*exp(-3*(x(2:end-2)+x(3:end-1))/2))
hold off
Categories
Find more on Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



