CoCalc Public FilesPM_2_5 / wave_equation / worksheets / dLp_xi.sagewsOpen in with one click!
Authors: Balavarun P, Aman Abhishek Tiwari
import numpy as np
var('x, xi') x_nodes = [-1, 1] xi_LGL = [-1.0, \ -0.87174014851, \ -0.591700181433,\ -0.209299217902,\ 0.209299217902, \ 0.591700181433, \ 0.87174014851, \ 1.0]
(x, xi)
#Assigning L_0 and L_1 as the lagrange basis polynomials. L_0 = ((xi - (xi_LGL[1])) / (xi_LGL[0] - xi_LGL[1]))\ * ((xi - (xi_LGL[2])) / (xi_LGL[0] - xi_LGL[2]))\ * ((xi - (xi_LGL[3])) / (xi_LGL[0] - xi_LGL[3]))\ * ((xi - (xi_LGL[4])) / (xi_LGL[0] - xi_LGL[4]))\ * ((xi - (xi_LGL[5])) / (xi_LGL[0] - xi_LGL[5]))\ * ((xi - (xi_LGL[6])) / (xi_LGL[0] - xi_LGL[6]))\ * ((xi - (xi_LGL[7])) / (xi_LGL[0] - xi_LGL[7])) L_1 = ((xi - (xi_LGL[0])) / (xi_LGL[1] - xi_LGL[0]))\ * ((xi - (xi_LGL[2])) / (xi_LGL[1] - xi_LGL[2]))\ * ((xi - (xi_LGL[3])) / (xi_LGL[1] - xi_LGL[3]))\ * ((xi - (xi_LGL[4])) / (xi_LGL[1] - xi_LGL[4]))\ * ((xi - (xi_LGL[5])) / (xi_LGL[1] - xi_LGL[5]))\ * ((xi - (xi_LGL[6])) / (xi_LGL[1] - xi_LGL[6]))\ * ((xi - (xi_LGL[7])) / (xi_LGL[1] - xi_LGL[7])) L_2 = ((xi - (xi_LGL[0])) / (xi_LGL[2] - xi_LGL[0])) \ * ((xi - (xi_LGL[1])) / (xi_LGL[2] - xi_LGL[1])) \ * ((xi - (xi_LGL[3])) / (xi_LGL[2] - xi_LGL[3])) \ * ((xi - (xi_LGL[4])) / (xi_LGL[2] - xi_LGL[4])) \ * ((xi - (xi_LGL[5])) / (xi_LGL[2] - xi_LGL[5])) \ * ((xi - (xi_LGL[6])) / (xi_LGL[2] - xi_LGL[6])) \ * ((xi - (xi_LGL[7])) / (xi_LGL[2] - xi_LGL[7])) L_3 = ((xi - (xi_LGL[0])) / (xi_LGL[3] - xi_LGL[0])) \ * ((xi - (xi_LGL[1])) / (xi_LGL[3] - xi_LGL[1])) \ * ((xi - (xi_LGL[2])) / (xi_LGL[3] - xi_LGL[2])) \ * ((xi - (xi_LGL[4])) / (xi_LGL[3] - xi_LGL[4])) \ * ((xi - (xi_LGL[5])) / (xi_LGL[3] - xi_LGL[5])) \ * ((xi - (xi_LGL[6])) / (xi_LGL[3] - xi_LGL[6])) \ * ((xi - (xi_LGL[7])) / (xi_LGL[3] - xi_LGL[7])) L_4 = ((xi - (xi_LGL[0])) / (xi_LGL[4] - xi_LGL[0])) \ * ((xi - (xi_LGL[1])) / (xi_LGL[4] - xi_LGL[1])) \ * ((xi - (xi_LGL[2])) / (xi_LGL[4] - xi_LGL[2])) \ * ((xi - (xi_LGL[3])) / (xi_LGL[4] - xi_LGL[3])) \ * ((xi - (xi_LGL[5])) / (xi_LGL[4] - xi_LGL[5])) \ * ((xi - (xi_LGL[6])) / (xi_LGL[4] - xi_LGL[6])) \ * ((xi - (xi_LGL[7])) / (xi_LGL[4] - xi_LGL[7])) L_5 = ((xi - (xi_LGL[0])) / (xi_LGL[5] - xi_LGL[0])) \ * ((xi - (xi_LGL[1])) / (xi_LGL[5] - xi_LGL[1])) \ * ((xi - (xi_LGL[2])) / (xi_LGL[5] - xi_LGL[2])) \ * ((xi - (xi_LGL[3])) / (xi_LGL[5] - xi_LGL[3])) \ * ((xi - (xi_LGL[4])) / (xi_LGL[5] - xi_LGL[4])) \ * ((xi - (xi_LGL[6])) / (xi_LGL[5] - xi_LGL[6])) \ * ((xi - (xi_LGL[7])) / (xi_LGL[5] - xi_LGL[7])) L_6 = ((xi - (xi_LGL[0])) / (xi_LGL[6] - xi_LGL[0])) \ * ((xi - (xi_LGL[1])) / (xi_LGL[6] - xi_LGL[1])) \ * ((xi - (xi_LGL[2])) / (xi_LGL[6] - xi_LGL[2])) \ * ((xi - (xi_LGL[3])) / (xi_LGL[6] - xi_LGL[3])) \ * ((xi - (xi_LGL[4])) / (xi_LGL[6] - xi_LGL[4])) \ * ((xi - (xi_LGL[5])) / (xi_LGL[6] - xi_LGL[5])) \ * ((xi - (xi_LGL[7])) / (xi_LGL[6] - xi_LGL[7])) L_7 = ((xi - (xi_LGL[0])) / (xi_LGL[7] - xi_LGL[0])) \ * ((xi - (xi_LGL[1])) / (xi_LGL[7] - xi_LGL[1])) \ * ((xi - (xi_LGL[2])) / (xi_LGL[7] - xi_LGL[2])) \ * ((xi - (xi_LGL[3])) / (xi_LGL[7] - xi_LGL[3])) \ * ((xi - (xi_LGL[4])) / (xi_LGL[7] - xi_LGL[4])) \ * ((xi - (xi_LGL[5])) / (xi_LGL[7] - xi_LGL[5])) \ * ((xi - (xi_LGL[6])) / (xi_LGL[7] - xi_LGL[6])) \
numerical_integral(L_0, -1, 1)
Error in lines 1-1 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 996, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> NameError: name 'L_0' is not defined
diff(L_0)(xi_LGL[0]), diff(L_0)(xi_LGL[1]), diff(L_0)(xi_LGL[2]), diff(L_0)(xi_LGL[3]), diff(L_0)(xi_LGL[4]), diff(L_0)(xi_LGL[5]), diff(L_0)(xi_LGL[6]), diff(L_0)(xi_LGL[7]) diff(L_1)(xi_LGL[0]), diff(L_1)(xi_LGL[1]), diff(L_1)(xi_LGL[2]), diff(L_1)(xi_LGL[3]), diff(L_1)(xi_LGL[4]), diff(L_1)(xi_LGL[5]), diff(L_1)(xi_LGL[6]), diff(L_1)(xi_LGL[7]) diff(L_2)(xi_LGL[0]), diff(L_2)(xi_LGL[1]), diff(L_2)(xi_LGL[2]), diff(L_2)(xi_LGL[3]), diff(L_2)(xi_LGL[4]), diff(L_2)(xi_LGL[5]), diff(L_2)(xi_LGL[6]), diff(L_2)(xi_LGL[7]) diff(L_3)(xi_LGL[0]), diff(L_3)(xi_LGL[1]), diff(L_3)(xi_LGL[2]), diff(L_3)(xi_LGL[3]), diff(L_3)(xi_LGL[4]), diff(L_3)(xi_LGL[5]), diff(L_3)(xi_LGL[6]), diff(L_3)(xi_LGL[7]) diff(L_4)(xi_LGL[0]), diff(L_4)(xi_LGL[1]), diff(L_4)(xi_LGL[2]), diff(L_4)(xi_LGL[3]), diff(L_4)(xi_LGL[4]), diff(L_4)(xi_LGL[5]), diff(L_4)(xi_LGL[6]), diff(L_4)(xi_LGL[7]) diff(L_5)(xi_LGL[0]), diff(L_5)(xi_LGL[1]), diff(L_5)(xi_LGL[2]), diff(L_5)(xi_LGL[3]), diff(L_5)(xi_LGL[4]), diff(L_5)(xi_LGL[5]), diff(L_5)(xi_LGL[6]), diff(L_5)(xi_LGL[7]) diff(L_6)(xi_LGL[0]), diff(L_6)(xi_LGL[1]), diff(L_6)(xi_LGL[2]), diff(L_6)(xi_LGL[3]), diff(L_6)(xi_LGL[4]), diff(L_6)(xi_LGL[5]), diff(L_6)(xi_LGL[6]), diff(L_6)(xi_LGL[7]) diff(L_7)(xi_LGL[0]), diff(L_7)(xi_LGL[1]), diff(L_7)(xi_LGL[2]), diff(L_7)(xi_LGL[3]), diff(L_7)(xi_LGL[4]), diff(L_7)(xi_LGL[5]), diff(L_7)(xi_LGL[6]), diff(L_7)(xi_LGL[7])
(-14.0000000000226, -3.20991570302344, 0.792476681323880, -0.372150435728984, 0.243330712724289, -0.203284568901545, 0.219957514771985, -0.500000000000000) (18.9375986071129, 3.31501492922825e-11, -2.80647579473469, 1.07894468878725, -0.661157350899271, 0.537039586158262, -0.573565414940005, 1.29768738831567) (-7.56928981931106, 4.54358506455201, -6.49491571635963e-12, -2.37818723350641, 1.13535801687865, -0.845022556506714, 0.869448098330221, -1.94165942553537) (4.29790816425547, -2.11206121431525, 2.87551740597844, -1.18891563261059e-11, -2.38892435916370, 1.37278583181113, -1.29423205091574, 2.81018898925442) (-2.81018898925442, 1.29423205091574, -1.37278583181113, 2.38892435916370, 1.18891563261059e-11, -2.87551740597844, 2.11206121431525, -4.29790816425547) (1.94165942553537, -0.869448098330221, 0.845022556506714, -1.13535801687865, 2.37818723350641, 6.49480469405717e-12, -4.54358506455201, 7.56928981931106) (-1.29768738831567, 0.573565414940005, -0.537039586158262, 0.661157350899271, -1.07894468878725, 2.80647579473469, -3.31504823591899e-11, -18.9375986071129) (0.500000000000000, -0.219957514771985, 0.203284568901545, -0.243330712724289, 0.372150435728984, -0.792476681323880, 3.20991570302344, 14.0000000000226)
lobatto_weights = [0.03571428571429,\ 0.21070422714351,\ 0.34112269248350,\ 0.41245879465870,\ 0.41245879465870,\ 0.34112269248350,\ 0.21070422714351,\ 0.03571428571429]
diff(L_0)(xi_LGL[0]) * lobatto_weights[0]
-0.500000000000866
L_0.simplify_full()
-3.351562500008004*xi^7 + 3.351562500008006*xi^6 + 3.867187500010295*xi^5 - 3.867187500010297*xi^4 - 1.054687500002225*xi^3 + 1.054687500002225*xi^2 + 0.03906249999993106*xi - 0.03906249999993102
(14 - 7 **0.5)/30
0.378474956297847