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.

1-. Picewise function defined with variables, does not work. 2-. How defining Matlab functions works?

Please login with a confirmed email address before reporting spam

Hi, everything is said in the title.

I know how to apply piecewise functions with numbers, but it does not allow me to use variables on the start-end intervals or in the "function", where you specify the function for each tram.

Do you know a way to do it? I really need to define a function, continuous and derivable, made with 5 parabolas. Later on the simulation, I must use that function, so I really need to define this kind of thng... maybe there are some tricks to do it (with if conditions, maybe...???)

I would thank your help a lot!

regards,

6 Replies Last Post 01.10.2012, 15:52 GMT-4
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 26.09.2012, 09:06 GMT-4
Hi
probably the only way around is to write out two analyitcal function "ana1_f(x,y)" or some combination "ana1_fx(x,y)" and "ana2_fy(x,y)" such that the product "ana1_fx*ana2_fy" or your unique "ana1_f" function gives ou the appropriate elevation for any boundary coordinate (x,y)

Note that the (x,y) call is mostly implicit in COMSOL via the boundary selection

--
Good luck
Ivar
Hi probably the only way around is to write out two analyitcal function "ana1_f(x,y)" or some combination "ana1_fx(x,y)" and "ana2_fy(x,y)" such that the product "ana1_fx*ana2_fy" or your unique "ana1_f" function gives ou the appropriate elevation for any boundary coordinate (x,y) Note that the (x,y) call is mostly implicit in COMSOL via the boundary selection -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 26.09.2012, 09:28 GMT-4
Thanks a lot for your reply, but sincerely, I do not understand too much your point...

Just an extra question, wasn't there a way to write piecewise functions in form of a long expressions with "and, if" commands on it? I remember to have seen that somewhere...

edit: I have seen also called Matlab function. The (no-)help of COMSOL says that it is to define a function in Matlab, and use it here. It would solve my problem. Indeed, I have it working in Matlab :).

Any idea about this?

Thanks in advance for any answer,
Thanks a lot for your reply, but sincerely, I do not understand too much your point... Just an extra question, wasn't there a way to write piecewise functions in form of a long expressions with "and, if" commands on it? I remember to have seen that somewhere... edit: I have seen also called Matlab function. The (no-)help of COMSOL says that it is to define a function in Matlab, and use it here. It would solve my problem. Indeed, I have it working in Matlab :). Any idea about this? Thanks in advance for any answer,

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 26.09.2012, 14:44 GMT-4
Hi

probably I did neither not fully understand your issue ;)

If you have Matlab (but perhaps you also need livelink to ... ?) then you can define a function in matlab and call it, indded, that is a way.

Still there must be a way within the GUI too

Using bollean expressions is always possible, it's like using if(,,) another way.

--
Good luck
Ivar
Hi probably I did neither not fully understand your issue ;) If you have Matlab (but perhaps you also need livelink to ... ?) then you can define a function in matlab and call it, indded, that is a way. Still there must be a way within the GUI too Using bollean expressions is always possible, it's like using if(,,) another way. -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 01.10.2012, 04:18 GMT-4
Thanks a lot (always) for your replies, Ivar. You really help hundreds of people here!.

Could you write a very simple example of how to use that? I do not have any idea of the syntaxes.

Consider this: x axis is mass, y axis is temperature (for example), and the function would be:

T=4m^2 (if 200<T<300) and T=2m (if T>=300)

It is a very simple example that I ask you to tell me to understand the syntaxes. I think that is easy for you, ;-)


writen in a single line, please. (this example is easy to implement with "piecewise function", the problem is that, in my piecewise function, the ranges depend on Temperatures, so I should write variables there, instead of Constants!!! I mean, looking at that function above, something like this: T=4m^2 (if var1<T<var2) and T=2m (if T>=var) , where "varx" are values that depends on Temperature... Quite complex for me!) The piecewise function does not allow me to introduce variables there in the ranges!


Thanks a lot!!
Thanks a lot (always) for your replies, Ivar. You really help hundreds of people here!. Could you write a very simple example of how to use that? I do not have any idea of the syntaxes. Consider this: x axis is mass, y axis is temperature (for example), and the function would be: T=4m^2 (if 200

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 01.10.2012, 05:19 GMT-4
Ey, I have just got it!!!!

For all the people:

H1*(x<var1)+H2*(x<=var1&&var3<x)+H3... Where Hi are the functions on each range.

:-)

Still, Ivar, thanks, and any other suggestion is more than welcome!
Ey, I have just got it!!!! For all the people: H1*(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 01.10.2012, 15:52 GMT-4
Hi

often it's like this, once you write out an issue, then you find the solution. Anyhow, I'm also quite busy and not here on the Forum each day ;)

--
Good luck
Ivar
Hi often it's like this, once you write out an issue, then you find the solution. Anyhow, I'm also quite busy and not here on the Forum each day ;) -- 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.