Question

In: Advanced Math

Use the Runge-Kutta method and the Runge-Kutta semilinear method with the indicated step sizes to find...

Use the Runge-Kutta method and the Runge-Kutta semilinear method with the indicated step sizes to find approximate values of the solution of the given initial value problem at 11 equally spaced points (including the endpoints) in the interval. This question is from the differential equation.

y'-4y = x/y^2(y+1) , y(0) = 1; h=0.1, 0.05 , 0.025, on [0, 1]

Solutions

Expert Solution


clear all
close all

%function for which RK4 method have to calculate
f=@(x,y) 4.*y+(x./((y.^2).*(y+1)));
fprintf('function for which RK4 method have to calculate f(x,y)= ')
disp(f)
%all h
h=[0.1 0.05 0.025];
    %step size h
    %initial value
    y0=1; x0=0;
  
    xx=0:0.1:1;
    fprintf('\tx\ty_h=0.1 \ty_h=0.05 \ty_h=0.025\n')
    for it=1:length(xx)
        x_end=xx(it);
        [t_result1,y1_result1] = RK4_method(f,y0,x0,x_end,h(1));
        [t_result2,y1_result2] = RK4_method(f,y0,x0,x_end,h(2));
        [t_result3,y1_result3] = RK4_method(f,y0,x0,x_end,h(3));
        fprintf('\t%2.2f \t%f\t%f\t%f\n',t_result1(end),y1_result1(end),y1_result2(end),y1_result3(end))
    end

%%Matlab function for Runge Kutta Method
function [t_rk,y_rk]=RK4_method(f,yinit,tinit,tend,h)
    % RK4 method
    % h amount of intervals
    t=tinit;         % initial t
    y=yinit;         % initial y
    t_eval=tend;     % at what point we have to evaluate
    n=(t_eval-t)/h; % Number of steps
    t_rk(1)=t;
    y_rk(1)=y;
    for i=1:n
    %RK4 Steps
       k1=h*double(f(t,y));
       k2=h*double(f((t+h/2),(y+k1/2)));
       k3=h*double(f((t+h/2),(y+k2/2)));
       k4=h*double(f((t+h),(y+k3)));
       dy=(1/6)*(k1+2*k2+2*k3+k4);
       t=t+h;
       y=y+dy;
       t_rk(i+1)=t;
       y_rk(i+1)=y;
    end
end

%%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%


Related Solutions

Use the Runge-Kutta method with step sizes h = 0.1, to find approximate values of the...
Use the Runge-Kutta method with step sizes h = 0.1, to find approximate values of the solution of y' + (1/x)y = (7/x^2) + 3 , y(1) = 3/2 at x = 0.5 . And compare it to thee approximate value of y = (7lnx)/x + 3x/2
Using Runge-Kutta method of order 4 to approximate y(1) with step size h = 0.1 and...
Using Runge-Kutta method of order 4 to approximate y(1) with step size h = 0.1 and h = 0.2 respectively (keep 8 decimals): dy/dx = x + arctan y, y(0) = 0. Solutions: when h = 0.1, y(1) = 0.70398191. when h = 0.2, y(1) = 0.70394257.
Use Classic Runge-Kutta method with h = 1 to solve the system y” - y’ -...
Use Classic Runge-Kutta method with h = 1 to solve the system y” - y’ - 6y = 0, y(0) = 2, y’(0) = 3 on [0,1]
Problem Four (12 Marks) Use Runge Kutta method of order four to approximate the solution of...
Problem Four Use Runge Kutta method of order four to approximate the solution of the initial value problem ?′ + 2? = ??3?, 0 ≤ ? ≤ 1, ?(0) = 0, ???ℎ ℎ = 0.5 Hint: Compute ?(0.5) ??? ?(1)
Use 3 steps of the Runge-Kutta (fourth order) method to solve the following differential equation to...
Use 3 steps of the Runge-Kutta (fourth order) method to solve the following differential equation to t = 2.4, given that y(0) = 2.3. In your working section, you must provide full working for the first step. To make calculations easier, round the tabulated value of y at each step to four decimal places. a) Provide the four K-values that are calculated at the first step, with four decimal places. b) Provide your answer for y(2.4) with four decimal places....
use Runge Kutta 4th order method y'=y-1.3333*exp(0.6x) a) h=2.5 and compare the value to the exact...
use Runge Kutta 4th order method y'=y-1.3333*exp(0.6x) a) h=2.5 and compare the value to the exact value b) h=1.25 and compare the value to the exact value Thks!
Q 4. With the aid of fourth order Runge-Kutta method, solve the competing species model [20...
Q 4. With the aid of fourth order Runge-Kutta method, solve the competing species model [20 points] defined by dx =x(2 − 0.4x − 0.3y), x(0) = 4 dt dy =y(1 − 0.1y − 0.3x), y(0) = 3 dt where the populations x(t) and y(t) are measured in thousands and t in years. Use a step size of 0.2 for 0 ≤ t ≤ 2 and plot the trajectories of the populations with Matlab or GNU Octave.
With the aid of fourth order Runge-Kutta method, solve the competing species model defined by dx/dt...
With the aid of fourth order Runge-Kutta method, solve the competing species model defined by dx/dt =x(2 − 0.4x − 0.3y), x(0) = 2 dy/dt =y(1 − 0.1y − 0.3x), y(0) = 4 where the populations x(t) and y(t) are measured in thousands and t in years. Use a step size of 0.2 for 0 ≤ t ≤ 2 and plot the trajectories of the populations with Matlab or GNU Octave.
Write a user-defined MATLAB function that uses classical fourth order Runge-Kutta method to solve a first...
Write a user-defined MATLAB function that uses classical fourth order Runge-Kutta method to solve a first order ODE problem dydx = f(x, y) in a given interval a ? x ? b with initial condition y(a) = y0 and step size of h. For function name and arguments, use [x,y] = myrk4(f, a, b, h, y0) Check your function to find the numerical solution for dydx=?1.2y+7e^(?0.3x) in the interval 0 ? x ? 4 with initial condition y(0)=3. Run your...
Exercise (a) Use Euler's method with each of the following step sizes to estimate the value...
Exercise (a) Use Euler's method with each of the following step sizes to estimate the value of y(1.6), where y is the solution of the initial-value problem y' = y, y(0) = 6. (i)    h = 1.6 (ii)    h = 0.8 (iii)    h = 0.4 Exercise (b) We know that the exact solution of the initial-value problem in part (a) is y = 6ex. Draw, as accurately as you can, the graph of y = 6ex, 0 ≤ x ≤ 1.6, together with...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT