How do I solve using centered finite difference formula?

15 ビュー (過去 30 日間)
Mohd Aniq Akmal Maludin
Mohd Aniq Akmal Maludin 2017 年 12 月 28 日
編集済み: Philipp Doblhofer 2017 年 12 月 30 日
%Boundary conditons
y(0) = 1;
y(5) = 6;
h = 2 %Step size
Centered difference formula;
d2y = (y(i+1) - 2y(i) + y(i-1)) / h^2;
dy = (y(i+1) - y(i-1))/2*h;
for i = 2:4
r(i+1) = r(i) + h;
r(i)*(d2y) + 3*(dy)+10*r(i) = 0
end
for i = 1:5
fprintf('%7.3f %10.3f \n', r(i), y(i)
end
I am expecting the program to print the value of y(i). But I can't run the program.
  3 件のコメント
Mohd Aniq Akmal Maludin
Mohd Aniq Akmal Maludin 2017 年 12 月 30 日
Hello Phillip,
I am trying to calculate the value of y(2), y(3) and y(4) based on the equation in the for-loop.
Philipp Doblhofer
Philipp Doblhofer 2017 年 12 月 30 日
編集済み: Philipp Doblhofer 2017 年 12 月 30 日
Hello,
You have to do two steps:
1) Calculate dy and d2y for all values of i (1 to 4). The result should be a vector, not a scalar value (like your sample code would suggest)
2) For each i-value you have a system of linear equations. You have to solve them. (y(i) = ...)

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by