2nd 3rd derivatives
조회 수: 9 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
추가 답변 (1개)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!