Error in Exact solution and numerical Solution
1 view (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!