In my code, i would like to use "case switch" because i find that the lisibility is better than several loops with if then else. However, I have some issues with the use of "case swith". My code with use case doesn't work.

**Do you have a idea why ?**To help troubleshooting, i put my code with "use case" which doesn't work and my code with "If then else" which works.

Moreover, i suppose that it is due to the fact that i don't use the conditions well.

**How a condition with 2 parts can be written ? For example, how can i write the condition "x<3 and x>2" ?**

**Code with use case**

Code: Select all

```
parameters
real F=1000;
real start_time = 5.0 {s};
real stop_time = 25.0 {s};
real f_start = 5.0 {frequency, Hz};
real f_stop = 25.0 {frequency, Hz};
real omega_start;
real omega_stop;
variables
real omega {frequency, rad/s}; // current frequency {rad/s}
real freq {frequency, Hz};
real hidden t;
real hidden dw;
real hidden dt;
real hidden dwdt;
real hidden dwdt2;
boolean hidden change;
initialequations
omega_start = (2*pi)*f_start;
omega_stop = (2*pi)*f_stop;
dw = omega_stop - omega_start;
dt = stop_time - start_time;
dwdt = dw/dt;
dwdt2 = dwdt/2;
equations
"calculate at least at the start and stop time"
change = timeevent (start_time) or timeevent (stop_time);
omega = omega_start + t * dwdt;
freq=omega/(2*pi);
switch time
case time < start_time do
FF = F*sin( time * omega_start );
case time > stop_time do
FF = F*sin( time * omega_stop );
default do
FF = F*sin( (time-start_time) *( omega_start + (time-start_time) * dwdt2 ) );
end;
```

**Code with If then else loops**

Code: Select all

```
parameters
real F=1000;
real start_time = 5.0 {s};
real stop_time = 25.0 {s};
real f_start = 5.0 {frequency, Hz};
real f_stop = 25.0 {frequency, Hz};
real omega_start;
real omega_stop;
variables
real omega {frequency, rad/s}; // current frequency {rad/s}
real freq {frequency, Hz};
real hidden t;
real hidden dw;
real hidden dt;
real hidden dwdt;
real hidden dwdt2;
boolean hidden change;
initialequations
omega_start = (2*pi)*f_start;
omega_stop = (2*pi)*f_stop;
dw = omega_stop - omega_start;
dt = stop_time - start_time;
dwdt = dw/dt;
dwdt2 = dwdt/2;
equations
"calculate at least at the start and stop time"
change = timeevent (start_time) or timeevent (stop_time);
omega = omega_start + (time - start_time) * dwdt;
freq=omega/(2*pi);
FF = if time < start_time then
F*(time/start_time)*sin( time * omega_start ) //(time/start_time)
else
if time > stop_time then
F*sin( time * omega_stop )
else
F*sin( (time - start_time)*( omega_start + (time - start_time) * dwdt2 ) )
end
end;
```