Output in MatLab has a capped amount of decimal points [duplicate]

試著忘記壹切 提交于 2019-12-02 21:07:33

问题


I have modified some code in MatLab so that it will give me the root of the function cos(x) - 3*x. When I run the code and ask for it to return the value of xnew (as xnew should equal the root of the function) it returns xnew to only 4 decimal points. I would like for it to be more than this. Does anyone know why it capping this value?

x = 0;
N = 100000; Tol = 0.00001;
count = 1;
while count <= N
f = cos(x) - 3*x;
Df = -sin(x) - 3;
d = (f/Df);
xnew = x - (d);
if (abs(xnew - x)) < Tol
break
end
x = xnew;
count = count + 1;
end

回答1:


Run format long;. That will set the display to 15 or 16 significant figures. The default is 4-5 significant figures. To reinstate the default, run format short;.



来源:https://stackoverflow.com/questions/32664240/output-in-matlab-has-a-capped-amount-of-decimal-points

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