防止Matlab舍入输出? [英] Prevent Matlab from rounding output?
本文介绍了防止Matlab舍入输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在运行一个简单的脚本来估计函数的根.一切正常,算法的每次迭代都会打印出当前的x和f(x),但是当脚本完成并将x的最终估计值设置为函数的输出时,将返回该值并将其四舍五入到小数点后三位.
Im running a simple script to estimate roots for a function. Everything works great, each iteration of the algorithm prints off the current x and f(x), but when the script finishes and sets the final estimate of x as the output of the function the value is returned and rounded to 3 decimal places...
while k < maxit
k = k + 1;
dx = b - a;
xm = a + 0.5*dx; % Minimize roundoff in computing the midpoint
fm = feval(fun, xm, diameter, roughness, reynolds);
fprintf('%4d %12.20e %12.4e\n',k,xm,fm);
if (abs(fm)/fref < feps) | (abs(dx)/xref < xeps) % True when root is found
r = xm;
return;
end
这是输出的尾巴:
k xm fm
45 6.77444446476613980000e-003 1.3891e-012
46 6.77444446478035060000e-003 -1.3380e-011
47 6.77444446477324520000e-003 -5.9952e-012
48 6.77444446476969250000e-003 -2.3022e-012
49 6.77444446476791610000e-003 -4.5830e-013
ans =
0.0068
我不知道为什么要对输出进行四舍五入....我该如何防止呢?
i dont know why its rounding the output.... how do i prevent that?
推荐答案
在运行脚本之前尝试在命令行中键入'format longE'
try typing 'format longE' in the command line before running the script
这篇关于防止Matlab舍入输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文