How to enter an if...else...end statement for a dae problem

1 次查看(过去 30 天)
This is my m file:
*M file* function f=ncs1_dae(t,x)
%Input parameters
global alpha A AH AI AO AV ACS beta CPH CPI CPIN CPO CPV dB g hB hI hO hH hV Hmax k M MH min Pset qein R rhol rhov ri ro TIN TR vB lambda;
input()
%Variables
TI=x(1);
........
..........
=x(16);
%f(1) to f(6) are ODEs
f(1)=
f(2)=
f(3)=
f(4)=
f(5)=
f(6)=
%f(7) to f(18) are Algebraic Equations
f(7)=
f(8)=
f(9)=
f(10)=
f(11)=
f(12)=
f(13)=
f(14)=
f(15)=
f(16)=
f(17)=
f(18)=
f=f';
My question is:
I want to enter if....else statements for a few equations...For example, in f(7), if PV<=Pset, mout = 0 else f(7)=. How can I incorporate that. I need to do this for 5-6 equations. Thanks!
  3 个评论

请先登录,再进行评论。

回答(2 个)

Azzi Abdelmalek
Azzi Abdelmalek 2012-10-3
if PV<=Pset
mout = 0
else
f(7)=mout-alpha*(PV-Pset)
end
in general
if condition1
% action1
elseif condition2
% action2
elseif condtion n
% action n
else
% action n+1
end
  1 个评论
Urvi
Urvi 2012-10-3
I have already tried this but I get an error saying "DAE index appears to be greater than 1".

请先登录,再进行评论。


Jan
Jan 2012-10-3
The DAE (or ODE) function must be continuous. Therefore IF, MAX, ABS and time-dependent functions are a big DON'T in functions to be integrated. Use event functions instead.
Remember, that the trajectory of an DAE must be kept on a feasible path. Could this be the case, when you insert a discontinuity?

类别

Help CenterFile Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by