`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
Kindly revert for any queries
Thanks.
Write a MATLAB Code to 8.5 (9) LAB. Implement the classical procedure (8.82), and apply it...
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 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...