精度问题 [英] Problem With Precision

查看:94
本文介绍了精度问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家下午好,

我偶然发现了一个有趣的问题,希望有人可以指出解决方案.首先让我们知道,该解决方案已经在MATLAB中进行了编码,似乎可以很好地处理.

Matlab代码: http://pastebin.com/ckUPueLW [ ^ ]
数据文件: http://pastebin.com/vzhTSeTA [ ^ ]

随时运行mfile来查看过滤后的信号看起来是什么.

我已将其实现为C ++类,但未获得预期的结果.滤波后的值Y(m)攀升并攀升至无穷大,我开始相信它与减除非常小的数字(* dun dun dun *)有关.我已经在此处上传了c ++代码的输出.如果您想随意看看.设置输出的方式与在m文件中组织注释的方式相同. X(m)代表原始输入信号,Y(m)代表滤波后的输出信号.

请注意,我的滤波器系数约为e-8,我的大多数值都带有较大的有效数字.我决定不发布c代码,主要是因为我不相信代码中有错误,但是如果有人认为这会有所帮助,我会非常乐意.如果取消注释m文件输出行,则可以在调试模式下逐步执行,并将这些值与文本文件进行比较.它们都非常接近,但总是略微偏离,我相信这会使我的c ++ Y(m)向上和向上传播.

我对所有变量都使用双精度.我认为,对于我的问题避免溢出,下溢和精度损失,这篇文章应该会有所帮助. [ ^ ]但我不知道如何将其应用于我的特定问题.

谢谢

Don

Afternoon everyone,

I''ve stumbled across an interesting problem and I was hoping someone may be able to point me towards a solution. First let it be known that the solution has been coded in MATLAB where it seems to be handled fine.

Matlab Code: http://pastebin.com/ckUPueLW[^]
Data File: http://pastebin.com/vzhTSeTA[^]

Feel free to run the mfile to see what the filtered signal looks like.

I have implemented this as a C++ class and am not getting the desired results. The filtered value Y(m) climbs and climbs to infinity and I''m starting to believe it has to do with SUBTRACTING REALLY SMALL NUMBERS (*dun dun dun*). I have uploaded the output of the c++ code here. If you''d like to take a look feel free. The output is set up the same way the comments were organized in the m-file. X(m) refers to the raw input signal and Y(m) refers to the filtered output signal.

Note that my filter coefficients are at the order of e-8 and most of my values carry large significant figures. I have decided not to post the c code, mainly because I don''t believe there is an error in the code but if anyone thinks that will help I would be more than happy to. If you un-comment the m-file output lines, you can step through it in debug mode and compare the values with the text file. They are all very close but always slightly off, which I believe is compounding and sending my c++ Y(m) onward and upward.

I use doubles for all of my variables. I believe this article should be helpful with respect to my issue, Avoiding Overflow, Underflow, and Loss of Precision[^] but I can not figure out how to apply this to my specific problem.

Thanks

Don

推荐答案

尝试使用 Gnu bc 进行操作[^ ]

bc是一种任意精度的数值处理语言.语法类似于C,因此测试起来不容易-尝试将c ++代码移至bc.

确保您没有将SSE2等用于浮点处理(vc ++编译器选项).

使用 _control87,_controlfp,__ control87_2 [
还有
GNU多精度算术库 [ ^ ],或者您可以查看高精度软件目录 [ ^ ]

最好的问候
Espen Harlinn
Try to do it with Gnu bc[^]

bc is an arbitrary precision numeric processing language. Syntax is similar to C so testing it out shouldn''t be to hard - try moving your c++ code to bc.

Ensure that you are not using SSE2 etc for floating point processing (vc++ compiler option).

Use _control87, _controlfp, __control87_2[^] to ensure that you are getting "real" 64-bit double support, and not 53-bit - _PC_64 vs _PC_53

There is also The GNU Multiple Precision Arithmetic Library [^], or you can look at the High-Precision Software Directory[^]

Best regards
Espen Harlinn


请参考John D. Cook的文章,在您的问题中已经提到过-简短而切合实际.如果您未能将其应用于代码,则应认真考虑您的学历.尽管所有含义都反映在实际的编程技术中,但与编程相比,这更多地是与应用数学和信息学有关的.或雇用自己的导师.我不认为在一个简短的CodeProject解决方案中解释您的问题会为其添加任何内容.

与该主题最接近的相关阅读是Donald Knuth的经典著作《计算机编程的艺术》.参见 http://en.wikipedia.org/wiki/Donald_Knuth [
Stick to the article by John D. Cook you''ve referenced in your question — it''s short and to the point. If you fail to apply it to your code, you should seriously think about your education. This is more about applied mathematics and informatics than programming, even though all implications are reflected in practical programming techniques. Or hire yourself a tutor. I don''t think explaining your issues in a short CodeProject solution will add anything to it.

The closest relevant reading on the topic would be classical ''The Art of Computer Programming'' by Donald Knuth. See http://en.wikipedia.org/wiki/Donald_Knuth[^].

—SA


这篇关于精度问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆