MATLAB: Solve state space equation by ODE45

differential equationsode45state-space

Hello everybody.
I am new to state space representation. please help me to solve this question.
I have state space equation for IM motor like this:
xdot=A.x+B.u –> and their dimensions are : [50,1]=[50,50]*[50,1]+[50,50]*[50,1]
I have calculated A & B and I need to get xdot. (there are no C & D)
1- how should I write my function? (I don't use Simulink)
2- I used my solver like this:
>> [t,y] = ode45(@sys, tspan, zeros(50,1));
Thanks in advance.

Best Answer

Hi Babak
In order to solve an ODE using ode45, you need to first define the function to describe the complete dynamics. In the linear state space system you provided, the definition of u is missing. In general, u can be designed as a linear feedback control law, such as u = Kx, where K is a 50-by-50 matrix. Let me give you a simpler example here. Suppose we have A = [0 1; -2 3]; B = [0;1]; K = [-1 -1]; Then, the system function can be constructed as
function dx = sys(t, x)
A = [0 1; -2 3]; B = [0;1]; K = [-1 -1];
u = K*x
dx = A*x + B*u;
end
Please save the above function in an MATLAB file and name is as sys.m
Then, in a separate MATLAB script file or in the command window, you can simulate the system by executing the following
>> tspan = [0 10];
>> iniCon = [1;-1]
>> [t, y] = ode45(@sys, tspan, iniCon);
If you would like to show the simulation result in a figure, try executing >> plot(t,y)
For more details regarding ode45, see here .