MATLAB Programming/Order Differential Equations

Order of Differential Equations
A differential equation is an equation with a function and one or more of its derivatives. It is usually to describe changes.

Note: Derivatives = $${dy \over dx}$$.

An order of differential equation (ODE) is an equation that has highest derivative of the dependent variable involved some ordinary derivatives of a function with respect to the independent variable. Often, the goal is to solve an ODE, i.e., determine what function or functions satisfy the equation. That means the differential equation defines the relationship between variables and their derivatives.

There are a primarily two of ODE types


 * 1) 1st Order Differential Equation (1st ODE)
 * 2) 2nd Order Differential Equation (2nd ODE)

First Order Differential Equation
All the linear equations in the form of derivatives are in the first order. It has only the first derivative such as dy/dx, where x and y are the two variables and is represented as

$$\frac{dy}{dx}+Py=Q$$

Second-Order Differential Equation
When the order of the highest derivative present is 2, then it is a second order differential equation.

$$\frac{d^{2}y}{dx^{2}}+n\frac{dy}{dx}+my^{2}=P$$

Using dsolve solve differential equation
We have an differential equations as follow,

$${dy^{3} \over dx^{3}} + 2{dy^{2} \over dx^{2}}+5{dy \over dx}+4y=5x $$ , $$y(0)=1, y'(0)=3$$

In order to solve this differential equation in MATLAB, we uses dsolve command to get the answer as followed

Type of ODE solver in MATLAB
There are few types of ODE solver but we will focus on just the commonly used :

Examples: ODE45 to solve differential equations
There are $10,000 deposited into the bank fixed deposit accounts and the interest rate is 2% annually.

To start with, we need to do a equation to model the money.

Equation 1: $$\frac{dM}{dt} = \frac{2}{100} M$$ : Annual saving interest is 2% annually on the balance of the bank balance over time ,

Equation 2: $$M(0) = 10,000$$ : Amount of money initial is at $10,000

From Equation 1, we take out (Note: Need to consult on other Wikiprojects on how to derive the linear equations)

$$dM = 0.002M.dt $$

$$\int\limits_{}^{} \frac{1}{M}.dM = \int_{}^{} 0.02dt$$

$$\ln e M = \ln e (0.02 t) + c$$

$$M(t) = e^{0.02t}. e^c$$, where $$e^c = M_{(0)}$$

$$M(t) = e^{0.02t}. M_{(0)}$$, taken from equation 2

$$M(t) =10000. e^{0.02t}$$

Using dsolve functions, we can similarly convert the differential equations

Hence. we have equations (shown as S) to do our modelling.

In MALAB to calculate differential equations using ode45, the syntax is as followed

where,

t = Evaluation points, returned as a column vector

y = Solutions, returned as an array

odefun = Function of the ode. You may use anonymous functions instead of writing a new files for the functions

tspan = Interval of integration, specified as a vector. At minimum, tspan must be a two element vector [t0 tf] specifying the initial and final times

y0 = Initial conditions, specified as a vector. y0 must be the same length as the vector output of ode function,

Using dsolve for converted differential equations ode45 functions to solve ODE