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

2 views (last 30 days)
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 Comments

Sign in to comment.

Answers (2)

Azzi Abdelmalek
Azzi Abdelmalek on 3 Oct 2012
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 Comment
Urvi
Urvi on 3 Oct 2012
I have already tried this but I get an error saying "DAE index appears to be greater than 1".

Sign in to comment.


Jan
Jan on 3 Oct 2012
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?

Community Treasure Hunt

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

Start Hunting!