如何在 Mathematica 中将有理数转化为实数
我这里有一些问题,我不知道如何以好的方式解决。例如,我想使用 BaseForm[1/3, 3]
。但是,除非我输入 BaseForm[1/3.,3]
,否则这不会达到我的预期。给定有理数形式的数据,如何将其转换为实数形式?我尝试使用Apply
,它不起作用。 (很奇怪,呃?对我来说,Apply 总是可以用来更改标题。)
对于这个具体问题,我可以做类似 BaseForm[1/3*1.,3]
的事情,但是这真的不太好。
感谢您的帮助。
I have some issue here which I don't know how to solve in a good way. For example, I want to use BaseForm[1/3, 3]
. However, this does not do what I intended unless I input BaseForm[1/3.,3]
. Given the data in Rational form, how to turn it to Real? I tried with Apply
, it does not work. (Strange enough, uh? To me, Apply can always be used to change header.)
To this specific problem, I could have done something like BaseForm[1/3*1.,3]
, but it really isn't very nice.
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
BaseForm
将 10 基数的有理数转换为您想要的任何基数的有理数...因此它可以满足您的期望。正如您所指出的,给它一个实数可以这样做:
最安全的改变方式是定义您自己的
baseForm
,它与BaseForm
相同,除了当给定有理数时:那么
不太安全的方法(因为你不知道它还会破坏什么)是重新定义
BaseForm
然后正常使用。
BaseForm
takes a rational in base 10 to a rational in what ever base you want... so it does what you expect.And as you pointed out, giving it a Real number can be done like:
The safest way to change things would be to define your own
baseForm
which is the same asBaseForm
except for when it's given rational numbers:Then
The less safe way (because you don't know what else it might break) is to redefine
BaseForm
and then use as normal.
我可能错过了您请求的微妙之处,但如果您总是想要实数输出,为什么不只使用
N
呢?I may be missing the subtlety of your request, but if you always want a real-number output, why not merely use
N
?