symbolic calculation

Why do I get
>> a = sqrt(sym(2))
a =
1/2
2
instead of
a = 2^(1/2)
And I got >> H = sym(hilb(2))
H =
[ 1. 0.500000000000000]
[ ]
[0.500000000000000 0.333333333333333]
instead of the fraction version. Is there any expert who can tell me how to set this? I use the mathlab 2010b.

 採用された回答

Walter Roberson
Walter Roberson 2011 年 3 月 31 日

1 投票

For the first point, try turning off pretty printing
evalin(symengine, 'PRETTYPRINT := FALSE');
I do not promise that it will work, though. If it doesn't, then
char(a)
should show you the linear form.
I don't know why the decimal form is given for the hilbert matrix. You could try, though,
evalin(symengine, 'linalg::hilbert(2)');

6 件のコメント

jack
jack 2011 年 3 月 31 日
Hmm, I don't know why I got the following when I tried your suggestion.
>> evalin(symengine, 'PRETTYPRINT := FALSE')
??? Undefined function or variable 'symengine'.
and
evalin(symengine, 'linalg::hilbert(2)')
??? Undefined function or variable 'symengine'.
jack
jack 2011 年 3 月 31 日
I was wondering that if there is a way for converting between the decimal and the fraction forms for the "symbol" case I mentioned in the question.
Walter Roberson
Walter Roberson 2011 年 3 月 31 日
Which Matlab version are you using? If you are using a version old enough that it uses Maple instead of MuPad, then as best I recall sym() did not automatically convert to rational back then (but I could be wrong.)
If you have the Maple engine, try
maple( subs('convert(H,rational)','H', hilb(2)) )
jack
jack 2011 年 3 月 31 日
The version I used is MATLAB 7.11.0.584(R2010b). I still got
>> maple( subs('convert(H,rational)','H', hilb(2)) )
ans =
[ 1. 0.500000000000000000]
[ ]
[0.500000000000000000 0.333333333333333315]
I find that I don't have the symbolic math toolbox in my matlab. Maybe this is the reason.
Walter Roberson
Walter Roberson 2011 年 3 月 31 日
2010b cannot use Maple. If it doesn't know symengine, the implication would be that you do not have the symbolic toolbox, except then I would have expected it to fail on sym . I'm surprised you are getting anywhere with those commands if you don't have the symbolic toolbox.
jack
jack 2011 年 3 月 31 日
Hmm, that's the key point. Everything will be OK with the symbolic toolbox.

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

その他の回答 (1 件)

jack
jack 2011 年 3 月 31 日

0 投票

The key point is that the MATLAB one uses needs to have the symbolic toolbox. Otherwise, one can not go further for the symbolic calculation.

Community Treasure Hunt

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

Start Hunting!

Translated by