Constraining Nonnegative states in a NOT EXPLICITLY NAMED ODE FUNCTION
Show older comments
Hi Everybody!
I've written a function which contains a system model:
function [xdot] = BR_1D_model(t,x,valve)
xdot = A*x + B*u
I want to constrain some of the states in the model to be non-negative values. Specifically, one of the states is vertical position, so I want to constrain it to [0 inf). I can successfully do this in the workspace by using ODESET.
options = odeset('NonNegative',[3 5]);
[t, x] = ode45(@BR_1D_model,tspan,initial,[],valve);
However, I'm also using this model in an s-function, and I can't figure out how to use the odeset 'NonNegative' attribute, because I'm not directly calling the ode45 solver in the s-function.
function [sys,x0,str,ts]=BR_1D_sfcn(t,x,u,flag,Pressure,Mass,Pos,Vel,Thrust)
switch flag
case 0 %initialize
str=[] ;
ts = [0 0] ;
s = simsizes ;
s.NumContStates = 5 ;
s.NumDiscStates = 0 ;
s.NumOutputs = 5 ;
s.NumInputs = 1 ;
s.DirFeedthrough = 0 ;
s.NumSampleTimes = 1 ;
sys = simsizes(s) ;
x0 = [Pressure,Mass,Pos,Vel,Thrust]' ;
case 1 %derivatives
valve = u ;
sys = BR_1D_model(t,x,valve) ;
case 3 %output
sys = x;
What do you guys think? Any thoughts?
Answers (0)
Categories
Find more on General Applications in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!