wayne 发表于 2011-1-12 20:32:51

开心一刻,考考你的计算能力

用你现在能用到的工具,算一下下面的式子的结果,
173746a + 94228b − 78487c
其中,a=sin(10^22), b=ln(17.1) , c=e^0.42
误差可不能太离谱哦!怎么滴也得给出三位有效的数字吧,嘿嘿

G-Spider 发表于 2011-1-12 21:26:13

那我开个头吧,win7自带计算器,科学计算模式:

得到结果:-1.0512863441079781032519972450172 e-12

mathe 发表于 2011-1-12 21:54:56

我用windows计算器,分步计算得到3.6e-6,不过毫无意义,因为根据第一项,精度只能到小数点后第四位。
所以这个需要用到超高精度的计算器,如gp等

northwolves 发表于 2011-1-12 22:45:18

-1.3418189578257976814 E-12

wayne 发表于 2011-1-13 12:32:25

4# northwolves
没想到在Gp里面,小数是以高精度的形式参与运算的。 而在Mathematica里面,则是理解成浮点数的。

sheng_jianguo 发表于 2011-1-13 12:47:14

我用windows科学型计算器,计算得到结果是-1.3418189578296195344869801634132e-12
不知这结果有几位有效数字是正确的?

mathe 发表于 2011-1-13 13:58:42

17位,你的windows计算器咋用的,怎么能够这么遒劲呢?

(13:57) gp > \p 1000
   realprecision = 1001 significant digits (1000 digits displayed)
(13:57) gp > 173746*sin(10^22)+94228*log(17.1)-78487*exp(0.42)
%1 = -1.341818957829619549704278684230958880945236623213976217962434436981089938
71312279204236206544026964118180103145787836199219907607751657432226579378133699
42673138948388704080333699130503634302598623021595844884842815186404964488993019
81368777421653289256176763481354563333978318148139513994817515990886147832886138
14009423625491108437542359945241230976686942298144397164838498907707200309053752
87484729429048218752026534587119639341698805631562056285102330233835905030673543
49517538850611048635618680726489169596715277974511412206702530051759493718502786
30652560015681918489816514452052905741539411382258843555920582595351033763538911
13849240166815332627634439188132230975810433409456274722029885800575384492578969
10811216452592543609582645706777327217900400968809363540246045287204534999389863
25195843128724973711501878053158765951349217286822596839169388219708019597980118
40868540358639304917740664850541886244699577805182425924015531286376334270197419
3799248216530963946104908731687689207806 E-12

G-Spider 发表于 2011-1-13 14:57:05

6# sheng_jianguo
看来,人工转成角度误差大一些,直接选弧度计算,就是你这个结果:
-1.3418189578296195344869801634132e-12

----------------------------------------------------
Help 说明:在科学型模式下,计算器会精确到 32 位数。

wayne 发表于 2011-1-13 16:26:33

7# mathe
这个题其实是我学习mpfr 拿来练手的:#include <stdio.h>
#include <stdlib.h>
#include "mpfr.h"
int main (int argc, char *argv[])
{char* s;
sprintf(s,"d=%%1.%dRe\n",atoi(argv)-1);
mp_prec_t p = 5*atoi (argv)+100;
mpfr_t a, b, c, d;
mpfr_inits2 (p, a, b, c, d, (mpfr_ptr) 0);
mpfr_set_str (a, "1e22", 10, GMP_RNDN);
mpfr_sin (a, a, GMP_RNDN);
mpfr_mul_ui (a, a, 173746, GMP_RNDN);
mpfr_set_str (b, "17.1", 10, GMP_RNDN);
mpfr_log (b, b, GMP_RNDN);
mpfr_mul_ui (b, b, 94228, GMP_RNDN);
mpfr_set_str (c, "0.42", 10, GMP_RNDN);
mpfr_exp (c, c, GMP_RNDN);
mpfr_mul_si (c, c, -78487, GMP_RNDN);
mpfr_add (d, a, b, GMP_RNDN);
mpfr_add (d, d, c, GMP_RNDN);
mpfr_printf (s, d);
mpfr_clears (a, b, c, d, NULL);
return 0;
}

wayne 发表于 2011-1-13 16:27:53

本帖最后由 wayne 于 2011-1-13 16:29 编辑

9# wayne
C:\msys\mpfr300>gcc abc.c -Iinclude -Llib -lmpfr

C:\msys\mpfr300>a 1000
d=-1.341818957829619549704278684230958880945236623213976217962434436981089938713122792042362065440269641181801031457878361992199076077516574322265793781336994267313894838870408033369913050363430259862302159584488484281518640496448899301981368777421653289256176763481354563333978318148139513994817515990886147832886138140094236254911084375423599452412309766869422981443971648384989077072003090537528748472942904821875202653458711963934169880563156205628510233023383590503067354349517538850611048635618680726489169596715277974511412206702530051759493718502786306525600156819184898165144520529057415394113822588435559205825953510337635389111384924016681533262763443918813223097581043340945627472202988580057538449257896910811216452592543609582645706777327217900400968809363540246045287204534999389863251958431287249737115018780531587659513492172868225968391693882197080195979801184086854035863930491774066485054188624469957780518242592401553128637633427019741937992482165309639461049087316877189508895085434e-12
页: [1] 2
查看完整版本: 开心一刻,考考你的计算能力