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 do I write three functions to one in comsol?

Please login with a confirmed email address before reporting spam

Excuse me. I want to ask a question. when 0=<t<=1, the function is f(t). When 1<t<=2, the function is g(t). When 2<t<=3, the function is h(t). How can the three functions be written one? I write "f(t)*(t>=0&t<=1)+g(t)*(t>1&t<=2)+h(t)*(t>2&t<=3)", but it is wrong. What shoud I do?

Best your wishes,

Xin Wei

2 Replies Last Post 2013年7月21日 GMT-4 19:01

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2013年7月21日 GMT-4 14:27
Hi,


What do you mean by wrong, what happens? Did you try replacing & with &&.


Suresh
Hi, What do you mean by wrong, what happens? Did you try replacing & with &&. Suresh

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2013年7月21日 GMT-4 19:01
I have found that the *(t>1) or *(c>0) etc operators can be a little bit unreliable in some models. I have had more success with if statements. So for your function, that could be written as

F(t) = if(t>1, if(t>2, h(t), g(t)), f(t))

If you have additional values of t outside of the range [0,3] then you may need an extra if loop to close these.

I know this is a little inefficient, but I have run both time- and concentration-dependent functions in the past, and found that this is a more reliable method.
I have found that the *(t>1) or *(c>0) etc operators can be a little bit unreliable in some models. I have had more success with if statements. So for your function, that could be written as F(t) = if(t>1, if(t>2, h(t), g(t)), f(t)) If you have additional values of t outside of the range [0,3] then you may need an extra if loop to close these. I know this is a little inefficient, but I have run both time- and concentration-dependent functions in the past, and found that this is a more reliable method.

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.