Matlab Script Accuracy of Results
이전 댓글 표시
I'm trying to write a Matlab script that shows the order of accuracy of the forward and central differencing methods for the first derivative of f = exp (x) at x = 0. The graph attached is the result I'm looking for.
Here is what I have so far in forward differencing method but I'm kinda stuck. Can you show me where I made my mistakes.
clear all
close all
delx = 1;
x = 0;
y = exp(x);
fig = figure();
set(fig,'color','white')
plot(x,y,'LineWidth',2)
xlabel('x')
ylabel('y')
grid on
yderiv = exp(x);
fig = figure();
set(fig,'color','white')
plot(x,yderiv,'LineWidth',2)
xlabel('x')
ylabel('y')
grid on
%%%Forward Differencing
yderivest = (y(2:end) - y(1:end-1))./delx;
hold on
plot(x(2:end)-delx/2,yderivest,'r-','LineWidth',2)
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!