problem with psi digamma function
3 views (last 30 days)
Show older comments
Can anyone help? I try to use the psi function to evaluate a complex number. It suggests in the help that I should convert number to sym first and then evaluate. I tried the examples in the math works page: http://www.mathworks.co.uk/help/toolbox/symbolic/psi.html
This works: [psi(1/2) psi(2, 1/2) psi(1.34) psi(1, sin(pi/3))] ans =
-1.9635 -16.8288 -0.1248 2.0372
But then when I tried this:
[psi(sym(1/2)), psi(1, sym(1/2)), psi(sym(1/4))] ??? Error using ==> psi Input must be single or double.
Please any help with this?
0 Comments
Answers (2)
Walter Roberson
on 2 Feb 2012
Sorry, system ate my earlier response:
Your expression psi(1, sym(1/2)) has a double precision number as the first parameter, so the MATLAB psi routine is the one that is dispatched. And then that routine complains because the second parameter is not a floating point number.
Cure: psi(sym(1), sym(1/2))
Better yet: psi(sym(1), sym(1)/sym(2))
or psi(sym(1), sym('1/2'))
Remember, sym() with a numeric expression as a parameter will evaluate the numeric expression before passing it to sym. sym() on a quoted will treat the expression in the string symbolically.
2 Comments
Walter Roberson
on 2 Feb 2012
Looks like there was no direct interface to psi in R2010a; it is not in the Special Functions list http://www.mathworks.com/help/releases/R2010a/toolbox/symbolic/f3-157665.html#f3-15507
psi does exist in MuPad in R2010a and can be invoked through
feval(symengine, 'psi', sym(1/2), sym(1))
http://www.mathworks.com/help/releases/R2010a/toolbox/mupad/stdlib/psi.html
Please note that this used the arguments in the other order than the R2011 MATLAB psi() interface to the MuPAD psi() routine.
Kai Gehrs
on 7 Feb 2012
Hi Ali,
just for the future: you may want to have a look at
mfunlist
in the Symbolic Math Toolbox interface in MATLAB. This gives access to special functions available in MuPAD by a more convenient syntax than maybe the
evalin
command does. For example
mfun('Psi',2,4)
corresponds to
psi(2,4)
but internally calls MuPAD's implementation of the PSI function.
Hope this helps a bit and best regards,
-- Kai
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!