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 6 mag 2012, 07:16 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 2 mag 2012, 17:25 GMT-4
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 2 mag 2012, 17:34 GMT-4
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 3 mag 2012, 03:05 GMT-4
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 3 mag 2012, 10:02 GMT-4
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 6 mag 2012, 07:16 GMT-4
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.