I DESPERATELY NEED HELP WITH THIS DIFFERENTIAL EQUATIONS MATLAB ASSIGNMENT IM SUPPOSED TO BE LEARNING BUT WE HAVE A SUB AND HE DIDN'T TEACH IT! ITS EULER AND IMPROVED EULER IN MATLAB! HERE IS THE LINK FOR THE IMAGE FILE THAT SHOWS THE FULL INSTRUCTIONS FOR THE CODE.
https://imgur.com/a/gjmypLs
Also, here is my code so far that I borrowed form an old assignment but the data is all wrong and the application of the code is slightly different so either create new code or modify mine so that it matches up with this assignment! I WILL RATE ASAP! Thanks!
%% Exercise 1
clc
clear all
t= linspace(0, 0.5, 100);
y= 3*exp(2*t);
%Inline function
f= inline('2*y', 't', 'y');
[t5, y5]= euler(f, [0, 0.5], 3, 5);
y5(end);
[t50, y50]= euler(f, [0, 0.5], 3, 50);
y50(end);
[t500, y500]= euler(f, [0, 0.5], 3, 500);
y500(end);
[t5000, y5000]= euler(f, [0, 0.5], 3, 5000);
y5000(end);
% Error of Euler's Method = Exact - Approximation
e5 = y(end) - y5(end); % error at N=5
e50 = y(end) - y50(end);
e500 = y(end) - y500(end);
e5000 = y(end) - y5000(end);
%Ratio of errors
ratio1= e5/e50; % error between 5 and 50
ratio2= e50/e500; % 5 and 500
ratio3= e500/e5000; % 5 and 5000
%Compile the data
N= [5;50;500;5000];
Approximation= [y5(end);y50(end);y500(end);y5000(end)];
Error= [e5;e50;e500;e5000];
Ratio= [0;ratio1;ratio2;ratio3];
T=table(N,Approximation,Error,Ratio)
%% Exercise 2
figure(1)
t = 0:.45:10; y = -30:6:42 ; % define grid of values in t and y
direction
[T,Y]=meshgrid(t,y); % creates 2d matrices of points in the
ty-plane
dT = ones(size(T)); % dt=1 for all points
dY = -2*Y; % dy = -2*y; this is the ODE
quiver(T,Y,dT,dY) % draw arrows (t,y)->(t+dt, t+dy)
axis tight % adjust look
hold on
hold off
figure(2)
t = 0:.45:10; y = -30:6:42 ; % define grid of values in t and y
direction
[T,Y]=meshgrid(t,y); % creates 2d matrices of points in the
ty-plane
dT = ones(size(T)); % dt=1 for all points
dY = -2*Y; % dy = -2*y; this is the ODE
quiver(T,Y,dT,dY) % draw arrows (t,y)->(t+dt, t+dy)
axis tight % adjust look
hold on
% Exact solution
t = linspace(0,10,200);
y = 3*exp(-2*t);
plot(t,y,'k-', 'linewidth',2)
hold off
%% Part c
figure(3)
t = 0:.45:10; y = -30:6:42 ; % define grid of values in t and y
direction
[T,Y]=meshgrid(t,y); % creates 2d matrices of points in the
ty-plane
dT = ones(size(T)); % dt=1 for all points
dY = -2*Y; % dy = -2*y; this is the ODE
quiver(T,Y,dT,dY) % draw arrows (t,y)->(t+dt, t+dy)
axis tight % adjust look
hold on
% Exact solution
t = linspace(0,10,200);
y = 3*exp(-2*t);
plot(t,y,'k-', 'linewidth',2)
% Euler's Approximation for N=8
f= inline('-2*y', 't', 'y'); %inline function
[t8, y8]= euler(f, [0, 10], 3, 8); % N=8
plot(t8,y8,'ro-', 'linewidth',2)
hold off
axis([0 10 -30 40])
%% Part d
figure(4)
t = 0:.4:10; y = -1:0.4:3; % define grid of values in t and y
direction
[T,Y]=meshgrid(t,y); % creates 2d matrices of points in the
ty-plane
dT = ones(size(T)); % dt=1 for all points
dY = -2*Y; % dy = -2*y; this is the ODE
quiver(T,Y,dT,dY) % draw arrows (t,y)->(t+dt, t+dy)
axis tight % adjust look
hold on
% Exact solution
t = linspace(0,10,200);
y = 3*exp(-2*t);
plot(t,y,'k-','linewidth',2)
% Euler's Approximation for N=16
f= inline('-2*y', 't', 'y'); %inline function
[t16, y16]= euler(f, [0, 10], 3, 16); % N=16
plot(t16,y16,'ro-','linewidth',2)
hold off
axis([0 10 -1 3])
% The step size of the function is larger than expected due to
the
% oscillation of the beginning values, but geometrically then
follows the
% field direction vectors.
%% Excerise 3
% Display contents of impeuler M-file.
type 'impeuler.m'
% Define ODE function for dy/dt = f(t,y) = 2y
f= inline('2*y', 't', 'y');
% Compute numerical solution to IVP with 5 timesteps using
"improved Euler."
[t5, y5] = impeuler(f, [0 0.5],3,5)
function [t,y] = impeuler(f,tspan,y0,N)
% Solves the IVP y' = f(t,y), y(t0) = y0 in the time interval tspan
= [t0,tf]
% using Euler's method with N time steps.
% Input:
% f = name of inline function or function M-file that evaluates the
ODE
% (if not an inline function, use: euler(@f,tspan,y0,N))
% For a system, the f must be given as column vector.
% tspan = [t0, tf] where t0 = initial time value and tf = final
time value
% y0 = initial value of the dependent variable. If solving a
system,
% initial conditions must be given as a vector.
% N = number of steps used.
% Output:
% t = vector of time values where the solution was computed
% y = vector of computed solution values.
m = length(y0);
t0 = tspan(1);
tf = tspan(2);
h = (tf-t0)/N; % evaluate the time step size
t = linspace(t0,tf,N+1); % create the vector of t values
y = zeros(m,N+1); % allocate memory for the output y
y(:,1) = y0'; % set initial condition
for n=1:N
f1= f(t(n), y(:,n));
f2= f(t(n+1), y(:,n)+h*f1);
y(:,n+1)= y(:,n) +h*(f1+f2)/2;
end
t = t'; y = y'; % change t and y from row to column vectors
end
% The output of the values versus the given match the data
correctly.
%% Exercise 4
%Euler's method
t= linspace(0, 0.5, 100);
y= 3*exp(2*t);
f= inline('2*y', 't', 'y'); %inline function
[t5, y5]= impeuler(f, [0, 0.5], 3, 5); % N=5
y5(end);
[t50, y50]= impeuler(f, [0, 0.5], 3, 50); % N=50
y50(end);
[t500, y500]= impeuler(f, [0, 0.5], 3, 500); % N=500
y500(end);
[t5000, y5000]= impeuler(f, [0, 0.5], 3, 5000); % N=5000
y5000(end);
% Error of Euler’s method
e5 = y(end) - y5(end); % error at N=5
e50 = y(end) - y50(end); % error at N=50
e500 = y(end) - y500(end); % error at N=500
e5000 = y(end) - y5000(end); % error at N=5000
% Ratio Error
ratio1= e5/e50; % ratio of error between 5 and 50
ratio2= e50/e500; % 5 and 50
ratio3= e500/e5000; % 5 and 50
% Compile the data into a table
N= [5;50;500;5000];
Approximation= [y5(end);y50(end);y500(end);y5000(end)];
Error= [e5;e50;e500;e5000];
Ratio= [0;ratio1;ratio2;ratio3];
T=table(N,Approximation,Error,Ratio)
% The step size of this example is 10, and the ratio of error is
100.
% This follows the k^2 decrease factor.
%% Exercise 5
% Part a same as in Exercise 2 (see Exercise 2a)
% Pand b same as in Exercise 2 (see Exercise 2b)
%% Part C
figure(5)
t = 0:.45:10; y = -30:6:42 ; % define grid of values in t and y
direction
[T,Y]=meshgrid(t,y); % creates 2d matrices of points in the
ty-plane
dT = ones(size(T)); % dt=1 for all points
dY = -2*Y; % dy = -2*y; this is the ODE
quiver(T,Y,dT,dY) % draw arrows (t,y)->(t+dt, t+dy)
axis tight % adjust look
hold on
% Exact solution for Euler
t = linspace(0,10,200);
y = 3*exp(-2*t);
plot(t,y,'k-', 'linewidth',2)
% Improved Euler's Approximation for N=8
f= inline('-2*y', 't', 'y'); %inline function
[t8, y8]= impeuler(f, [0, 10], 3, 8); % N=8
plot(t8,y8,'ro-', 'linewidth',2)
hold off
axis([0 10 -30 40])
%% Part D
figure(6)
t = 0:.4:10; y = -1:0.4:3; % define grid of values in t and y
direction
[T,Y]=meshgrid(t,y); % creates 2d matrices of points in the
ty-plane
dT = ones(size(T)); % dt=1 for all points
dY = -2*Y; % dy = -2*y; this is the ODE
quiver(T,Y,dT,dY) % draw arrows (t,y)->(t+dt, t+dy)
axis tight % adjust look
hold on
% Exact solution
t = linspace(0,10,200);
y = 3*exp(-2*t);
plot(t,y,'k-','linewidth',2)
% Improved Euler's Approximation for N=16
f= inline('-2*y', 't', 'y'); %inline function
[t16, y16]= impeuler(f, [0, 10], 3, 16); % N=16
plot(t16,y16,'ro-','linewidth',2)
hold off
axis([0 10 -1 3])
% In comparison to the N = 8 Euler approximation,
% the N = 16 approximation more closely follows the function
resulting
% in larger accuracy using Euler’s method.
clc
clear all
t= linspace(0, 0.5, 100);
y= 3*exp(2*t);
%Inline function
f= inline('2*y', 't', 'y');
[t5, y5]= euler(f, [0, 0.5], 3, 5);
y5(end);
[t50, y50]= euler(f, [0, 0.5], 3, 50);
y50(end);
[t500, y500]= euler(f, [0, 0.5], 3, 500);
y500(end);
[t5000, y5000]= euler(f, [0, 0.5], 3, 5000);
y5000(end);
% Error of Euler's Method = Exact - Approximation
e5 = y(end) - y5(end); % error at N=5
e50 = y(end) - y50(end);
e500 = y(end) - y500(end);
e5000 = y(end) - y5000(end);
%Ratio of errors
ratio1= e5/e50; % error between 5 and 50
ratio2= e50/e500; % 5 and 500
ratio3= e500/e5000; % 5 and 5000
%Compile the data
N= [5;50;500;5000];
Approximation= [y5(end);y50(end);y500(end);y5000(end)];
Error= [e5;e50;e500;e5000];
Ratio= [0;ratio1;ratio2;ratio3];
T=table(N,Approximation,Error,Ratio)
%% Exercise 2
figure(1)
t = 0:.45:10; y = -30:6:42 ; % define grid of values in t and y
direction
[T,Y]=meshgrid(t,y); % creates 2d matrices of points in the
ty-plane
dT = ones(size(T)); % dt=1 for all points
dY = -2*Y; % dy = -2*y; this is the ODE
quiver(T,Y,dT,dY) % draw arrows (t,y)->(t+dt, t+dy)
axis tight % adjust look
hold on
hold off
figure(2)
t = 0:.45:10; y = -30:6:42 ; % define grid of values in t and y
direction
[T,Y]=meshgrid(t,y); % creates 2d matrices of points in the
ty-plane
dT = ones(size(T)); % dt=1 for all points
dY = -2*Y; % dy = -2*y; this is the ODE
quiver(T,Y,dT,dY) % draw arrows (t,y)->(t+dt, t+dy)
axis tight % adjust look
hold on
% Exact solution
t = linspace(0,10,200);
y = 3*exp(-2*t);
plot(t,y,'k-', 'linewidth',2)
hold off
I DESPERATELY NEED HELP WITH THIS DIFFERENTIAL EQUATIONS MATLAB ASSIGNMENT IM SUPPOSED TO BE LEARNING BUT...
Matlab & Differential Equations Help Needed
I need help with this Matlab project for differential equations.
I've got 0 experience with Matlab other than a much easier project
I did in another class a few semesters ago. All we've been given is
this piece of paper and some sample code. I don't even know how to
begin to approach this. I don't know how to use Matlab at all and I
barely can do this material.
Here's the handout:
Here's...
Numerical Methods for Differential Equations - Please
post full correct solution!!! - need to use MATLAB
3. (a) Write Matlab functions to integrate the initial value problem y = f(x,y), y(a) = yo, on an interval [a, b] using: • Euler's method • Modified Euler • Improved Euler • Runge Kutta 4 It is suggested that you implement, for example, Improved Euler as [x, y) = eulerimp('f', a, yo, b, stepsize), where (2,y) = (In, Yn) is the computed solution....
Hello. I need help modifying this MatLab code. This is a basic slider-crank animation. the current program stops the animation and then has the crank move backward. I need the crank to instead to move in full 360 degrees circular motion. Exactly like how a slide-crank mechanism works in real life. thank you and here is the code. %%Code Begins Here%% L1=0.2; L2=0.45; W=0.5; tt=linspace(0,15); for i=1:length(tt) x2=@(t) L2+L1*sin(W*t); y2=0; X2=x2(tt(i)); Y2=y2; sol= fsolve(@(x,x2,y2) root2d(x,X2,Y2),...
help me with this. Im done with task 1 and on the way to do task
2. but I don't know how to do it. I attach 2 file function of rksys
and ode45 ( the first is rksys and second is ode 45) . thank for
your help
Consider the spring-mass damper that can be used to model many dynamic systems -- ----- ------- m Applying Newton's Second Law to a free-body diagram of the mass m yields the...
Differential Equations with MATLAB/Plotting first order
differential equations in Matlab/ Differential Equations MATLAB/IVP
Matlab/IVP
I'd really appreciate if I can get some help plotting these 3
first order differential equations as well as their comments.
PLEASE! ANYTHING HELPS, I am very stuck :(
EZplot and ODE 45 were mentioned in class and the instructions
in class were not clear at all.
Given the first order differential equation with initial condition. dy/dt = y t, y(0)=-1 Complete problems 1-3 in one...
I mostly needed help with developing matlab code using
the Euler method to create a graph. All the other methods are
doable once I have a proper Euler method code to refer to.
2nd order ODE of modeling a cylinder oscillating in still water wate wate Figure 1. A cylinder oscillating in still water. A cylinder floating in the water can be modeled by the second order ODE: dy dy dt dt where y is the distance from the water...
MATLAB code for a double pendulum. Please explain each lines for these codes pls. ---------------------------------------------------------------------------- clc close all clear all %---------Parameters------------------------------------------------------ L1=1; L2=1 ; M_1=2 ; M_2=1; G=9.8; %---------initial condition----------------------------------------------- tspan=30; theta1=3; theta1_prime=0; theta2=2.5; theta2_prime=0; y0=[theta1 theta1_prime theta2 theta2_prime]; [t,y]=ode45(@pend, [0 ,tspan],[ 3 0 2 0]); %---position of mass 1 and mass 2---------------------------------------- x1=L1*sin(y(:,1)); y1=-L1*cos(y(:,1)); x2=L1*sin(y(:,1))+l2*sin(y(:,3)); y2=-L1*cos(y(:,1))-l2*cos(y(:,3)); %------visualizing the result--------------------------------------------- figure(1) plot(x1,y1,'linewidth',2) hold on plot(x2,y2,'r','linewidth',2) h=gca; get(h,'fontSize') set(h,'fontSize',14) xlabel('X','fontSize',14); ylabel('Y','fontSize',14); title('Chaotic Double Pendulum','fontsize',14) fh = figure(1); set(fh, 'color', 'white'); figure(2)...
Hello
These are a math problems that need to solve by MATLAB as
code
Thank you !
Initial Value Problem #1: Consider the following first order ODE: dy-p-3 from to 2.2 with y() I (a) Solve with Euler's explicit method using h04. (b) Solve with the midpoint method using h 0.4. (c) Solve with the classical fourth-order Runge-Kutta method using 0.4 analytical solution of the ODE is,·? solution and the numerical solution at the points where the numerical solution is...
Question 1
QUESTION 2
Use the attached Matlab code as a basis to solve the following ordinary differential equation using Euler's method, with timestep of 0.1, from t-0to t-100. d)0) -0 - sin (5vt cos(у Plot y versus t from t=0 to t=100. How many local maxima are on this interval(do not include end points). Be careful to count them all! Answer should be an integer 1 w% Matlab code for the solution of Module 2 3 dt-9.1; %dt is...
MATLAB help please!!!!!
1. Use the forward Euler method Vi+,-Vi + (ti+1-tinti , yi) for i=0.1, 2, , taking yo-y(to) to be the initial condition, to approximate the solution at 2 of the IVP y'=y-t2 + 1, 0 2, y(0) = 0.5. t Use N 2k, k2,...,20 equispaced timesteps so to 0 and t-1 2) Make a convergence plot computing the error by comparing with the exact solution, y: t (t+1)2 exp(t)/2, and plotting the error as a function of...