Question

Problem 1. (15 points) Solve the following system of ODEs using your Euler implementation and ode45 and compare the errors at

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Problem 1:

Programming code in MATLAB

---------------------- ode45

---------------------- let
f=@(t,y) [ y(1)-y(2); -y(1)-y(2)];
tspn=[0 1];
y0=[0 4];
tol=10^(-6);
[t,ya]=ode45(f,tspn,y0,tol);
disp('using ode45 :');
disp(ya(end,:));


--------------------- Euler method
h=0.1;
t1=0:h:1;
%%% let x=y(1), y=y(2)
f1=@(x ,y) x-y;
f2=@(x ,y) -x-y;
x(1)=0;
y(1)=4;
for k=1:length(t1)
x(k+1)=x(k)+h*feval(f1,x(k),y(k));
y(k+1)=y(k)+h*feval(f2,x(k),y(k));
end


sol=[x(end) y(end)];
disp('using Eular :');
disp(sol);
err=sum((ya(end,:)-[x(end) y(end)]).^2);
fprintf('Error in vector : %f \n',err);

MATLAB O/P:

using ode45 :
-5.4732 3.2395

using Euler :
-5.7950 3.1479

Error in vector : 0.111941

---------------------- Exact solution

clc;
clear all;
close all;
syms s
A=[1 -1;-1 -1];
x0=[0;4];
tf=s*eye(2)-A;
gh=ilaplace(inv(tf)*x0);
subs(gh,1)
disp('Exact solution :');
disp(gh);
disp('at t=1');
sol=subs(gh,1);
fprintf('solution is[%f , %f ] : \n',sol(1),sol(2));

MATLAB O/P:


ans =

-2*2^(1/2)*sinh(2^(1/2))
4*cosh(2^(1/2)) - 2*2^(1/2)*sinh(2^(1/2))

Exact solution :
-2*2^(1/2)*sinh(2^(1/2)*t)
4*cosh(2^(1/2)*t) - 2*2^(1/2)*sinh(2^(1/2)*t)

at t=1
solution is[-5.473195 , 3.239539 ] :
>> err

Solut ion - iven that Sem f : U 0 3 30 Coo is onyPind eigen vaing of 3 2. 1 3 s unsob b

Add a comment
Know the answer?
Add Answer to:
Problem 1. (15 points) Solve the following system of ODEs using your Euler implementation and ode...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT