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

13 vues (au cours des 30 derniers jours)
Urvi
Urvi le 1 Oct 2012
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 commentaires
Urvi
Urvi le 3 Oct 2012
Please help! its urgent!
Jan
Jan le 3 Oct 2012

Connectez-vous pour commenter.

Réponses (2)

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

Connectez-vous pour commenter.


Jan
Jan le 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?

Catégories

En savoir plus sur Chemistry dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by