Forgot password
 Register account
View 2173|Reply 5

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

[Copy link]

414

Threads

1641

Posts

15

Reputation

Show all posts

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

414

Threads

1641

Posts

15

Reputation

Show all posts

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

764

Threads

4672

Posts

27

Reputation

Show all posts

isee posted 2015-9-6 14:30
回复 2# abababa


    这个要求好奇怪的。。。

673

Threads

110K

Posts

218

Reputation

Show all posts

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

673

Threads

110K

Posts

218

Reputation

Show all posts

kuing posted 2015-9-6 14:38
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 出现时,总往偶数靠。

414

Threads

1641

Posts

15

Reputation

Show all posts

original poster abababa posted 2015-9-9 23:10
回复 5# kuing

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

Quick Reply

Advanced Mode
B Color Image Link Quote Code Smilies
You have to log in before you can reply Login | Register account

$\LaTeX$ formula tutorial

Mobile version

2025-7-20 05:45 GMT+8

Powered by Discuz!

Processed in 0.014487 seconds, 22 queries