
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Notes on Ordinary Differential Equations.
Typology: Exercises
1 / 24
This page cannot be seen from the preview
Don't miss anything!

















MATLAB software
Computers and Matlab program in the Mechanical Design.
An equation involving the derivatives or differentials of the dependent variable is called a differential equation. A differential equation involving only one independent is called an ordinary differential equation. If a differential equation involves two or more independent variables, it is called a partial differential equation.
Ordinary differential equations are classified according to their order, linearity, and boundary conditions. The order of an ordinary differential equation is defined to be the order of the highest derivative present in that equation. Some examples of first-, second-, and third-order differential equations are
**- 1st-order equation
and
- 3rd-order equation
where x is the independent variable; y is the dependent variable. Ordinary differential equations can be classified as linear and nonlinear equations. A differential equation is linear if it can be written in form
Ordinary differential equations can be classified as initial value problems or boundary value problems. An equation is called an initial value problem (IVP) if the values of the dependent variables or derivatives are known at the initial value of the independent variables. An equation for which the values of the dependent variable or their derivatives are known at the final value of the independent variable is called a final value problem. If the dependent variable or its derivatives are known at more than one point of the independent variable, the differential equation is a boundary- value problem.
Analysis Laborat
Figure 1: The sequence of events in the application of ODEs for engineering problem solving
3.1. Ordinary differential equations with MATLAB function
**- M-file
Example 7.
Find the solution of the problem
and exact solution is
in interval 0 ≤ t ≤ 2 with step size is 0.2, using MATLAB functions ode23 and ode45.
Analysis Laborat
Note: To use ode23 just replace ‘ ode45 ’ with ‘ ode23 ’.
3.2. Numerical Method 3.2.1. Euler’s Method Although Euler’s method can be derived in several ways, the derivation based on Taylor’s series expansion is considered here. The value of can be expressed using Taylor’s series expansion about x (^) i , as
where the third term on the right-hand side of Eq.(7.1) denotes the error or remainder term, and
By Substituting into Eq.(7.1), Eq.(7.1) can be expressed as
If h is small, the error term can be neglected, and Eq.(7.2) yields
is known as Euler’s or Euler-Cauchy or the point slope method.
Euler’s Method Procedure
decreasing h (go to step 2)
the finals
Analysis Laborat
Flowchart Euler
Analysis Laborat
In Euler’s method, the value of the function f ( x , y ), which denotes the derivative , is computed at the beginning of the interval h and is assumed to be a constant over the entire interval. This assumption is a major source of error since the derivative, , changes from point over the interval h. In Heun’s method, the derivative or slope, , is compute at two points-one at the beginning and the other at the end of the interval h-and their average value is used to achieve an improvement.
Recall that in Euler’s method, the slope at the beginning of an interval (7.2) Is used to extrapolate linearly to : (7.3) For the standard Euler method we would stop at this point. However, in Heun’s method the calculated in Eq.(7.3) is not the final answer, but an intermediate prediction. This is why we have distinguished it with a superscript 0. Equation(7.3) is called a predictor equation. It provides an estimate of that allows the calculation of an estimated slope at the end of the interval:
Thus, the two slopes [Eqs.(7.2) and (7.4)] can be combined to obtain an average slope for the interval:
This average slope is then used to extrapolate linearly from to using Euler’s method:
which is called a corrector equation. The Heun method is a predictor-corrector approach.
The computational procedure of Heun’s method can be stated as follows:
-with iteration
Analysis Laborat
recalculate by decreasing h (go to step 2)
figures, that is the final solution
FlowChart of Heun’s Method
Analysis Laborat
the Editor/Debugger window.
df=input('Enter the ordinary differential equation(df):'); f=input('Enter the exact equation(f):'); a=input('Enter the left endpoints(a):'); b=input('Enter the right endpoints(b):'); dt=input('Enter the step size(dt):'); ya=input('Enter the initial condition(ya):'); xa=input('Enter the initial condition(xa):'); esp=input(‘Enter the percent tolerance(esp):’); N=input(‘Enter the number of iteration(N):’);
M=(b-a)/dt; t=zeros(M,1); y_huen=zeros(M,1); y_exact=zeros(M,1); error=zeros(M,1); y_huen(1)=ya; y_exact(1)=ya; t(1)=ta;
for k=1:M t(k+1)=t(k)+dt; y_exact(k+1)=feval(f,t(k+1)); y_huen(k+1)=y_huen(k)+feval(df,t(k),y_huen(k))dt; %y_huen(k+1)=y_huen(k)+(dt/2(feval(df,t(k),y_huen(k))+feval (df,t(k+1),y_huen(k+1))));**
for i=1:N y_huen(k+1)=y_huen(k)+(dt/2(feval(df,t(k),y_huen(k))+feval (df,t(k+1),y_huen(k+1)))); error1(k+1)=abs((y_huen(k+1)-y_huen(k))/y_huen(k+1))100;**
if error1 < esp break end
y_huen(k+1)=y_huen(k+1)
end
error(k+1)=abs((y_exact(k+1)-y_huen(k+1))/y_exact(k+1)) end*
Analysis Laborat
R=[t y_huen y_exact error];
3.2.2. Runge-Kutta’s Method
These methods are used for the solution of first order ODE (linear and nonlinear). They are a particular set of self- starting numerical methods. They can be used to generate an entire solution. They are more accurate than Euler’s method, but the calculations are more involved
Ruge-Kutta methods require only one initial point to start the procedure. The solution using Ruge-Kutta’s method can be stated in the form:
where is called the increment function, which is chosen to represent the average slope over the interval. The increment function can be expressed as
where n denotes the order of the Runge-Kutta’s method; are constants; and are recurrence relations given by
and (7.6)
where p and a are constants.
3.2.2.1. Second-Order Runge-Kutta Method
We now consider three of most commonly used versions of second-order Runge-Kutta method
Midpoint’s Method
with
Analysis Laborat
FlowChart Second-Order Runge-Kutta (Huen’s Method)
Analysis Laborat
Example 7. Use Euler’s method to integrate from t=0 to 4 with step size of 1. The initial condition at t=0 is y=2. Note that the exact solution can be determined analytically as
Procedures-MATLAB Program
the Editor/Debugger window.
Analysis Laborat
Example 7. Use Euler’s method to integrate from t=0 to 4 with step size of 1. The initial condition at t=0 is y=2. Note that the exact solution can be determined analytically as
Analysis Laborat
Procedures-MATLAB Program
the Editor/Debugger window.
3.2.2.3. Higher-Order Runge-Kutta Methods
(7.10)
Analysis Laborat
Example 7. Use Euler’s method to integrate from t=0 to 4 with step size of 1. The initial condition at t=0 is y=2. Note that the exact solution can be determined analytically as
Procedures-MATLAB Program
in the Editor/Debugger window.
Analysis Laborat
Analysis Laborat