File size: 1,236 Bytes
76cb30c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | from numpy import array
def legendre_interval(count):
from math import sqrt
if count <= 1:
p = array([0.0])
w = array([2.0])
return p, w
elif count == 2:
p = array([-1.0 / sqrt(3.0),1.0 / sqrt(3.0)])
w = array([1.0,1.0])
return p, w
elif count == 3:
p = array([-sqrt(3.0 / 5.0),0.0,sqrt(3.0 / 5.0)])
w = array([5.0 / 9.0,8.0 / 9.0,5.0 / 9.0])
return p, w
elif count == 4:
p = array([-sqrt((3.0 + 2.0 * sqrt(6.0 / 5.0)) / 7.0),-sqrt((3.0 - 2.0 * sqrt(6.0 / 5.0)) / 7.0),sqrt((3.0 - 2.0 * sqrt(6.0 / 5.0)) / 7.0), sqrt((3.0 + 2.0 * sqrt(6.0 / 5.0)) / 7.0)])
w = array([(18.0 - sqrt(30.0)) / 36.0,(18.0 + sqrt(30.0)) / 36.0,(18.0 + sqrt(30.0)) / 36.0,(18.0 - sqrt(30.0)) / 36.0])
return p, w
else:
p = array([-(1.0 / 3.0) * sqrt(5.0 + 2.0 * sqrt(10.0 / 7.0)),-(1.0 / 3.0) * sqrt(5.0 - 2.0 * sqrt(10.0 / 7.0)),0.0,(1.0 / 3.0) * sqrt(5.0 - 2.0 * sqrt(10.0 / 7.0)),(1.0 / 3.0) * sqrt(5.0 + 2.0 * sqrt(10.0 / 7.0))])
w = array([(322.0 - 13.0 * sqrt(70.0)) / 900.0,(322.0 + 13.0 * sqrt(70.0)) / 900.0,128.0 / 225.0,(322.0 + 13.0 * sqrt(70.0)) / 900.0,(322.0 - 13.0 * sqrt(70.0)) / 900.0])
return p, w |