`Hey,
Note: If you have any queries related to the answer please do comment. I would be very happy to resolve all your queries.
clc
clear all
close all
format long
f=@(t,y) [y(2);-4*y(1)];
[T1,Y1]=eulerSystem(f,[0,4],[1,0],0.125);
f=@(t,y) [y(2),-4*y(1)];
[T2,Y2]=runge4(f,[0,4],[1,0],0.125);
plot(T1,Y1(1,:),T2,Y2(:,1),T1,cos(2*T1));
legend('Euler','Runge 4','Exact');
function [t,y]=eulerSystem(Func,Tspan,Y0,h)
t0=Tspan(1);
tf=Tspan(2);
N=(tf-t0)/h;
y=zeros(length(Y0),N+1);
y(:,1)=Y0;
t=t0:h:tf;
for i=1:N
y(:,i+1)=y(:,i)+h*Func(t(i),y(:,i));
end
end
function [x,y]=runge4(f,tspan,y0,h)
x = tspan(1):h:tspan(2); % Calculates upto y(3)
y = zeros(length(x),2);
y(1,:) = y0; % initial condition
for i=1:(length(x)-1) % calculation loop
k_1 = f(x(i),y(i,:));
k_2 = f(x(i)+0.5*h,y(i,:)+0.5*h*k_1);
k_3 = f((x(i)+0.5*h),(y(i,:)+0.5*h*k_2));
k_4 = f((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; % main equation
end
end
Kindly revert for any queries
Thanks.
> nvm I was confused. Thanks
CMFishing Mon, Apr 18, 2022 7:07 AM
solve it with matlab 25.24 Given the initial conditions, y(0) = 1 and y'(0) = 1...
Problem 3. Given the initial conditions, y(0) from t- 0 to 4: and y (0 0, solve the following initial-value problem d2 dt Obtain your solution with (a) Euler's method and (b) the fourth-order RK method. In both cases, use a step size of 0.1. Plot both solutions on the same graph along with the exact solution y- cos(3t). Note: show the hand calculations for t-0.1 and 0.2, for remaining work use the MATLAB files provided in the lectures Problem...
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
Please solve this in Matlab Consider the initial value problem dx -2x+y dt x(0) m, y(0) = = n. dy = -y dt 1. Draw a direction field for the system. 2. Determine the type of the equilibrium point at the origin 3. Use dsolve to solve the IVP in terms of mand n 4. Find all straight-line solutions 5. Plot the straight-line solutions together with the solutions with initial conditions (m, n) = (2, 1), (1,-2), 2,2), (-2,0)
4. * Using your calculations from 3., plot the exact solution to dy = 1-y, dt y(0) = 1/2, for 0 <ts1, along with the numerical solution given by Euler's method and the trapezoid method, both with stepsize h = 0.1. Give the approximation of y(t = 1) for each numerical method. To distinguish your solutions: (i) Plot the Euler solution using crosses; do not join them with line segments. (ii) Plot the trapezoid solution using squares; again do not...
Problem Thre: 125 points) Consider the following initial value problem: dy-2y+ t The y(0) -1 ea dt ical solution of the differential equation is: y(O)(2-2t+3e-2+1)y fr exoc the differential equation numerically over the interval 0 s i s 2.0 and a step size h At 0.5.A Apply the following Runge-Kutta methods for each of the step. (show your calculations) i. [0.0 0.5: Euler method ii. [0.5 1.0]: Heun method. ii. [1.0 1.5): Midpoint method. iv. [1.5 2.0): 4h RK method...
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 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.
using matlab solve numerically dy/dt = sin t, y(0)=0 for 0<=t<=4π the exact solution is y(t) = 1 - cos t. Compare the exact and numerical solution.
Read the sample Matlab code euler.m. Use either this code, or write your own code, to solve first order ODE = f(t,y) dt (a). Consider the autonomous system Use Euler's method to solve the above equation. Try different initial values, plot the graphs, describe the behavior of the solutions, and explain why. You need to find the equilibrium solutions and classify them. (b). Numerically solve the non-autonomous system dy = cost Try different initial values, plot the graphs, describe the...
I need to solve this using Matlab please type comments in the script so I understand thank you. Create a table (similar to what we do in class) with all the parameters that you have to calculate for every step in the solution. Include y and dy/dx in the same plot with points from your table joined by straight lines (and clearly indicate which line correspond to what). You may use the MATLAB function you created above. Solve the following...
> This looks good, but I need to see what the eulerSystem and Runge4 functions are. thanks
CMFishing Mon, Apr 18, 2022 6:54 AM