Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Matlab!! I have such function for Runge-Kutta method (3rd order) for 2nd differential equations but the following code will only work with specific function. Could

Matlab!!

I have such function for Runge-Kutta method (3rd order) for 2nd differential equations but the following code will only work with specific function. Could you fix this code so that I can pass any 2nd differential equations as argument?? Ex:

If it is clear, I will thumb up for sure :)

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

a = 0;

b = 1;

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

y = [2; -2];

t = 0:h:n*h;

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')

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

function fty = Ex(t,y)

Y = [0 1; -1 -exp(-3*t)]*y;

u = [0; (5-2*exp(-3*t))*exp(-2*t)+1];

fty = Y + u;

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

Step: 3

blur-text-image

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

Transactions On Large Scale Data And Knowledge Centered Systems Xxxviii Special Issue On Database And Expert Systems Applications Lncs 11250

Authors: Abdelkader Hameurlain ,Roland Wagner ,Sven Hartmann ,Hui Ma

1st Edition

3662583836, 978-3662583838

More Books

Students also viewed these Databases questions