MATLAB Answers

How to calculate a variable dependent on the state variables using ODE?

3 ビュー (過去 30 日間)
Hugo Mendonça
Hugo Mendonça 2017 年 6 月 2 日
Hi, Everyone!
Given a simple state-space system such as:
dx/dt = Ax + Bu
y = Cx + Du
To solve it, I am using the ode fuction because it is more convenient for me and it works fine. For example:
[t,x] = ode23s(@(t,x) system(t,x,A,B,u,ut),tspan,iniCon);
function dx = system(t,x,A,B,u,ut)
u = interp1(ut,u,t);
dx = A*x + B*u;
end
If I insert some simple nonlinearity to this system, it would become:
function dx = system(t,x,A,B,u,ut)
u = interp1(ut,u,t);
if x(1) > threshold
A = A*2;
dx = A*x + B*u;
else
dx = A*x + B*u;
end
and, again, the system works perfect.
If flag is a variable in the time that represents which condition the system is being calcuted, how can I calculate it with the same sample rate of x?
Appreciate any help.

回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by