Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Matlab: I'd like to apply y''+2y'+3y=e^(-2t) where y(0)=0, y'(0)=0 and y''-t^2*y'-2ty = 1 where y(0)=1, y'(0)=0 but how can we pass them for this program?

Matlab:

I'd like to apply y''+2y'+3y=e^(-2t) where y(0)=0, y'(0)=0 and y''-t^2*y'-2ty = 1 where y(0)=1, y'(0)=0 but how can we pass them for this program? since I don't fully understand f = @f(t,y)[0 1; -1 ....] here.

Please write @f(t,y) for them and appreciate if you explain how this function works.

I will thumb up if the solution seems corret, thank you :)

===============================================

function test()

a = 0;

b = 1;

%n = input('Enter the number of intervals:');

y = [2; -2];

t = 0:h:n*h;

% Define the function as an anonymous function

f = @(t,y) [0 1; -1 -exp(-3*t)]*y + [0; (5-2*exp(-3*t))*exp(-2*t)+1];

for i=1:n

k1 = f(t(i),y(:,i));

k2 = f(t(i)+0.5*h,y(:,i)+0.5*k1*h);

k3 = f(t(i)+h,y(:,i)-k1*h+2*k2*h);

y(:,i+1)= y(:,i)+h/6*(k1+4*k2+k3); %approximated value of the ODE using RK3

end

exact = exp(-2*t)+1;

disp(max(abs(exact-y(1,:))))

plot(t,y(1,:),'r',t,exact,'b--'),grid

xlabel('t'),ylabel('y')

legend('RK3','Exact')

end

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications Dexa 2023 Workshops 34th International Conference Dexa 2023 Penang Malaysia August 28 30 2023 Proceedings

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Atif Mashkoor ,Johannes Sametinger ,Maqbool Khan

1st Edition

303139688X, 978-3031396885

More Books

Students also viewed these Databases questions