Search code examples
matlabsymbolic-math

Symbolic Toolkit - Piecewise function gives NaN


So I have the following function:

psi(z,mu) = piecewise(mod(mu,2)==1, sin((mu+1)*z), mod(mu,2)==0, cos(mu*z)) ;

However this gives me psi(z,mu) = NaN for mu>2, and I am not sure why.


Solution

  • This seems to be a very odd issue that would appear to be a problem with using mod in the symbolic environment.

    A fix that I found to work was to just replace mod with mu-2*floor(mu/2), which is a definition of mod often used with languages that do not have the mod function.