2nd 3rd derivatives

9 vues (au cours des 30 derniers jours)
Muhammad Rohaan
Muhammad Rohaan le 1 Oct 2022
Modifié(e) : Torsten le 2 Oct 2022
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

Réponse acceptée

Matt J
Matt J le 1 Oct 2022
Modifié(e) : Matt J le 1 Oct 2022
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))

Plus de réponses (1)

Torsten
Torsten le 1 Oct 2022
Modifié(e) : Torsten le 2 Oct 2022
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

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by