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
Posted 2011/03/11 5:59 GMT-5 7 Replies
Please login with a confirmed email address before reporting spam
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.
Please login with a confirmed email address before reporting spam
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
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
Please login with a confirmed email address before reporting spam
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
Please login with a confirmed email address before reporting spam
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
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
Please login with a confirmed email address before reporting spam
have you tried the filter and (x<5)*(y>2) 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.
Suggested Content
- BLOG How to Use State Variables in COMSOL Multiphysics®
- KNOWLEDGE BASE How do I solve a PDE with space derivatives of order higher than two?
- KNOWLEDGE BASE Solving time dependent models with inconsistent initial values
- BLOG Solutions as Starting Point Values with LiveLink™ for MATLAB®
- FORUM if statement
