%%Matlab code for Euler, Mid Point, RK2 and RK4 method
clear all
close all
%Function for which solution have to do
f=@(t,y) y.*t.^2-1.1.*y;
h=0.5; % amount of intervals
fprintf('\nSolution for Euler method using step
size %2.2f.\n',h)
fprintf('Initial condition y(0)=1 at
t=0.\n')
%Euler method
%%%%%%%%%%%%%%%
t=0;
% initial t
y=1;
% initial y
t_eval=2; % at what point
we have to evaluate
n=(t_eval-t)/h; % Number of steps
t2(1)=t;
y2(1)=y;
for i=1:n
%Eular Steps
m=double(f(t,y));
t=t+h;
y=y+h*m;
t2(i+1)=t;
y2(i+1)=y;
fprintf('\t at t=%2.2f
value of y(%2.2f)=%f\n',t2(i+1),t2(i+1),y2(i+1))
end
%Euler method
%%%%%%%%%%%%%%%
h=0.25;
fprintf('\nSolution for Euler method using step
size %2.2f.\n',h)
fprintf('Initial condition y(0)=1 at
t=0.\n')
t=0;
% initial t
y=1;
% initial y
t_eval=2; % at what point
we have to evaluate
n=(t_eval-t)/h; % Number of steps
t3(1)=t;
y3(1)=y;
for i=1:n
%Euler steps
m=double(f(t,y));
y=y+h*m;
t=t+h;
y3(i+1)=y;
t3(i+1)=t;
fprintf('\t at t=%2.2f value
of y(%2.2f)=%f\n',t3(i+1),t3(i+1),y3(i+1))
end
%RK4 method
%%%%%%%%%%%%%%%
h=0.5; % amount of intervals
fprintf('\nSolution for RK4 method using step
size %2.2f.\n',h)
fprintf('Initial condition y(0)=1 at
t=0.\n')
t=0;
% initial t
y=1;
% initial y
t_eval=2; % at what point
we have to evaluate
n=(t_eval-t)/h; % Number of steps
t4(1)=t;
y4(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)));
dx=(1/6)*(k1+2*k2+2*k3+k4);
t=t+h;
y=y+dx;
t4(i+1)=t;
y4(i+1)=y;
fprintf('\t at t=%2.2f value
of y(%2.2f)=%f\n',t4(i+1),t4(i+1),y4(i+1))
end
%Midpoint method
h=0.5;
%%%%%%%%%%%%%%%
fprintf('\nSolution for Midpoint method using
step size %2.2f.\n',h)
fprintf('Initial condition y(0)=1 at
t=0.\n')
t=0;
% initial t
y=1;
% initial y
t_eval=2; % at what point
we have to evaluate
n=(t_eval-t)/h; % Number of steps
t5(1)=t;
y5(1)=y;
for i=1:n
%Midpoint Steps
k1=h*double(f(t,y));
k2=h*double(f((t+h),(y+k1)));
dx=(1/2)*(k1+k2);
t=t+h;
y=y+dx;
t5(i+1)=t;
y5(i+1)=y;
fprintf('\t at t=%2.2f value
of y(%2.2f)=%f\n',t5(i+1),t5(i+1),y5(i+1))
end
%%Exact solution
syms y(t)
eqn = diff(y,t) ==
y*t^2-1.1*y;
cond = y(0) == 1;
ySol(t) =
dsolve(eqn,cond);
fprintf('Exact solution
for given ode is y(t)=')
disp(ySol)
yy_ext(t)=ySol;
fprintf('Initial
condition y(0)=1 at t=0.\n')
for
ii=1:length(t4)
y6(ii)=double(yy_ext(t4(ii)));
fprintf('\t at t=%2.2f value of
y(%2.2f)=%f\n',t4(ii),t4(ii),y6(ii))
end
%%Plotting solution using Euler method
figure(1)
hold on
plot(t2,y2,'Linewidth',2)
plot(t3,y3,'Linewidth',2)
plot(t4,y4,'Linewidth',2)
plot(t5,y5,'linewidth',2)
plot(t4,y6,'linewidth',2)
xlabel('t')
ylabel('y(t)')
title('Solution plot y(t) vs. t')
legend('Euler Method','Euler Method','RK4 Method','Midpoint
Method','Exact solution','Location','northwest')
grid on
%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%
PROBLEMS 22.1 Solve the following initial value problem over the interval from 0to2 where yo) 1.Display all your results on the same graph. dy=vr2-1.ly dt (a) Analytically. (b) Using Euler'...
I need the visual basic code that is supposed to be typed through excel o Solve the following initial value problems with your VBA code over the interval from t 0 to 2 where y(0)1. o Graph the results from each solution method on the same graph. Analytically Euler's method with h 0.5 and h 0.25 Huen's method with h 0.5 and h 0.25 Fourth-order RK with h 0.5 o Solve the following initial value problems with your VBA code...
SOLVE USING MATLAB Problem 22.1A. Solve the following initial value problem over the interval fromt 0 to 5 where y(0) 8. Display all your results on the same graph. dt The analytical solution is given by: y(0) - 4e-0.5t (a) Using the analytical solution. (b) Using Eulers method with h 0.5 and 0.25 (c) Using the midpoint method with h 0.5. (d) Using the fourth-order RK method with h 0.5.
Solve using MATLAB code 22.2 Solve the following problem over the interval from 0 to 1 using a step size of 0.25 where y(0) 1. Display all your results on the same graph. dy dx (a) Analytically (b) Using Euler's method. (c) Using Heun's method without iteration. (d) Using Ralston's method. (e) Using the fourth-order RK method. Note that using the midpoint method instead of Ralston's method in d). You can use my codes as reference.
Solve the following Initial value problem over the Interval from t-0 to 2 where yo)-1 using the following methods dy= yt2_ 1.1y 5. value 15.00 points Fourth-order RK method with h- 0.5 at t-2 O 0.5914 O 1.5845 O 2.7332 O 0.7614
I want Matlab code. 22.2 Solve the following problem over the interval from x = 0 to 1 using a step size of 0.25 where y(0)-1. Display all your results on the same graph. r dV = (1 + 4x) (a) Analytically. (b) Using Euler's method. (c) Using Heun's method without iteration. (d) Using Ralston's method. (e) Using the fourth-order RK method. 22.2 Solve the following problem over the interval from x = 0 to 1 using a step size...
Problem 2. Solve the following pair of ODEs over the interval from 0 to 0.4 using a step size of 0.1. The initial conditions are (0)-2 and (0) 4. Obtain your solution with (a) Euler's method and (b) the fourth-order RK method. Display your results as a plot. dy =-2y+Sze dt dz dt 2
1.Solve the following problem over the interval from t 0 to 1 using a step size of 0.25 where y(0) . Display your results on the same graph. dy dt (1 +4t)vy (a) Euler's method. (b) Ralston's method. 1.Solve the following problem over the interval from t 0 to 1 using a step size of 0.25 where y(0) . Display your results on the same graph. dy dt (1 +4t)vy (a) Euler's method. (b) Ralston's method.
Q2 Using Fourth-order RK method, solve the following initial value problem over the interval from t = 0 to 1. Take the initial condition of y(0) = 1 and a step size (h)=0.5. dy = f(t, y) = y t- 1.1 y dt
Display all methods listed below in ONE GRAPH: 1. Analytical method 2. Euler's method 3. Heun's method without iteration 4. Ralston's method 5. Fourth-order RK method Metlab preferred Solve the following initial value problem over the interval from t= 0 to 1 where y(O) = 1 using the following methods with a step size of 0.25 4) dt Solve the following initial value problem over the interval from t= 0 to 1 where y(O) = 1 using the following methods...
show all step please ((NOT in MATLAB)) except part d Ralston's method 22.2 Solve the following problem over the interval from x = 0 to 1 using a step size of 0.25 where y(0) = 1. Display all your results on the same graph. Bolo dy bolo moto = (1 + 2x)VÝ Viena no woliszt unigas og tog (a) Analytically. sanoi solist og (b) Using Euler's method. (c) Using Heun's method without iteration. (d) Using Ralston's method. (e) Using the...