Question

In: Advanced Math

Please make a little adjust for the following script then make it work for Runge Kutta...

Please make a little adjust for the following script then make it work for

Runge Kutta method

Consider the initial value problem

du/dt=t^5   u(0)=0

0<=t<=1

Q1. how we change the below script to make it to solve the above IVP and the answer should be near 4

here is the script

f =@(t ,y)(t^5); % define f by f(t,y)=y^5
for k =1:10
[ tlist , ylist ]= RKfour174 (f ,0 ,1 ,0, 2^k);
error1 (k)= max ( abs ( ylist - ( tlist )));
hlist (k) =1/2^k;
end
x= log ( hlist );
y= log ( error1 );
polyfit (x ,y ,1)

function [tlist,ylist] =RungMethod(f,t0,tfinal ,y0,N)     what is the input for N, n is a stepsize

Solutions

Expert Solution

clear all
close all
%function for which Solution have to do
fun=@(t,y) t.^5;
%exact solution
y_ext=@(t) t.^6/6;
%initial guess
tinit=0; yinit=0;
tend=1;

for k=1:10
    [t_rk,y_rk]=RK4(fun,tinit,yinit,tend,2^k);
    y_exact=double(y_ext(t_rk));
    error(k)=norm(y_exact-y_rk);
    hlist(k)=1./2.^k;
    fprintf('\tFor n=%d value of u(%2.2f) is %f\n',2^k,t_rk(end),y_rk(end))
end
x=log(hlist);
y=log(error);

plot(x,y)
ylabel('log(error)')
xlabel('log(hlist)')
title('error vs. step size plot')
p=polyfit(x,y,1);
fprintf('\npolyfit values are p=%f and %f\n',p(1),p(2))

%%Matlab function for Runge Kutta Method
function [t_rk,y_rk]=RK4(f,tinit,yinit,tend,n)
    %Euler method
    % h amount of intervals
    t=tinit;         % initial t
    y=yinit;         % initial y
    t_eval=tend;     % at what point we have to evaluate
    h=(t_eval-t)/n; % 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 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....
Prompt: Produce a 4th order Runge Kutta code in PYTHON that evaluates the following second order...
Prompt: Produce a 4th order Runge Kutta code in PYTHON that evaluates the following second order ode with the given initial conditions, (d^2y/dt^2) +4(dy/dt)+2y=0, y(0)=1 and y'(0)=3. After your code can evaluate the 2nd order ode, add a final command to plot your results. You may only use python.
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
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)
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.
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.
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...
1)Select all that applies to the Fourth-order Runge-Kutta (RK4) method K subscript 1 equals f left...
1)Select all that applies to the Fourth-order Runge-Kutta (RK4) method K subscript 1 equals f left parenthesis t subscript k comma y subscript k right parenthesis K subscript 2 equals f left parenthesis t subscript k plus h over 2 comma space y subscript k plus h over 2 space K subscript 1 right parenthesis K subscript 3 equals f left parenthesis t subscript k plus h over 2 comma space y subscript k plus h over 2 space K...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT