Error in Exact solution and numerical Solution

1 回表示 (過去 30 日間)
Muhammad Usman
Muhammad Usman 2015 年 4 月 27 日
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 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by