MatLab中的输出的小数位数为上限 [英] Output in MatLab has a capped amount of decimal points
问题描述
我已经在MatLab中修改了一些代码,以便它将给我函数cos(x)-3 * x的根.当我运行代码并要求它返回xnew的值时(因为xnew应该等于函数的根),它仅将xnew返回到4个小数点.我希望它不仅限于此.有谁知道为什么要限制这个值?
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
推荐答案
运行format long;
.这样会将显示设置为15或16个有效数字.默认值为4-5个有效数字.要恢复默认设置,请运行format short;
.
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;
.
这篇关于MatLab中的输出的小数位数为上限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!