Note: This discussion is about an older version of the COMSOL Multiphysics® software. The information provided may be out of date.

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.

How to do "if---else" in comsol GUI?

Please login with a confirmed email address before reporting spam

How to write the equivalent "phi" expression in GUI according to the codes below ?

if x==0
if y>0
phi=0.5*pi
else
phi=-0.5*pi
else if x>0
if y>0
phi=atan(y/x)
else
phi=2*pi+atan(y/x)
else
phi=pi+atan(y/x)

ps: x, y are the space independent variables, phi is a user-defined variable

my ways is: phi=(x==0&&y>0)*(0.5*pi)+(x==0&&y<=0)*(-0.5*pi)+(x>0&&y>0)*(atan(y/x))+(x>0&&y<=0)*(2*pi+atan(y/x))+(pi+atan(y/x)). Is it right? or are there better ones?

1 Reply Last Post 22 gen 2011, 12:34 GMT-5
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 22 gen 2011, 12:34 GMT-5
Hi

I have seen the "if()" way, your way and the one replacing the && and ¦¦ by */+ i believe all work, but have newer tested the issue w.r.t speed, have you tried these variants as "functions" and used COMSOL to plot them ? That's my way to test the equations.

--
Good luck
Ivar
Hi I have seen the "if()" way, your way and the one replacing the && and ¦¦ by */+ i believe all work, but have newer tested the issue w.r.t speed, have you tried these variants as "functions" and used COMSOL to plot them ? That's my way to test the equations. -- 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.