solving state equation by ODE 45 by user defined time step and also checking response at each timestep

3 Ansichten (letzte 30 Tage)
Hi I want to calculate response x (fixed time step=0.01 sec) by solving state equation using ODE45: xdot=A.x+B.u --> A,B,x0(initial value of x) & u are known to me, but I will decide (or modify) the input u at (i+1)-th time based on the response I am getting at i-th time step. If I use ODE45 directly then I will get the final responses at each time and I will not be able to modify u accordingly. May be some loop is required to do that but HOW!!! Please help me.Thanks in advance.

Akzeptierte Antwort

Star Strider
Star Strider am 27 Jan. 2016
The MATLAB ODE solvers return the current value of your independent variable (here, time) and the current values of the integrated function. If you have a time-dependent input, you can use the time value to change the input. If you are making small adjustments to ‘u’, this should not be a problem.
Note that the ODE solvers don’t deal well with significant discontinuities, so consider stopping the integration and re-starting it with new values for ‘u’ (using the previous final values of ‘x’ as the new initial conditions) if the discontinuities are significant.
  20 Kommentare
Kamal Bera
Kamal Bera am 31 Jan. 2016
Please give a last try with the code ContRespNew.m that I have already sent to you on 30 Jan 2016 at 18:56. Change ' k' (that will eventually change the ' u' also) whatever you want.You will get same response each time. I think this is not correct. If correct, can you explain me!!!
Star Strider
Star Strider am 31 Jan. 2016
If that’s the file with the ode45 call, I already looked at it, ran it, and commented on it. It appears to be correct to me.
The other problem was your (incorrect) use of the expm function that I also commented on in some detail.
It is quite possible to quickly converge on a similar-appearing solution. The only way you can determine if it is working correctly is to closely examine what it is doing over time, preferably by plotting the output of the plant and the control inputs over time.
You would have to save the control signals, perhaps as ‘uv’, by inserting this statement at the end of your loop (after defining the new value of ‘u’ in each iteration):
uv(:,i) = u;
Then in your plot, plot ‘uv’ against ‘t’, as well as the signals you are already plotting. I am certain you will see them change appropriately.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Nithin Chava
Nithin Chava am 8 Okt. 2019
?(?) = ?+6 ?(? 2+4?+3)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by