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.

Using 'if' statement with two conditions

Please login with a confirmed email address before reporting spam

Hi,

I want to use and if statement in COMSOL but I need it to have two conditions.

I want to calculate the value of the x coordinate when y = 0 and T=300.
Something like:
if(y ==0 and T == 300, xi == x)

Would the AND logical operator (&&) work instead of the and in my above statement?
No matter what I try I get errors.

Someone mentioned in a previous post that my if statement must not contain discontinuities and that they can be avoided by combining the if and sens operators, I don't understand how to do this though.

I would really appreciate some help with this problem!

Thanks,
-Adam.

7 Replies Last Post 2012年7月25日 GMT-4 02:09
Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2011年3月11日 GMT-5 08:13
Hi

the discontinuity issue is when you use such Dirac functions for the physics, then the solver might "jump over them"

perhaps if you use more (), or try a boolean

(x==0)*(T==300)*YourValue

--
Good luck
Ivar
Hi the discontinuity issue is when you use such Dirac functions for the physics, then the solver might "jump over them" perhaps if you use more (), or try a boolean (x==0)*(T==300)*YourValue -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2011年3月11日 GMT-5 09:56
Hi Ivar,

Thanks for the quick reply.

I understand what you are saying.

However I wish to assign the variable xi to the value of x when T=300 and y=0.
So that if both T=300 and y=0 are true (then equal to one) then whatever the x coordinate at the point is gets assigned to xi.

If I use the expression you suggested then xi comes back with a value of 0.

I am trying to use an if statement to get the value I want but keep getting a value of 0 for xi:

if(T==300 && y == 0,xi == x)

I hope I have made my problem clear!

I would really appreciate some help!

Thanks,
-Adam
Hi Ivar, Thanks for the quick reply. I understand what you are saying. However I wish to assign the variable xi to the value of x when T=300 and y=0. So that if both T=300 and y=0 are true (then equal to one) then whatever the x coordinate at the point is gets assigned to xi. If I use the expression you suggested then xi comes back with a value of 0. I am trying to use an if statement to get the value I want but keep getting a value of 0 for xi: if(T==300 && y == 0,xi == x) I hope I have made my problem clear! I would really appreciate some help! Thanks, -Adam

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2011年3月11日 GMT-5 11:06
Hi

then what about:

Your_value = (y==0)*(T==300)*(My_New_Value - Some_other_value) + Some_other_value

--
Good luck
Ivar
Hi then what about: Your_value = (y==0)*(T==300)*(My_New_Value - Some_other_value) + Some_other_value -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2011年3月11日 GMT-5 17:56
There are some descriptions about the if operator in the User's Guide. It said the expression is if(cond, expr1, expr2), I am not sure whether expr2 is necessary or not. You can see the Guide for details.
There are some descriptions about the if operator in the User's Guide. It said the expression is if(cond, expr1, expr2), I am not sure whether expr2 is necessary or not. You can see the Guide for details.

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2011年3月12日 GMT-5 04:36
Hi

there are two places whree aou can test out formulas:

- the parameter line that calcualtes out your value (and translates the units)
- the analytical function, whcih allows you quickly to plot a function. I mostly write my complex fomulas as functions, as then I can plot them easily to check how they look, its so easy to forget a sign, or an offset. Alwaysmverify and validate your work,in steps it's easier ;)

--
Good luck
Ivar
Hi there are two places whree aou can test out formulas: - the parameter line that calcualtes out your value (and translates the units) - the analytical function, whcih allows you quickly to plot a function. I mostly write my complex fomulas as functions, as then I can plot them easily to check how they look, its so easy to forget a sign, or an offset. Alwaysmverify and validate your work,in steps it's easier ;) -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2012年7月24日 GMT-4 20:52
Are there any way to make a 2D function?

I can easily plot the function f=(x<= 5).

But how to plot a function f=(x<=5,y<=5) in a 2D plan.

Cheers,
Dao
Are there any way to make a 2D function? I can easily plot the function f=(x

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2012年7月25日 GMT-4 02:09
Hi

have you tried the filter and (x<5)*(y>2) condition, or whatever Boolena condition you need ?

--
Good luck
Ivar
Hi have you tried the filter and (x2) condition, or whatever Boolena condition you need ? -- Good luck Ivar

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.