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.

To check whether a variable is an integer?

Please login with a confirmed email address before reporting spam

Hi,

Is it possible to check whether the value of the variable at a particular timestep is an integer? Is there any function that I can use to find this?

Thanks.

5 Replies Last Post May 6, 2012, 7:16 a.m. EDT
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 May 2, 2012, 5:25 p.m. EDT
Hi

never hear of that, but perhaps something like ((x-floor(x))<eps) might work, but check carefully the positive and negative side effects, and you ight need several times of "eps" if x is getting large

--
Good luck
Ivar
Hi never hear of that, but perhaps something like ((x-floor(x))

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago May 2, 2012, 5:34 p.m. EDT
Possibly, we could use the 'mod' function i.e.

If mod(var,1) == 0 , it is an integer;

If you use matlab scripting 'isinteger' function could be used.
Possibly, we could use the 'mod' function i.e. If mod(var,1) == 0 , it is an integer; If you use matlab scripting 'isinteger' function could be used.

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 May 3, 2012, 3:05 a.m. EDT
Hi

but what about the numerical precision ? in "automatic" mode COMSOL might stop and solve for a value very close to the integer, but not exactly "on" it

--
Good luck
Ivar
Hi but what about the numerical precision ? in "automatic" mode COMSOL might stop and solve for a value very close to the integer, but not exactly "on" it -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago May 3, 2012, 10:02 a.m. EDT
Yes, we need to use some threshold (eps) as Ivar suggested in last post.
Yes, we need to use some threshold (eps) as Ivar suggested in last post.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago May 6, 2012, 7:16 a.m. EDT
Thanks Ivar and Mranal. I used (ceil(t)-t<eps) and it works well. Thanks for your input.
Thanks Ivar and Mranal. I used (ceil(t)-t

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.