18 Solve Exercise 1 with fourthorder RungeKutta method How l
18. Solve Exercise 1 with fourth-order Runge-Kutta method. How large can h be to get the correct value at x = 1.0, which is 2.19496?
1. Use the Taylor series method to get solutions to dyldx = x + y - xy, y(0) = 1 at x = 0.1 and x = 0.5. Use terms through x5.
Can you solve this problem by using matlab code? I need mat lab answer not excel
Solution
using RK method
clc;
clear all;
h=0.2; % step size
x = 0:h:1;
y = zeros(1,length(x));
y(1) = 1; % initial condition
F_xy = @(x,y) x+y-x*y;
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;
end
y =
1.0000 1.2184 1.4652 1.7237 1.9739 2.1949
