Error in Exact solution and numerical Solution
1 回表示 (過去 30 日間)
古いコメントを表示
Hi I am solving a 2nd order linear ODE using Forward Scheme Finite Difference Method and also computing the Exact solution and plot these 2 curves,but there is very much error in my curves. Please follow my code and mention my mistake in either computing forward scheme or some else.
clear all;clc;
t0 = 0;
y0 = 0;
Dt = 0.01;
tn = 1;
t = t0:Dt:tn;
n = (tn-t0)/Dt +1;%length(x);
y = zeros(1,n);
% Second Order ODE
for j = 1:n-2
y(j+2) = -(1-Dt)*y(j)+(Dt^2)*t(j)*exp(3*t(j))+(2-Dt)*(y(j)+Dt);
end;
plot(t,y,'b:');
hold on;
% Exact Solution
y1=(10/9)-(7/144).*exp(3.*t)+(1/12).*t.*exp(3.*t)-(17/16).*exp(-t);
plot(t,y1,'r-');
0 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!