Error with square root function and powers in Matlab R2014b [closed]

此生再无相见时 提交于 2019-12-14 03:22:21

问题


I am carrying out a series of calculations using the sqrt() function. My colleagues and I have noticed that we get different results when using the same inputs. Has anyone encountered this problem before?

This is an example:

input1 = 4;
input2 = 8;

result = sqrt(input1^2 + input2^2)

Result then displays a different value from my colleagues result. We have contacted MathWorks about this issue and have yet to receive a reply.


回答1:


My team and I came across the same problem a year or two ago.

MathWorks explained that the sqrt() function has an issue with powers when they are added. To overcome this issue and achieve the same result, square each term outside of the sqrt() function:

input1 = 4^2;
input2 = 8^2;

result = sqrt(input1 + input2)

This solved it for my team and I. MathWorks didn't clarify as to the reason for the issue, but told us they were in the process of updating their documentation (haven't seen anything as of yet).



来源:https://stackoverflow.com/questions/28497857/error-with-square-root-function-and-powers-in-matlab-r2014b

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!