- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Error using IF expression
Page Start Prev 1 Next End
Error using IF expression
Error using IF expression
Jun-19-20 14:39:31
Hi Everyone,
I want to implement an IF expression that enables two different sets of initial conditions. What I came up with is what follows:
Code:
parameter Real A;
if A ==1 then
Real y1(start=0.2), y2(start=3.5), y3(start=0.5);
else
Real y1(start=2.2), y2(start=1.5), y3(start=0.3);
end if;
Unfortunately, using the above code I got the following syntax error message:
No viable alternative near token: if
Could you help me figure this out?
Thank you so much!
Gabri
Edited by: Gabri - Jun-19-20 14:40:31
Re: Error using IF expression
Jun-19-20 19:39:45
You cannot have IF in the component section in a Modelica model (well, except for conditional components). You can only use if inside equations. However, what you want can be done via if expressions:
Code:
parameter Real A;
Real y1(start=if A ==1 then 0.2 else 2.2),
y2(start=if A ==1 then 3.5 else 1.5),
y3(start=if A ==1 then 0.5 else 0.3);
- adrpo
- 885 Posts
Page Start Prev 1 Next End
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Error using IF expression
There are 0 guests and 0 other users also viewing this topic