Write Matlab code for Numerical Differentiation using Newton Forward, Backward, and Lagranges formulas?

Fun = @(x) exp(-x).*sin(3*x);
dFun = @(x) -exp(-x).*sin(3*x)+ 3*exp(-x).*cos(3*x);
x=linspace(0,4,101);
F=Fun(x);
h=x(2)-x(1);
xCentral=x(2:end-1);
dFCenteral=(F(3:end)-F(1:end-2))/(2*h);
xForward=x(1:end-1);
dFForward=(F(2:end)-F(1:end-1))/h;
xBackward=x(2:end);
dFBackward=(F(2:end)-F(1:end-1))/h;
plot(x,dFun(x));
hold on
plot(xCentral,dFCenteral,'r')
plot(xForward,dFForward,'k');
plot(xBackward,dFBackward,'g');
legend('Analytic','Central','Forward','Backward')

3 件のコメント

What is your question? if your code works, then why are you posting your homework? So you must have a question in this somewhere.
Actually, I need separate codes for forward, backward and lagrange formula of numerical differentiation.
Not for plot, but to run the codes

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSignal Processing Toolbox についてさらに検索

製品

リリース

R2017a

質問済み:

2020 年 7 月 28 日

コメント済み:

2020 年 7 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by