Pi, Matlab Symbolic math toolbox is there an error?

Hi, I have one question. When I calculate the division in matlab: x / (pi. ^ 2)

syms x x/(pi.^2) ans = (281474976710656*v)/2778046668940015 

The correct answer is x / 9.8696, so why does Matlab give me this result?

This is mistake?

+4
source share
2 answers

You need to use the vpa () variable precision arithmetic command. 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 useful 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 symbolic tools. If you do not use it, you will see many complex conjugations and other things that are not important for your problem, because x is probably a real variable.

Hope this helps,

+9
source

No, this is not an error:

 2778046668940015/281474976710656 = 9.8696 
+2
source

Source: https://habr.com/ru/post/1440114/


All Articles