Right code for Centred finite difference?

6 ビュー (過去 30 日間)
Sakusan Puwanendran
Sakusan Puwanendran 2017 年 11 月 24 日
Is this the right code to find the Centred finite difference and plot it on a graph? My plot looks wrong. The centred difference is in yellow
y=2*cos(3*x)-x.^2+7*x-6;
diff(y,x)
dydx_actual=diff(y,x)
clear x
h=0.1;
x=0:h:6;
%CFD
dydx_cfd=(y(3:end)-y(1:end-2))./h;
plot(x(2:end-1),dydx_cfd,'y')

回答 (0 件)

カテゴリ

Help Center および File ExchangeComputational Fluid Dynamics (CFD) についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by