pi

Python numpy unwrap function

别说谁变了你拦得住时间么 提交于 2019-12-04 09:08:47
I am hoping to convert a array of radians into range [0, 2*pi) and numpy unwrap function is exactly what I need However, when I run the following code to input a = [pi, 2*pi, 3*pi] : import numpy as np a = np.array([np.pi, 2*np.pi, 3*np.pi]) np.unwrap(a) I expect the results to be close to [pi, 0, pi] . However, the output is still: array([ 3.14159265, 6.28318531, 9.42477796]) It is not unwrapped. However, if I instead run the following without using the numpy.pi a = np.array([3.14159265, 6.28318531, 9.42477796]) np.unwrap(a) The output is correct: array([ 3.14159265e+00, 2.82041412e-09, 3

Computing π to “infinite” binary precision in C#

北城以北 提交于 2019-12-04 06:23:24
So far it looks like Fabrice Bellard's base 2 equation is the way to go Ironically this will require a BigReal type; do we have this for .Net? .Net 4.0 has BigInteger. Anyone have a Haskell version? sth Since you're asking for a Haskell version, here is a paper by Jerzy Karczmarczuk, called "The Most Unreliable Technique in the World to compute π": This paper is an atypical exercice in lazy functional coding, written for fun and instruction. It can be read and understood by anybody who understands the programming language Haskell. We show how to implement the Bailey-Borwein-Ploue formula for π

Approximation to constant “pi” does not get any better after 50 iterations

非 Y 不嫁゛ 提交于 2019-12-04 06:22:46
问题 In R I have written this function ifun <- function(m) { o = c() for (k in 1:m) { o[k] = prod(1:k) / prod(2 * (1:k) + 1) } o_sum = 2 * (1 + sum(o)) # Final result print(o_sum) } This function approximates constant pi , however, after m > 50 the approximation gets stuck, i.e. the approximation is the same value and don't get better. How can I fix this? Thanks. 回答1: Let's go inside: o <- numeric(100) for (k in 1:length(o)) { o[k] = prod(1:k) / prod(2 * (1:k) + 1) } o # [1] 3.333333e-01 1.333333e

Bailey–Borwein–Plouffe formula implementation in C++?

一世执手 提交于 2019-12-04 05:14:23
EDIT : The requirement was vague and instead of calculating the n-th digit of pi they just wanted pi to the n-th digit not going beyond floats limitation so the brute force way worked for the requirements. I need to calculate PI the the n-th digit and I wanted to try using the BBP formula but am having difficulties. The equation I typed up doesn't seem to be giving me PI correctly. (1 / pow(16,n))((4 / (8 * n + 1)) - (2 / (8 * n + 4)) - (1 / (8 * n + 5)) - (1 / (8 * n + 6))) I was successful with the brute force way of finding PI but that is only so accurate and finding the nth number is

Cython's calculations are incorrect

↘锁芯ラ 提交于 2019-12-04 04:52:22
I implemented the Madhava–Leibniz series to calculate pi in Python, and then in Cython to improve the speed. The Python version: from __future__ import division pi = 0 l = 1 x = True while True: if x: pi += 4/l else: pi -= 4/l x = not x l += 2 print str(pi) The Cython version: cdef float pi = 0.0 cdef float l = 1.0 cdef unsigned short x = True while True: if x: pi += 4.0/l else: pi -= 4.0/l x = not x l += 2 print str(pi) When I stopped the Python version it had correctly calculated pi to 3.141592. The Cython version eventually ended up at 3.141597 with some more digits that I don't remember

Why is there no definition of the constant pi in the C++11 standard? [closed]

徘徊边缘 提交于 2019-12-04 02:47:18
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 6 years ago . I find it quiet annoying that I have to use the macro _USE_MATH_DEFINES in order to get the value of pi into my program. Or I need to define it myself in one of my own headers. Or I have to use boost and all that. It just annoys me, that there isn't a standard c++ header

让Mono 4在Raspberry Pi上飞

限于喜欢 提交于 2019-12-03 19:17:02
最近公司有项目想要在树莓派上做,代替原来的工控机(我们是把工控主机当作小的主机用,一台小的工控主机最少也要600左右,而树莓派只要200多)。于是,公司买了一个Raspberry Pi B+和一个Raspberry Pi 2 B,并要求能在B+上做就尽量用B+,原因很简单,B+比Raspberry Pi 2要便宜70左右。拿到闻名已久的树莓派之后很是兴奋,试着从官网下载了官方推荐的镜像raspbian,用Win32DiskImager烧录到SD卡上,然后上电,起初屏幕上什么都没显示,不管重新烧写了多少次SD卡,屏幕都是黑的,后来发现原来屏幕是否显示,是需要配置一下config.txt文件里面的一些参数屏幕才会显示,我用的是HDMI接显示器,所以只要把config.txt里面跟HDMI有关的选项前面的#去掉就可以了。剩下的就比较简单了,配置一下就可以用了,初始登录用户是pi。 本人用的比较熟的语言是C#,树莓派上能用吗?答案是肯定的,Mono 4是支持ARM设备的,这就意味着树莓派可以用C#写程序,但问题来了,怎么安装Mono 4呢?如果你用官方的镜像raspbian-wheezy,你会发现,通过apt-get怎么都装不上Mono 4,显示缺少依赖项。于是,我想到有没有其他可以用的镜像,是不是镜像的问题,wheezy是debian的上一个版本,debian当前的版本是jessie

Finding PI digits using Monte Carlo

我怕爱的太早我们不能终老 提交于 2019-12-03 17:21:47
I have tried many algorithms for finding π using Monte Carlo. One of the solutions (in Python) is this: def calc_PI(): n_points = 1000000 hits = 0 for i in range(1, n_points): x, y = uniform(0.0, 1.0), uniform(0.0, 1.0) if (x**2 + y**2) <= 1.0: hits += 1 print "Calc2: PI result", 4.0 * float(hits) / n_points The sad part is that even with 1000000000 the precision is VERY bad ( 3.141... ). Is this the maximum precision this method can offer? The reason I choose Monte Carlo was that it's very easy to break it in parallel parts. Is there another algorithm for π that is easy to break into pieces

Plot the sine and cosine functions

我的梦境 提交于 2019-12-03 15:06:50
I'm currently having some problems regarding my homework. Here's the Exercise: (Plot the sine and cosine functions) Write a program that plots the sine function in red and the cosine function in blue. hint: The Unicode for Pi is \u03c0 . To display -2Pi, use g.drawString("-2\u03c0", x, y). For a trigonometric function like sin(x), x is in radians. Use the following loop to add the points to a polygon p for (int x = -170; x <= 170; x++) { p.addPoint(x + 200, 100 - (int)(50 * Math.sin((x / 100.0) * 2 * Math.PI))); -2Pi is at ( 100, 100 ), the center of the axis is at ( 200, 100 ), and 2Pi is at

creating math constants of variable precision using Boost mpfr_float, such as pi or e

♀尐吖头ヾ 提交于 2019-12-02 15:53:56
问题 I am using Boost.Multiprecision for wrappers around the mpfr backend, and I am having some trouble creating pi (and e or any other math constant) to my desired precision. I feel like what I want to do should be possible, because of the use of Boost.Math for constants on a tutorial page for Boost.Multiprecision. In the tutorial, they use fixed-precision numbers of types such as cpp_dec_float_50 -- I want to do it with variable_precision mpfr_float . Check out the following code: #include