Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Math 使用babel生成Emacs组织模式文件中的简单数学结果_Math_Emacs_Org Mode_Org Babel - Fatal编程技术网

Math 使用babel生成Emacs组织模式文件中的简单数学结果

Math 使用babel生成Emacs组织模式文件中的简单数学结果,math,emacs,org-mode,org-babel,Math,Emacs,Org Mode,Org Babel,我希望在组织模式文件中嵌入简单的数学表达式,例如: sqrt(p*(1-p)*N) 其中p=0.8,N=10000,根据一个简单的桌面计算器,答案是40。我运气不好,巴贝尔给我这个答案。。。这是一个组织文件: Some weird rounding errors with Python: #+begin_src python :var N=100000 :var p=0.8 from math import sqrt return sqrt(p * (1 - p) * N) #+end_sr

我希望在组织模式文件中嵌入简单的数学表达式,例如:

sqrt(p*(1-p)*N)
其中p=0.8,N=10000,根据一个简单的桌面计算器,答案是40。我运气不好,巴贝尔给我这个答案。。。这是一个组织文件:

Some weird rounding errors with Python:

#+begin_src python :var N=100000 :var p=0.8
from math import sqrt
return sqrt(p * (1 - p) * N)
#+end_src

#+results:
: 126.491106407


Some other weird rounding errors, this time with Emacs lisp:

#+begin_src elisp :var N=100000 :var p=0.8
(sqrt (* p (- 1 p) N))
#+end_src

#+results:
: 126.49110640673517


Note sure which number calc is unhappy with:

#+begin_src calc :var N=100000 :var p=0.8
sqrt(p * (1 - p) * N)
#+end_src

#+results:
| 5 | Expected a number |


Yet more weird rounding errors, using bc in the shell:

#+begin_src sh :var N=100000 :var p=0.8
echo "sqrt($p * (1 - $p) * $N)" | bc
#+end_src

#+results:
: 100.0


A different set of rounding errors with bc without using variables:

#+begin_src sh
echo "sqrt(0.8 * (1 - 0.8) * 10000)" | bc
#+end_src

#+results:
: 31.6


Looks like the variables are being substituted OK:

#+begin_src sh :var N=100000 :var p=0.8
echo "sqrt($p * (1 - $p) * $N)"
#+end_src

#+results:
: sqrt(0.8 * (1 - 0.8) * 100000)


Using extra precision directly gives the correct result:

#+begin_src sh
echo "sqrt(0.80 * (1 - 0.80) * 10000)" | bc
#+end_src

#+results:
: 40.0


So, just use extra precision in the p variable, eh:

#+begin_src sh :var N=100000 :var p=0.80
echo "sqrt($p * (1 - $p) * $N)" | bc
#+end_src

#+results:
: 100.0


No! Because it get stripped out:

#+begin_src sh :var N=100000 :var p=0.80
echo "sqrt($p * (1 - $p) * $N)"
#+end_src

#+results:
: sqrt(0.8 * (1 - 0.8) * 100000)


Please God, kill me now...
我只是在寻找一种方便的方法,在一个组织文件中嵌入一些数学知识


(组织模式7.8.03来自最近的git签出,emacs 24.0.93.1来自最近的git chekout)

不要因为打字错误而自杀:)

(sqrt(*p(-1 p)))
0.39999999999999997
添加缺少的N

(let((p0.8)(N 10000))
(sqrt(*p(-1 p)N)))
40
对于bc,请尝试使用

scale=10

不要因为打字错误而自杀:)

(sqrt(*p(-1 p)))
0.39999999999999997
添加缺少的N

(let((p0.8)(N 10000))
(sqrt(*p(-1 p)N)))
40
对于bc,请尝试使用

scale=10
你说:

sqrt(p * (1-p) * N)

where p=0.8, N=10,000 and the answer according to a simple desk calculator is 40. 
这是正确的,但在您使用的许多代码中

:var N=100000
相反,也就是说,以10的系数进行关断

>>> from math import sqrt 
>>> p = 0.8
>>> sqrt(p*(1-p)*10000)
40.0
>>> sqrt(p*(1-p)*100000)
126.49110640673517
你说:

sqrt(p * (1-p) * N)

where p=0.8, N=10,000 and the answer according to a simple desk calculator is 40. 
这是正确的,但在您使用的许多代码中

:var N=100000
相反,也就是说,以10的系数进行关断

>>> from math import sqrt 
>>> p = 0.8
>>> sqrt(p*(1-p)*10000)
40.0
>>> sqrt(p*(1-p)*100000)
126.49110640673517

@吉米:那么你最好回来,当你得到代表时再投票。开玩笑:)@吉米:那么你最好回来,当你得到代表时再投票。开玩笑:)