Why does poly() not evalp

I have an example:
evalp( poly( sqrt( 1-x^2 ), [x] ), x=cos(0.5) )
This gives (sqrt(1-x^2)) as the response.
The expected result is only given by
evalp( poly( sqrt( 1-x^2 ), [x] ), x=cos(0.5) ) | x=cos(0.5)
And evalp works as expected with simple expression like
evalp( poly( x, [x] ), x = 1 )
Is this a bug?

 採用された回答

Walter Roberson
Walter Roberson 2011 年 6 月 15 日

0 投票

sqrt( 1-x^2 ) is not a polynomial. evalp() is only for evaluating polynomials.
I am not familiar with the way you used "|" in your second expression. I looked through the Standard Library but I do not find any meaning defined for "|" . Could you give a reference on that?

4 件のコメント

Billy
Billy 2011 年 6 月 15 日
So can you eval the expression without using |? | can also be used for evaluating any function, I cannot remember where I first saw it, will post a reference when I do.
Walter Roberson
Walter Roberson 2011 年 6 月 15 日
Found the | notation: it is a shortcut for evalAt() http://www.mathworks.com/help/toolbox/mupad/stdlib/evalAt.html
Evaluation:
level(subs(sqrt(1-x^2),x=cos(0.5)),1)
or perhaps the ,1 might need to be ,2 -- that would have to be tested.
I would probably tend to instead use
eval(subs(sqrt(1-x^2),x=cos(0.5))
which is a bit different than the level() version with respect to symbols in the expression that might have been assigned a value. evalp() is defined to *not* evaluate the other symbols indefinitely.
Well... actually what I would probably use myself is
eval(sqrt(1-x^2),x=cos(0.5))
in Maple. This is similar to MuPad's evalAt() .
Is there a specific reason you are using poly() instead of just an expression ? Do you care about the number of levels of evaluation of symbols, for example?
Billy
Billy 2011 年 6 月 15 日
I'm using poly() to simulate the output of my P function I just wrote, which outputs a poly() (in turn because orthpoly::legendre outputs a poly).
Ultimately I'm trying to evaluate the legendre polynomials with cos(t) in the place of x in legendre(n,x).
Billy
Billy 2011 年 6 月 15 日
The P function is here: http://www.mathworks.com/matlabcentral/answers/9485-how-do-i-specify-m-for-orthpoly-legendre

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSymbolic Math Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by