-
Notifications
You must be signed in to change notification settings - Fork 0
/
lagrange1st.py
39 lines (30 loc) · 1.04 KB
/
lagrange1st.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from GetGLL import GetGLL
from lagrange import lagrange
from legendre import legendre
def lagrange1st(N):
out = np.zeros([N+1, N+1])
[xi, w] = GetGLL(N)
# initialize dij matrix (see Funaro 1993)
d = np.zeros([N + 1, N + 1])
for i in range(-1, N):
for j in range(-1, N):
if i != j:
d[i + 1, j + 1] = legendre(N, xi[i + 1]) / \
legendre(N, xi[j + 1]) * 1.0 / (xi[i + 1] - xi[j + 1])
if i == -1:
if j == -1:
d[i + 1, j + 1] = -1.0 / 4.0 * N * (N + 1)
if i == N-1:
if j == N-1:
d[i + 1, j + 1] = 1.0 / 4.0 * N * (N + 1)
# Calculate matrix with 1st derivatives of Lagrange polynomials
for n in range(-1, N):
for i in range(-1, N):
sum = 0
for j in range(-1, N):
sum = sum + d[i + 1, j + 1] * lagrange(N, n, xi[j + 1])
out[n + 1, i + 1] = sum
return(out)