Hello i have one question. When I calculate a division in matlab: x/(pi.^2)
syms x
x/(pi.^2)
ans =
(281474976710656*v)/2778046668940015
the correct answer is x/9.8696, so why is matlab giving me this result?
Is it a bug?
You have to use the vpa() command "Variable-precision arithmetic". Check this code:
syms x real; % define x as a real symbolic variable (not a complex variable)
vpa( x/(pi.^2), 5) % second argument define number of significant digits
For trigonometric expressions involving pi, it is sometimes good to define sym('pi'):
syms x real;
pi_s = sym('pi');
expr = x/pi_s^2
I try to always use the 'real' tag when using the symbolic toolbox. If you do not use it you are going to see a lot of complex conjugates and other things that are not important for your problem, because x is probably real variable.
Hope this helps,
281474976710656/2778046668940015 ~= 1/9.8696. The symbolic math toolbox tries to preserve as much precision as possible by deferring floating point computations. Since pi is inherently irrational, it uses this approximation. - mbaumandouble(blah)from mathworks.com/help/symbolic/double.html - im so confusedsym('pi')to get a symbolic representation of pi rather than an approximation - im so confused