problem with psi digamma function

6 visualizzazioni (ultimi 30 giorni)
Ali
Ali il 1 Feb 2012
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?

Risposte (2)

Walter Roberson
Walter Roberson il 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 Commenti
Ali
Ali il 2 Feb 2012
Thanks!
I tried your suggestion but got this:
psi(sym(1), sym(1/2))
??? Error using ==> psi
Too many input arguments.
I suspect I have a version of matlab that doesn't have the updated psi function? I am using 2010a and saw since I posted this question that the psi function was updated in the 2011 version.
Walter Roberson
Walter Roberson il 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.

Accedi per commentare.


Kai Gehrs
Kai Gehrs il 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

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by