I was banging my head against the wall looking for the error in my code, that kept returning "false" when it should have returned true. I finally realised that my error was because in MATLAB (or at least in my copy) pi^0.5^2==pi returns "false". The same goes for sqrt(pi)^2==pi. I assume this is because the machine precision of pi is more exact then the machine precison of the square root function, even though they are identical up to 16 digits.
I have some unelegant solutions to this. e.g writing down pi=3.141592 at the begining of my code. is there a better solution? a more percise calculaion of the square root?
many thanks
5 Comments
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/715788-square-root-of-pi#comment_1260988
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/715788-square-root-of-pi#comment_1260988
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/715788-square-root-of-pi#comment_1261133
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/715788-square-root-of-pi#comment_1261133
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/715788-square-root-of-pi#comment_1261193
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/715788-square-root-of-pi#comment_1261193
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/715788-square-root-of-pi#comment_1261198
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/715788-square-root-of-pi#comment_1261198
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/715788-square-root-of-pi#comment_1261323
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/715788-square-root-of-pi#comment_1261323
Sign in to comment.