Question

Write a MATLAB Code to

8.5 (9) LAB. Implement the classical procedure (8.82), and apply it to equation (8.66). Solve it with stepsizes of h = 0.25 a

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

`Hey,

Note: If you have any queries related to the answer please do comment. I would be very happy to resolve all your queries.

clc

clear all

close all

format long

f=@(x,y) -y+2*cos(x);

disp('Solution for h=0.25')

[X1,Y1]=runge4(f,[0,1],1,0.25)

[X2,Y2]=runge4(f,[0,1],1,0.125)

plot(X1,Y1,X2,Y2);

legend('h=0.25','h=0.125')

function [x,y]=runge4(f,tspan,y0,h)

x = tspan(1):h:tspan(2); % Calculates upto y(3)

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

y(1,:) = y0; % initial condition

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

k_1 = f(x(i),y(i,:));

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

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

k_4 = f((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

end

end

Efx 2 E . A=80 1.45 EDIT h=0.25 h=0.125 1.4 CS MATL tor-/Use eee.m X 1.35 y(1,:) 1.3 for i= 125 k_1 = 1.2 k_2 = 1.15 k_3 = 1.

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Write a MATLAB Code to 8.5 (9) LAB. Implement the classical procedure (8.82), and apply it...
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
  • Implement the classical procedure, and apply it to equation, Solve it with step sizes bf h...

    Implement the classical procedure, and apply it to equation, Solve it with step sizes bf h = 0.25 and 0.125 Compare with results in Table 8.13, the fourth order Fehlberg example. 8.5 (9) LAB. Implement the classical procedure (8.82), and apply it to equation (8.66). Solve it with stepsizes of h = 0.25 and 0.125 Compare with results in Table 8.13, the fourth- order Fehlberg example. Y'(x) = -Y(x) + 2 cos(x), Y(0) = 1 (8.66) h Runge-Kutta methods of...

  • LAB. Implement the classical procedure (8.82), and apply it to equation (8.66). Solve it with stepsizes...

    LAB. Implement the classical procedure (8.82), and apply it to equation (8.66). Solve it with stepsizes of h = 0.25 and 0.125. (8.82) h h h Runge-Kutta methods of higher order can also be developed. A popular classical method is the following fourth-order procedure: 01 -f(x,y) V2 = 1 (**+ 2 Yu + 2" h lg = f(x+ Yu + (8.82) V4 = f(x+h, yn + hvy) h Yn+1 = y +7(+202 +223 +24] The truncation error in this method...

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