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!