是什么导致了这个奇怪的 Mathematica 结果? [英] What is causing this strange Mathematica result?

查看:40
本文介绍了是什么导致了这个奇怪的 Mathematica 结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Mathematica 8 中遇到了一个 bug.我在网上找不到与它相关的任何内容,但我承认我不确定要搜索什么.

I've run into what seems like a bug in Mathematica 8. I can't find anything related to it online, but I admit I'm not exactly sure what to search for.

如果我运行这个语句:

0.05 + .10 /. {0.15 -> "pass"}
1.04 + .10 /. {1.14 -> "pass"}
1.05 + .10 /. {1.15 -> "pass"}
1.15 /. {1.15 -> "pass"}

我得到这个输出:

pass

pass

1.15

pass

我只是忽略了什么吗?

在阅读下面有用的讨论后,我更改了我的调度表,改为使用 which 语句:

After reading the helpful discussion below, I changed my dispatch table to use a Which statement instead:

f[x_] := Which[x == 1.05, -1.709847, x == 1.10, -1.373823, 
  x == 1.15, -1.119214, x == 1.20, -0.9160143, x == 1.25, -0.7470223, x == 1.30, -0.6015966]

这似乎可以解决问题.

推荐答案

欢迎来到机器精度的世界.如果您更仔细地检查 1.05 +.10 和 1.15,您会发现它们并不完全相同:

Welcome to the world of machine precision. If you examine 1.05 +.10 and 1.15 more closely, you'll see that they're not quite the same:

1.05 + .10 // FullForm

==> 1.1500000000000001`

1.15 // FullForm

==> 1.15`

这篇关于是什么导致了这个奇怪的 Mathematica 结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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