Solve state space equation by ODE45
240 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Yu Jiang
on 8 Aug 2014
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)
5 Comments
More Answers (5)
Babak
on 9 Aug 2014
1 Comment
Yu Jiang
on 9 Aug 2014
Edited: Yu Jiang
on 11 Aug 2014
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
on 19 Oct 2016
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
0 Comments
Yasir Ghazi
on 15 Nov 2017
I have Linearized model state-space show below [I need to plot output (P&Q) in matlab ]
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/179382/image.png)
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/179384/image.png)
1 Comment
ANIL KUMAR BALLA
on 30 Mar 2019
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
on 26 Apr 2021
Yu Jiang Can you tell me how I plot input signal u from (dx/dt) = A*x + B*u with ode45?
0 Comments
bhargav
on 10 Dec 2024
Problem No.1
- Handwritten work for the derivation of the state space model, the observer gains and the controller gains.
- MATLAB: Do the whole problem using MATLAB.
- Simulate using SIMULINK. Here, include images of the SIMULINK blocks and outputs unless you are able to incorporate the SIMULINK work into the MATLAB published output.
For a mechanical control system, the transfer function of the plant is given by:
H(s)=1400s(s+2)(s+120)H(s) = \frac{1400}{s(s + 2)(s + 120)}H(s)=s(s+2)(s+120)1400
Design a controller to result in a 10% overshoot and a settling time of 1 second. Place the third pole at 10 times as far from the imaginary axis as the dominant poles.
Assume that the state variables of the plant are not accessible, design an observer for the states.
MATLAB:
Observer Design:
- Assume the states' initial conditions are:x0=[0.1,0.15,−0.2]x_0 = [0.1, 0.15, -0.2]x0=[0.1,0.15,−0.2]and x^(0)=[0,0,0].\hat{x}(0) = [0, 0, 0].x^(0)=[0,0,0].
- Plot the unit step response of the system and clearly show that you have a successful observer design. Clearly show the response of the states, xi(t)x_i(t)xi(t) and x^i(t)\hat{x}_i(t)x^i(t), and the errors, xe(t)x_e(t)xe(t). Explain the results.
Controller Design:
Design a full-state feedback controller based on the stated requirements in the problem and the observer designed above since the states are not accessible via measurements. Simulate for the unit step response of the system.
1 Comment
Steven Lord
on 10 Dec 2024
This sounds like a homework assignment. If it is, post it as a new question. In that new question, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the free MATLAB Onramp tutorial to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!