Question

2nd order ODE of modeling a cylinder oscillating in still water wate wate Figure 1. A cylinder oscillating in still water. A

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The Euler Method in Matlab For the Second order DE is given below.There are two files one is function file which is contains the euler method. And the another is script file that prepares the differential equation and sets the constants and then feeds the DE into euler function

************************************euler_method.m**********************

function [t,y] = euler_method( deriv_func,t0,dt,t_end,y0 )
%deriv_func is the differential eq.
%t0, t_end are the time range. dt is the increment
%calculate the size of output array
size=ceil((t_end-t0)/dt);

time_range=t0:dt:t_end;

%following line creates array with all elements 0
Y=zeros(size+1,2);
%initialize the Y with initial values
Y(1,:)=y0;

%the below loop solves the differential equation
% y(i+1)=y(i)+h*f(t,y)
for i=1:size
%x will give us column vector with two values
%one for y(1) and another for y(2)
x=deriv_func(time_range(i),Y(i,:));
%below is the euler method formula
Y(i+1,:)=Y(i,:)+dt*x';

end
t=time_range;
y=Y;
end

****************************SecondOrderDE.m************************

clc
clear all;

m=1;
c=0.1;
k=0.01;


initial=[0.2,0];
%Here we convert the Second order
%ODE in to first order by renaming the
%variables. y'=y(2).So differential of y' i.e. y"
% is d(y(2))/dt
%Now d(y(2))/dt = (-k*y(1)-c*y(2))/m.
%That is what we are representing below using Anonymous function
F= @(t,y)[y(2);(-k*y(1)-c*y(2))/m];

t0=0;
t_end=100;
dt=0.001;
[t,y]=euler_method(F,t0,dt,t_end,initial);

%Following is the Analytical function against which we compare
%Euler method.
Y=@(t)exp(-0.05.*t).*(0.2.*cos(0.0866025.*t)+0.11547.*sin(0.0866025.*t))
y_analytical=Y(t);

%Now we compare euler with True method
for i=1:length(t)
fprintf('Euler:%f\t\tAnalytical:%f\n',y(i,1),y_analytical(i))
end

%plot (t,y(;,1)) plots displacement vs time

plot(t,y(:,1)), xlabel('time'), ylabel('Displacement'),title('distance-time');



Euler:-0.000433 Euler:-0.000433 Euler:-0.000434 Euler:-0.000434 Euler:-0.000434 Euler:-0.000434 Euler:-0.000434 Euler:-0.0004alstance-time 0.2 0.15 50.1 CO 0.05 0 0.05 0 10 20 304050 60 70 80 90 100 time

Add a comment
Know the answer?
Add Answer to:
I mostly needed help with developing matlab code using the Euler method to create a graph. All th...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use the Runge Kutta 4th Order (RK-4) Method on the function below to predict the value...

    Use the Runge Kutta 4th Order (RK-4) Method on the function below to predict the value of y(0.1), given t = 0, y(0)-2, and h-01. Report your answer to 3 decimal places. dy/dt = e + 3y Answer: Use the Runge-Kutta 4th Order (RK-4) Method on the function below to predict the value of y(0.2), given y(0.1) from the previous question, and h = 0.1. Report your answer to 3 decimal places. -t dy/dt -e +3y Answer

  • ME 32200 Programming course (MATLAB) 4. Please finish the following Matlab code for solving the ODE:...

    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 =...

  • Hello These are a math problems that need to solve by MATLAB as code Thank you...

    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...

  • Please answer with Matlab Programming that can be copied and pasted when doing the Matlab part...

    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 =...

  • 9) Using Euler method, solve this with following initial conditions that t = 0 when y = 1, for th...

    9) Using Euler method, solve this with following initial conditions that t = 0 when y = 1, for the range t = 0 to t = 1 with intervals of 0.25 dr + 2x2 +1=0.3 dt 1o) Using second order Taylor Series method, solve with following initial conditions to-0, xo-1 and h-0.24 11) x(1)-2 h-0.02 Solve the following system to find x(1.06) using 2nd, and 3rd and 4th order Runge-Kutta (RK2, RK3 and RK4)method +2x 2 +1-0.3 de sx)-cox(x/2)...

  • PLEASE HELP! I need to write a MATLAB code for this Euler approximation for finding the...

    PLEASE HELP! I need to write a MATLAB code for this Euler approximation for finding the velocity of a parachutist at given time iterations. The answers are provided so you can check to see if the code works. I need to see it done in actual MATLAB program so I can understand the coding methodology better. 1.) Euler Method (estimated time 11min) For the second-order drag model (see Eq. (1)), compute the velocity of a free-falling parachutist using Euler's method...

  • Using the Runge-Kutta fourth-order method, obtain a solution to dx/dt=f(t,x,y)=xy^3+t^2; dy/dt=g(t,x,y)=ty+x^3 for t= 0 to t= 1 second. The initial conditions are given as x(0)=0, y(0) =1. Use a time...

    Using the Runge-Kutta fourth-order method, obtain a solution to dx/dt=f(t,x,y)=xy^3+t^2; dy/dt=g(t,x,y)=ty+x^3 for t= 0 to t= 1 second. The initial conditions are given as x(0)=0, y(0) =1. Use a time increment of 0.2 seconds. Do hand calculations for t = 0.2 sec only.

  • Can you help me with this problem? This has to be done using Matlab and solving with runge-katta, euler method, and the built in function ode45

    Consider a cylindrical storage tank with surface area A which contains a liquid at depth y:At time t = 0, the tank is empty (y = 0 when t = 0). Liquid is supplied to the tank at a sinusoidal rate Qin =3Qsin2 (t) and withdrawn from the tank as: 𝑄𝑜𝑢𝑡 = 3(𝑦 − 𝑦𝑜𝑢𝑡) 1.5 if 𝑦 > 𝑦𝑜𝑢𝑡 𝑄𝑜𝑢𝑡 = 0 if 𝑦 ≤ 𝑦𝑜𝑢𝑡 Please note that both 𝑄𝑖𝑛 and 𝑄𝑜𝑢𝑡 have units m3 /h. The mass...

  • Ordinary Differential Equations (a) Write a Python function implementing the 4'th order Runge-Kutta method. (b) Solve...

    Ordinary Differential Equations (a) Write a Python function implementing the 4'th order Runge-Kutta method. (b) Solve the following amusing variation on a pendulum problem using your routine. A pendulum is suspended from a sliding collar as shown in the diagram below. The system is at rest when an oscillating motion y(t) = Y sin (omega t) is imposed on the collar, starting at t = 0. The differential equation that describes the pendulum motion is given by: d^2 theta/dt^2 =...

  • where is says use euler2, for that please create a function file for euler method and use that! please help out with t...

    where is says use euler2, for that please create a function file for euler method and use that! please help out with this! please! screenahot the outputs and code! thanks!!! The van der Pol equation is a 2nd-order ODE that describes self-sustaining oscillations in which energy is withdrawn from large oscilations and fed into the small oscillations. This equation typically models electronic circuits containing vacuum tubes. The van der Pol equation is: dy dt where y represents the position coordinate,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT