"Daniel Karssen" <NoSpamj.g.d.karssen@NoSpamtudelft.nl> wrote in message
> "Daniel Karssen" <NoSpamj.g.d.karssen@NoSpamtudelft.nl> wrote in message
>> Today I upgraded to the 2009b version of Matlab and now I got a strange
>> error while using the symbolic tool. For the input:
>> syms a
>> matlab returns
>> ans =
>> and not zero.
>> I believe I did not have this error with the 2007b version. However my
>> license does not allow me anymore to use that version, so I can not test
>> it. Is there a way to fix this error or is there a workaround?
> Found the answer myself.
> pi = sym('pi')
> Does the trick.
When you compute cos(pi/2) you're computing that in double precision (and
this does not give an exact 0, for reasons that have been discussed in the
past on this newsgroup.) At the next step, when you multiply that very
small double precision result by a, the small double precision result is
converted into a symbolic number. That number is also not exactly 0, but
Rather than redefining the variable pi, I would probably do something like:
piOver2 = sym('pi')/2;
or simply move the SYM call into the expression directly, if you only need
to use pi/2 once.
Dividing a symbolic pi by 2 converts the 2 into a symbolic value and then
performs the division symbolically, so you avoid double precision roundoff
This is the same general reason that:
x1 = sym(10^1000)
gives a much different result from:
x2 = sym(10)^1000
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on