MATLAB Code:
close all
clear
clc
k = 0:1:5;
H = 0.1 * 2.^(-k);
f = @(t,y) t; % Given ODE
y_exact = @(t) 1 + t^2 / 2;
y(1) = 1; % Initial condition
ti = 0; tf = 1; % Interval of t
yf_vec = []; % Vector for storing y(t = 1) for different step
sizes
for i = 1:length(H)
h = H(i);
t = ti:h:tf;
for j = 1:length(t)-1
k1 = f(t(j), y(j));
k2 = f(t(j) + 0.5*h, y(j) + 0.5*h*k1);
k3 = f(t(j) + 0.5*h, y(j) + 0.5*h*k2);
k4 = f(t(j) + h, y(j) + k3*h);
y(j + 1) = y(j) + (1/6)*(k1 + 2*k2 + 2*k3 + k4)*h; % RK4
Update
end
yf_vec = [yf_vec, y(end)]; % Store the value of y(t = 1)
end
figure, loglog(H, abs(y_exact(1) - yf_vec), 'o-'), xlabel('h'),
ylabel('Error')
title(sprintf('Log-Log plot of Error of RK4 Method at t = 1\nODE:
y'' = t'))
f = @(t,y) 2*(t + 1)*y; % Given ODE
y_exact = @(t) exp(t^2 + 2*t);
y(1) = 1; % Initial condition
ti = 0; tf = 1; % Interval of t
yf_vec = []; % Vector for storing y(t = 1) for different step
sizes
for i = 1:length(H)
h = H(i);
t = ti:h:tf;
for j = 1:length(t)-1
k1 = f(t(j), y(j));
k2 = f(t(j) + 0.5*h, y(j) + 0.5*h*k1);
k3 = f(t(j) + 0.5*h, y(j) + 0.5*h*k2);
k4 = f(t(j) + h, y(j) + k3*h);
y(j + 1) = y(j) + (1/6)*(k1 + 2*k2 + 2*k3 + k4)*h; % RK4
Update
end
yf_vec = [yf_vec, y(end)]; % Store the value of y(t = 1)
end
figure, loglog(H, abs(y_exact(1) - yf_vec), 'o-'), xlabel('h'),
ylabel('Error')
title(sprintf('Log-Log plot of Error of RK4 Method at t = 1\nODE:
y'' = 2(t + 1)y'))
f = @(t,y) 5 * t^4 * y; % Given ODE
y_exact = @(t) exp(t^5);
y(1) = 1; % Initial condition
ti = 0; tf = 1; % Interval of t
yf_vec = []; % Vector for storing y(t = 1) for different step
sizes
for i = 1:length(H)
h = H(i);
t = ti:h:tf;
for j = 1:length(t)-1
k1 = f(t(j), y(j));
k2 = f(t(j) + 0.5*h, y(j) + 0.5*h*k1);
k3 = f(t(j) + 0.5*h, y(j) + 0.5*h*k2);
k4 = f(t(j) + h, y(j) + k3*h);
y(j + 1) = y(j) + (1/6)*(k1 + 2*k2 + 2*k3 + k4)*h; % RK4
Update
end
yf_vec = [yf_vec, y(end)]; % Store the value of y(t = 1)
end
figure, loglog(H, abs(y_exact(1) - yf_vec), 'o-'), xlabel('h'),
ylabel('Error')
title(sprintf('Log-Log plot of Error of RK4 Method at t = 1\nODE:
y'' = 5t^4y'))
f = @(t,y) t^3 / y^2; % Given ODE
y_exact = @(t) (3 * t^4 / 4 + 1)^(1/3);
y(1) = 1; % Initial condition
ti = 0; tf = 1; % Interval of t
yf_vec = []; % Vector for storing y(t = 1) for different step
sizes
for i = 1:length(H)
h = H(i);
t = ti:h:tf;
for j = 1:length(t)-1
k1 = f(t(j), y(j));
k2 = f(t(j) + 0.5*h, y(j) + 0.5*h*k1);
k3 = f(t(j) + 0.5*h, y(j) + 0.5*h*k2);
k4 = f(t(j) + h, y(j) + k3*h);
y(j + 1) = y(j) + (1/6)*(k1 + 2*k2 + 2*k3 + k4)*h; % RK4
Update
end
yf_vec = [yf_vec, y(end)]; % Store the value of y(t = 1)
end
figure, loglog(H, abs(y_exact(1) - yf_vec), 'o-'), xlabel('h'),
ylabel('Error')
title(sprintf('Log-Log plot of Error of RK4 Method at t = 1\nODE:
y'' = t^3/y^2'))
Plots:
use Matlab y'=t, y0)=1, solution: y(t)=1+t/2 y' = 2(1 +1)y, y(0)=1, solution: y(t) = +24 v=5"y,...
(Matlab) Use Matlab's built-in Runge-Kutta function ode45 to solve the problem 1010y -xz +28x - y 3 on the interval t є [0, 100 with initial condition (z(0), y(0),z(0)) = (1,1,25), and plot the trajectory of the solution ((t), (t)) forte [0, 100
(Matlab) Use Matlab's built-in Runge-Kutta function ode45 to solve the problem 1010y -xz +28x - y 3 on the interval t є [0, 100 with initial condition (z(0), y(0),z(0)) = (1,1,25), and plot the trajectory of the...
///MATLAB/// Consider the differential equation over the
interval [0,4] with initial condition y(0)=0.
3. Consider the differential equation n y' = (t3 - t2 -7t - 5)e over the interval [0,4 with initial condition y(0) = 0. (a) Plot the approximate solutions obtained using the methods of Euler, midpoint and the classic fourth order Runge Kutta with n 40 superimposed over the exact solution in the same figure. To plot multiple curves in the same figure, make use of the...
1 st s2, y(1)1 The exact solution is given by yo) - = . 1+Int Write a MATLAB code to approximate the solution of the IVP using Midpoint (RK2) and Modified Euler methods when h [0.5 0.1 0.0s 0.01 0.005 0.001]. A) Find the vector w mid and w mod that approximates the solution of the IVP for different values of h. B) Plot the step-size h versus the relative error of both in the same figure using the LOGLOG...
Given the initial-value problem y'=2-2tyt2+1, 0 ≤t≤1, y0=1 With exact solution yt= 2t+1t2+1 Using MATLAB use Euler’s method with h = 0.1 to approximate the solution of y
use
matlab
Assignment: 1) Write a function program that implements the 4th Order Runge Kutta Method. The program must plot each of the k values for each iteration (one plot per k value), and the approximated solution (approximated solution curve). Use the subplot command. There should be a total of five plots. If a function program found on the internet was used, then please cite the source. Show the original program and then show the program after any modifications. Submission...
Please answer with Matlab Programming that can be copied and pasted
when doing the Matlab part
4 part 2
4. Please finish the following Matlab code for solving the ODE: dy 2(1+t) dt I.C. y(0) = 0 with the multi-step 4th order Milne's Method, and apply 4th order Runge Kutta method to the first 4 points (1 boundary point and the next 3 points). (Hint: 4th order Milne's Method Predictor: Jon = Y-3 + H25,- fia+2f1-2) h Corrector: Y:-1 =...
ME 32200 Programming course (MATLAB)
4. Please finish the following Matlab code for solving the ODE: dy = y(1+1) dt I.C. y(0) = 0 with the multi-step 4th order Milne's Method, and apply 4th order Runge Kutta method to the first 4 points (1 boundary point and the next 3 points). (Hint: 4th order Milne's Method Predictor: 7i+ = Y-3 +h(2f;- fi- +25,-2) Corrector: y = y + + +0. +45j + fi-) Where f; = f(t;,y,) and Fit =...
answer fast please
2. For y'=(1+4x)/7, and y(0)=0.5 a) Use the Euler method to integrate from x=0 to 0.5 with h=0.25. (10 pts) b) Use the 4th order Runge-Kutta method to numerically integrate the equation above for x=0 to 0.25 with h=0.25. (15 pts) Euler Method 91+1 = y + oh where $ = = f(ty 4th Order Runge-Kutta Method 2+1= ++ where $ = (ką + 2k2 + 2kg + ks) ky = f(tuy) k2 = f(t+1,91 +{kxh) kz...
Implement the 4th order Runge-Kutta algotithm in MATLAB. Use the script you produced to integrate the following function x(t)--10t + e-t , x(0)--1; t.-0 t, = 1 Vary At and observe the difference in your results. Let At 0.2 sec., 0.1 sec., 0.05 sec. and 0.01 sec. Now integrate the function analytically and compare your result with the results obtained numerically
Implement the 4th order Runge-Kutta algotithm in MATLAB. Use the script you produced to integrate the following function x(t)--10t...
Complete using MatLab
1. Consider the following initial value problem 3t2-y, y(0) = 1 Using Euler's Method and the second order Runge-Kutta method, for t E [0, 1] with a step size of h 0.05, approximate the solution to the initial value problem. Plot the true solution and the approximate solutions on the same figure. Be sure to label your axis and include an a. appropriate legend b. Verify that the analytic solution to the differential equation is given by...