Forgot password?
 Create new account
View 2049|Reply 5

小数乘法每次都只保留3位小数怎么算?

[Copy link]

418

Threads

1628

Posts

110K

Credits

Credits
11891

Show all posts

abababa Posted at 2015-9-1 21:58:20 |Read mode
例如有一个数$1.23$,要将它连乘$50$次$1.3$,但每次都必须四舍五入,只保留小数点后三位作为下一次的乘数,用Mathemtaica要怎么做呢?

418

Threads

1628

Posts

110K

Credits

Credits
11891

Show all posts

 Author| abababa Posted at 2015-9-1 22:28:34
会了,原来是用Nest函数
f[x_] := Round[(x*1.3)*1000]/1000
N[Nest[f, 1.23, 50]]

801

Threads

4889

Posts

310K

Credits

Credits
36169

Show all posts

isee Posted at 2015-9-6 14:30:59
回复 2# abababa


    这个要求好奇怪的。。。

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2015-9-6 14:34:17
不过我记得 Round 也不完全是四舍五入,好像 .5 的时候也有舍有入的

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2015-9-6 14:38:19
Round 实际上是取最接近的整数,但 .5 与两边一样近,所以就要另外规定。

In[1]:= Round[{{0.49, 0.5, 0.51},
  {1.49, 1.5, 1.51},
  {2.49, 2.5, 2.51},
  {3.49, 3.5, 3.51},
  {4.49, 4.5, 4.51}}]

Out[1]= {{0, 0, 1}, {1, 2, 2}, {2, 2, 3}, {3, 4, 4}, {4, 4, 5}}

可以看到,当 .5 出现时,总往偶数靠。

418

Threads

1628

Posts

110K

Credits

Credits
11891

Show all posts

 Author| abababa Posted at 2015-9-9 23:10:52
回复 5# kuing

是要保留一位小数吗?我看网上介绍的可以先乘10再除以10,这样都是0.5
N[Round[{0.49, 0.5, 0.51}*10]/10]

手机版Mobile version|Leisure Math Forum

2025-4-20 22:07 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list