Solve state space equation by ODE45

394 次查看(过去 30 天)
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.

采纳的回答

Yu Jiang
Yu Jiang 2014-8-8
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 .
  5 个评论
savvas
savvas 2015-10-5
How is the sys.m file altered for a two input system?
Sunil Ojwani
Sunil Ojwani 2018-12-28
how i plot control input u with tspan

请先登录,再进行评论。

更多回答(4 个)

Babak
Babak 2014-8-9
Thank you Yu Jiang. After your explanation I could get answer from the solver but still I have a problem for updating. Please have a look on attached picture.
I must update X and U in next step. as you said I must update U inside the function but it didn't work.
function xdot=sys(t,X,A,B,Lsr,Tm)
p=4;Tl=0;Tm=0; J=0.03832; Vab=208;Vbc=208;
U=[Vab,Vbc,zeros(1,46),((Tm-Tl)/J),0]';
xdot=A*X+B*U;
Is=[xdot(1,1),xdot(2,1),-(xdot(1,1)-xdot(2,1))];% 1st calculation
Tm=(p/2)*Is*(Lsr)*xdot(3:48,1); % 2nd calculation
U=[Vab,Vbc,zeros(1,46),((Tm-Tl)/J),0]'; %use 1st and 2nd to update U
end
[t,y]=ode45(@(t,X) sys(t,X,A,B,Lsr,Tm),tspan,X);
X=y; % Update X
Two problems:
1- how can I update the U inside (or outside) the function? (I need xdot to update U)
2- When I solved the equation the dimension of y is not [50,1], then I can not use it as a input again.(X=y ?)
  1 个评论
Yu Jiang
Yu Jiang 2014-8-9
编辑:Yu Jiang 2014-8-11
From what I understand, this is not an issue with MATLAB, but an issue with control theory.
In standard state-space-based control design, the control signal u is usually a function of x, not a function of xdot. If it is the later case, I think you may need to do some math to rearrange the terms with dot operation to the left-hand side of the equation.
Again, bear in mind that ode45 is used for autonomous systems in the form of dx = f(t,x). No derivative terms of x should appear on the right hand side. If you define Tm using xdot and use it as part of the input u, you are actually introducing xdot to the right hand side of the equation.

请先登录,再进行评论。


Delcio Macaia
Delcio Macaia 2016-10-19
Heloo, i have some questions to ask i have a state space, dx/dt = Ax(t) + Bu(t) , y = C x(t) + D u(t) i know all the values and the size of the matrix's
A is a (6*6)matrix B is a (6*1)matrix C is a (6*6) matrix D is a (6*1) mtrix
i need to input a signal in my state space system, the signal is a vector (6000*2),
in the first column i have the time and the second column i have the acelerations
Ts is my simple time Ts = 0.02 the interval of the integration is 0 to 120 [0 120]
so if i put in matlab --> sys = ss(A,B,C,D,Ts )
how can i input my signal and how can a solve it whit the ODE45 ?
THANKS

Yasir Ghazi
Yasir Ghazi 2017-11-15
I have Linearized model state-space show below [I need to plot output (P&Q) in matlab ]
where
a=[-100 -628.32 -1000 0 0 0 0 0 0 0 0;226.19 -100 0 -1000 0 0 0 0 0 0 0;100000 0 0 -628.32 -104790 0 102500 0 0 0 0;0 1e6 226.19 0 0 -37726 0 36902 0 0 0;0 0 325.55 0 -45.54 -376.99 44.375 50.528 212.38 0 0;0 0 0 325.55 376.99 -45.54 -50.528 44.375 -14.612 0 0;0 0 0 0 28.905 0 -29.551 1.5489 1591.1 0 0;0 0 0 0 0 28.905 -1.5489 -29.551 -109.47 0 0;0 0 0 0 0.87472 -0.060182 -0.89748 0.014545 -1.0531 16849 42.123;0 0 0 0 0 0 0 0 -0.025 0 1;0 0 0 0 0 0 0 0 1.25 -20000 -55.302];
b=[4331.6 5243.1 0 0 0;0 -6371.2 -97980 0 0;22411 -4527.5 -7979600 0 0;-7619.9 -17920000 3041500 0 0;-222.94 0 0 0 0;24.59 0 0 0 0;-1591.1 0 0 0 0;109.47 0 0 0 0;0.39844 0 0 0 0;0 0 0 0 0;0 0 0 22.848 -5.3188];
c=[9798 0 0 0 0 0 0 0 0 0 0;0 -16330 0 0 0 0 0 0 0 0 0];
d=[219.62 0 -24528 0 0;108.44 136279 137990 0 0];
and Input, state and output variables at the operating point for linearization
  1 个评论
ANIL KUMAR BALLA
ANIL KUMAR BALLA 2019-3-30
i need to give speed bump and steering as inputs to my state space block, but my inputs are in graphical form how to give these two inputs to the same state space block.

请先登录,再进行评论。


Yower Jymmy
Yower Jymmy 2021-4-26
Yu Jiang Can you tell me how I plot input signal u from (dx/dt) = A*x + B*u with ode45?

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by