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

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

采纳的回答

Star Strider
Star Strider 2016-1-27
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 个评论
Kamal Bera
Kamal Bera 2016-1-31
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 2016-1-31
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.

请先登录,再进行评论。

更多回答(1 个)

Nithin Chava
Nithin Chava 2019-10-8
?(?) = ?+6 ?(? 2+4?+3)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by