Project

How to convert 2nd degree ODE into 1st order ODE using State Space Variables

Since there has been a lot of confusion regarding changing 2nd order ODEs to 1st order ODEs using state space variables, this project will give a detailed insight on it.

This conversion of 2nd order ODEs is required because the ODE23/ODE45 solver in matlab can only accept a 1st degree ODE.

What is a 2nd degree ODE ?

The general ODE for a spring mass system with mass m, stiffness k, and damping coefficient c will be as follows,

`m*((d^2x)/dt^2)+c*(dx/dt)+k*x=0`

which can also be represented as,

`m*x''+c*x'+k*x=0`

for convenience where,

`dx/dt=x' and (d^2x)/dt^2=x''`

Since, the highest order differential in this equation is 2 (i.e) `(d^2x)/dt^2` this can be termed as a second degree ordinary differential equation.

What does this ODE mean?

First we understood that our ODE defining the motion of a spring mass system was a 2nd order ODE, but what does the eqaution mean?

Upon solving the equation by integrating twice (analytical solution) we will get an equation of the form `x(t)` which basically means - the location of the mass at time 't'.

This solution when differentiated will give the equation of the form `x'(t)` which basically means the rate of change of displacement with time or velocity at any time instant.

Suppose, it is required to find the velocity and displacement at time 't=1sec' we can substitute the value of t in both the equations `x(t)` and `x'(t)` and we will get the displacement and velocity at time t=1 sec repectively.

For example,

The solution for a much simple spring mass system equation system without damping of the form,

`m*x''+k*x=0` is,

`x(t)=A*sin(omega*t+phi)`

where,

A is the max amplitude(max range of motion from mean position) of the mass.

`omega` is the natrual oscillation frequency of the system.

`phi` is the intial phase difference of the system.

All of these constants can be determined, when in this solution equation when we substitute t=1 sec we can get the 'x' location of the mass at 1 sec.

Similarly when we differentiate the equation and then substitute t=1 sec, we will get the velocity at t=1 sec.

This is why the solution of an ODE for motion system is significant.

What is a State Space Variable?

A state-space representation is a mathematical model of a physical system as a set of input, output and state variables related by first-order differential equations or difference equations.

What that essentially means is that a state space representation is a way of converting higher order differential equations in a 1st order ODE of different variables.

`f(x'',x',x,t)=g1(s1,s2)andg2(s1,s2)` where g1 and g2 are two different functions of state variables s1 and s2

The number of state variables used and the number of first order differential equations will be the same as the order of the differential equation - in our case 2.

State variables also mean the variables in the equation of motion which define state based quantities (vary with time).

Basically in our case `x, dx/dt, (d^2x)/dt^2` are also state variables and represent displacement, velocity and acceleration with respect to time respectively.

`[[x],[dx/dt],[(d^2x)/dt^2]]=[[x],[x'],[x'']]=[[displacement],[velocity],["acceleration"]]`

How to form a State space relation from a 2nd order ODE?

Let us assume the original problem of a spring mass system of mass m, stiffness k and damping coefficient c which will have a system ODE of the form,

`m*x''+c*x'+k*x=0`

Here, since the degree of the ODE is 2, we can conclusively say that we need 2 state variables and will subsequently get 2 1st order ODEs.

Let us assume the state space matrix is a 2 x 1 matrix with 2 elements (the 2 state variables)

`s=[[s1],[s2]]`

Now let us assume that the values of s1 and s2 are x and x' hence,

`s=[[s1],[s2]]=[[x],[x']]rarr(1)`

Now, the input for the ODE23 or ODE45 solvers must be first order ODEs. Hence, the input will be the differential of state space matrix 's' or equation 1.

`s'=[[s1'],[s2']]=[[x'],[x'']]`

`s'=[[x'],[x'']]rarr(2)`

Now to form a relationship between the variables s1 and s2 and our primary ODE we can perform the following manipulations,

`m*x''+c*x'+k*x=0rarr(3)`

from here upon rearranging the terms in equation 3 we get,

`x''=-(c/m)*x'-(k/m)*xrarr(4)`

but from equation 1 we already know that,

`x=s1 and x'=s2rarr(5)`

`x'=s2rarr(5.2)`

substituting values from equation 5 into equation 4 we get,

`x''=-(c/m)*s2-(k/m)*s1rarr(6)`

Now since the input state space vector is of the form of differential of s (equation 2),

`s'=[[s1'],[s2']]=[[x'],[x'']]`

substituting values of x' from equation 5.2 and x'' from equation 6 we get,

`s'=[[s1'],[s2']]=[[x'],[x'']]=[[s2],[-(c/m)*s2-(k/m)*s1]]`

Hence, we have successfully represented a 2nd order ODE in the form of 2 1st order ODEs with the state space matrix 's'.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.