问题
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