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.

Heavyside-Function and Divison by Zero

Please login with a confirmed email address before reporting spam

Hi

I stumble realising a Gaussian-beam like in the tutorial model "Nanorods" (using RF-module).

Problem:
Part of the wave function has a singularity: constant/z
Solution in tutorial:
Define a piecewise-function covering the singularity like:
z<-z0 : constant/z
-z0<z<z0 : constant/z0
z0<z : constant/z

But in contrary to the example I need frequency-dependent borders respectively frequency-dependent z0 [Z0(freq)].
As this is not possible with piecewise-function (i guess) i tried a sum of Haevyside-functions (like recommended in several forum-posts):
(constant/z)*flc2hs(-z-Z0(freq),range)
+(constant/z0)*flc2hs(z+Z0(freq),range)*flc2hs(-z+Z0(freq),range)
+(constant/z)*flc2hs(z-Z0(freq),range)

Does the same when being plotted from the Global_Definition/Anayltics-Node. Produces also no error when the model is being computed. But trying to plot from Solution1-Node producing the error:
Evaluation of result expression failed
Error in user-defined function
Failed to evaluate expression

This error does not occur if the (constant/z)-function is replaced by a non-singularity-function. So plotting after computing messes somehow with the Heavyside-function.

Any idea or experience how to get that work? This starts to erode my self-confidence.

Thanks for any help


edit: Problem was, i think, not the above expression but the fact that inside of the wave-function something gets divided by that expression. And i think the smoothening of the heavyside-function leads to a zero at the singularity. And then again divided by zero ^.^ -> error
Though i am not sure.

But in this case using the inverse function just works fine : )

2 Replies Last Post 12 feb 2013, 12:09 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 12 feb 2013, 11:14 GMT-5
Hi

if you plot your function as "something/z" with a "z=0" ituation you wil lend up with a NaN, isnt it that what happens, so you need to ensure you are never close to z=0, even when the solver is searching for new values

--
Good luck
Ivar
Hi if you plot your function as "something/z" with a "z=0" ituation you wil lend up with a NaN, isnt it that what happens, so you need to ensure you are never close to z=0, even when the solver is searching for new values -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 12 feb 2013, 12:09 GMT-5
Thx Ivar for reply.

It was the case that i did not fully understand my own problem : )
It is like:

Something/R(z) and R(z)=Anything/z

I was just looking at R(z) and taking care of it by adding heavyside-functions.
Now i think the smoothening of this functions lead to R(0)=0 somewhere between R(-0.01)=-infinity and R(0.01)=infinity. And then Something/R(z) causes problems.

I am just guessing because:
Something*R(z) made no problems.

When realizing that the trouble came from Something/R(z) I just used Something*R(z)^(-1).
That works fine ; )

Maybe I will run some trial&errors to ensure my thoughts.

Sry for circumstances, i did not delete my topic because maybe it helps someone. As far as is see I can not tag it as solved.

Have a nice evening!

Thx Ivar for reply. It was the case that i did not fully understand my own problem : ) It is like: Something/R(z) and R(z)=Anything/z I was just looking at R(z) and taking care of it by adding heavyside-functions. Now i think the smoothening of this functions lead to R(0)=0 somewhere between R(-0.01)=-infinity and R(0.01)=infinity. And then Something/R(z) causes problems. I am just guessing because: Something*R(z) made no problems. When realizing that the trouble came from Something/R(z) I just used Something*R(z)^(-1). That works fine ; ) Maybe I will run some trial&errors to ensure my thoughts. Sry for circumstances, i did not delete my topic because maybe it helps someone. As far as is see I can not tag it as solved. Have a nice evening!

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.