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.

Syntax of writing conditional statements on comsol

Please login with a confirmed email address before reporting spam

I want to implement following conditions for a variable g

g = 1 for T>1439

g= (T-1450)/100 for 1339>T>1439

g= 0 for T<1339

what is the syntax for writing the such statements?
can anyone please help?

2 Replies Last Post 30.01.2017, 02:54 GMT-5
Gunnar Andersson COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 7 years ago 30.01.2017, 02:26 GMT-5

I want to implement following conditions for a variable g

g = 1 for T>1439

g= (T-1450)/100 for 1339>T>1439

g= 0 for T<1339

what is the syntax for writing the such statements?
can anyone please help?


The general syntax for conditional statements is if(condition,true_branch,false_branch). You can use two nested if()-calls to express the condition for g above. You can also use a piecewise function. This is more readable if there are many branches.

[QUOTE] I want to implement following conditions for a variable g g = 1 for T>1439 g= (T-1450)/100 for 1339>T>1439 g= 0 for T

Please login with a confirmed email address before reporting spam

Posted: 7 years ago 30.01.2017, 02:54 GMT-5
Thank you.

I used the piecewise function.
solved the problem.
Thank you. I used the piecewise function. solved the problem.

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.