I tried entering an if else statement but when I run the code, it gives me an error saying DAE index appears to be greater than one. Without the if else statement I am getting results. Even though they might be incorrect and some debugging might be needed. What should I understand from this difference?
How to enter an if...else...end statement for a dae problem
2 ビュー (過去 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
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
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?
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!