Question

(16 marks) Consider the initial value problem (a) Without using pre-built commands write an m-file function that uses the fourth-order Runge-Kutta method to estimate the value of y(n) for a given value n and a given step size h (b) Use the m-file function built in part (a) to compute an estimate of y(2) using step size h = 0.5 and h = 0.25. Fron these two estimates, approximate the step size needed to estimate y(2) correct to 4 decimal places, explaining your answer. Compute y(2) using the approximate step size and then with half the approximate step size. Comment on your results. (30 marks)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer for (a):

clc;                                               % Clears the screen

clear all;

h=1.5;                                             % step size

x = 0:h:3;                                         % Calculates up to y(3)

y = zeros(1,length(x));

y(1) = 5;                                          % initial condition

F_xy = @(t,r) t*t- sqrt(t*r);                    % change the function as you desire

for i=1:(length(x)-1)                              % calculation loop

    k_1 = F_xy(x(i),y(i));

    k_2 = F_xy(x(i)+0.5*h,y(i)+0.5*h*k_1);

    k_3 = F_xy((x(i)+0.5*h),(y(i)+0.5*h*k_2));

    k_4 = F_xy((x(i)+h),(y(i)+k_3*h));

    y(i+1) = y(i) + (1/6)*(k_1+2*k_2+2*k_3+k_4)*h; % main equation

Add a comment
Know the answer?
Add Answer to:
(16 marks) Consider the initial value problem (a) Without using pre-built commands write an m-file function...
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