Value for Function with 2nd order Central difference scheme
古いコメントを表示

I am trying to write code for the above problem but getting wrong answer, Kindly help me to find the error in the code or suggest if there is any better alternate way to write code for the problem.
Right answer is 2.3563
c=1.5;
h=0.1;
x=(c-h):h:(c+h);
Fun=@(x) exp(x)-exp(-x)/2;
dFun=@(x) 2*exp(x)+2*exp(-x)/2;
F=Fun(x);
n=length(x);
dx= (F(:,end)-F(:,1))/(2*h)
採用された回答
その他の回答 (1 件)
Anu
2023 年 9 月 30 日
0 投票
- c is the central point.
- h is the step size.
- x is a vector of values around c.
- Fun is the function you want to calculate the derivative for.
- F is the function values at the points in x.
- dx calculates the derivative at the central point c using finite differences.
カテゴリ
ヘルプ センター および File Exchange で Matrix Computations についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!