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

 采纳的回答

Matt J
Matt J 2022-10-1
编辑:Matt J 2022-10-1
x = [-2:0.01:1];
y = exp(-3.*x);
dy=gradient(y,0.01);
ddy=gradient(dy,0.01);
plot (x(3:end),ddy(3:end))

更多回答(1 个)

Torsten
Torsten 2022-10-1
编辑:Torsten 2022-10-2
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

类别

帮助中心File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by