Backward and Central Difference
古いコメントを表示

Given that x =10 and delta_x = 0.4,
Is there a better way of writing this code?
x = 10;
delta_x = 0.4;
backward_difference = ((2*f(x)-5*f(x-dx)+4*f(x-2*dx)-f(x-3*dx))/dx^2);
central_difference = (-f(x+2*dx)+16*f(x+dx)-30*f(x)+16*f(x-dx)-f(x-2*dx))/(12*(dx^2));
2 件のコメント
Joseph Cheng
2021 年 6 月 11 日
編集済み: Joseph Cheng
2021 年 6 月 11 日
Have you already defined "f" as an anonymous function or symbolic function? Otherwise if "f" is an array you would be indexing "f" in a non-integer value
Anna Lin
2021 年 6 月 11 日
採用された回答
その他の回答 (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!