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 CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by