Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

If Condition evaluation?

Please login with a confirmed email address before reporting spam

Hey there,

I am struggling with the evaluation of if conditions within COMSOL.

I have an equation that shall be evaluated if x is between 0 and 1. Say:

y = f(x) * (0<x<1)

Assuming x is between 0 and 1, the expression (0<x<1) should be evaluated as 1, shouldn´t it? But it is not. COMSOL evaluates the if condition as 0. Hence, COMSOL returns y=0, which is not correct.

I also tried it this way:

y = f(x) * (0<x) * (x<1)

Here both if conditions are evaluated as 1, resulting in the correct solution y = f(x).

I monitored the values of the if expressions with Point Probe Expressions during the calculation procedure.

Why is there a difference in the evaluation of the same if conditions?

Thanks for your effort!


1 Reply Last Post 2017年7月13日 GMT-4 05:24
Henrik Sönnerlind COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 7 years ago 2017年7月13日 GMT-4 05:24
Hi,

Your second version is correct.

The first will be interpreted as ((0<x)<1)=(1<1)=0

Regards,
Henrik
Hi, Your second version is correct. The first will be interpreted as ((0

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.