-
Notifications
You must be signed in to change notification settings - Fork 0
/
shape_gen.py
75 lines (60 loc) · 1.5 KB
/
shape_gen.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import numpy as np
from sympy import *
# ord_ = number of variables needed for each finite element
def shape_gen(ord_):
# Constructing symbols for polynomial
if ord_ / 2 - ord_ // 2 == 0:
pass
else:
raise Exception("ord_ must be an non-negative even number")
coeff = []
L = symbols('L')
for i in range(ord_):
coeff.append('c' + f'{i}')
x = symbols('x')
coeffexpr = []
for s in coeff:
globals()[s] = symbols(s)
coeffexpr.append(symbols(s))
#print(coeff)
#print(coeffexpr)
# Construction for terms in y
term = []
e = 0
while e < len(coeffexpr):
term.append(coeffexpr[e] * x**e)
e += 1
#print(term)
# Constructing y
y = 0
for t in term:
y += t
# print(y)
n = ord_ // 2
Q = []
for i in range(n):
k = diff(y, x, i)
globals()['q'+f'{i}'] = k.subs(x, 0)
Q.append(k.subs(x,0))
for i in range(n, ord_):
k = diff(y, x, i - n)
globals()['q'+f'{i}'] = k.subs(x, L)
Q.append(k.subs(x, L))
# print(Q)
# print(coeffexpr)
A, b = linear_eq_to_matrix(Q, coeffexpr)
# print(A)
# print(b)
shape_func = []
A_ = A**-1
# print(A_)
for j in range(ord_):
expr = 0
for i in range(ord_):
expr += A_[i, j] * x ** i
shape_func.append(expr)
# print(shape_func)
return shape_func
if __name__ == '__main__':
shape_func = shape_gen(4)
print(shape_func)