基于等效积分形式的近似方法——加权余量法(配点法,伽辽金法)求解微分方程近似解
1.配點法:
配點法取δ函數為權函數是利用δ函數的性質,從而簡化計算。
下面是用python實現的代碼:(只取前六項)
import sympyx = sympy.Symbol('x') # a = sympy.symbols('a1:7') a1, a2, a3, a4, a5, a6 = sympy.symbols('a1 a2 a3 a4 a5 a6') a = [a1, a2, a3, a4, a5, a6] b1, b2, b3, b4, b5, b6 = sympy.symbols('b1 b2 b3 b4 b5 b6') b = [b1, b2, b3, b4, b5, b6] f1 = x*(1-x) for i in range(1, 7):f2 = 0for j in range(0, i):f2 = f2 + a[j] * x ** jf = f1 * f2f3 = sympy.diff(f, x, 2) + f + xfor k in range(1, i+1):b[k-1] = f3.subs(x, k/(i+1))c = sympy.solve(b, a)print('配點法', i, '項近似解如下:')print(c)res = []for k, j in c.items():res.append(j)if i == 1 :d = f.subs([(x, 0.25), (a1, res[0])])d1 = ((d - 0.04401) / 0.04401) * 100print('x = 0.25時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')d = f.subs([(x, 0.5), (a1, res[0])])d1 = ((d - 0.06975) / 0.06975) * 100print('x = 0.5時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')d = f.subs([(x, 0.75), (a1, res[0])])d1 = ((d - 0.06006) / 0.06006) * 100print('x = 0.75時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')elif i == 2 :d = f.subs([(x, 0.25), (a1, res[0]), (a2, res[1])])d1 = ((d - 0.04401) / 0.04401) * 100print('x = 0.25時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')d = f.subs([(x, 0.5), (a1, res[0]), (a2, res[1])])d1 = ((d - 0.06975) / 0.06975) * 100print('x = 0.5時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')d = f.subs([(x, 0.75), (a1, res[0]), (a2, res[1])])d1 = ((d - 0.06006) / 0.06006) * 100print('x = 0.75時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')elif i == 3:d = f.subs([(x, 0.25), (a1, res[0]), (a2, res[1]), (a3, res[2])])d1 = ((d - 0.04401) / 0.04401) * 100print('x = 0.25時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')d = f.subs([(x, 0.5), (a1, res[0]), (a2, res[1]), (a3, res[2])])d1 = ((d - 0.06975) / 0.06975) * 100print('x = 0.5時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')d = f.subs([(x, 0.75), (a1, res[0]), (a2, res[1]), (a3, res[2])])d1 = ((d - 0.06006) / 0.06006) * 100print('x = 0.75時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')elif i == 4:d = f.subs([(x, 0.25), (a1, res[0]), (a2, res[1]), (a3, res[2]), (a4, res[3])])d1 = ((d - 0.04401) / 0.04401) * 100print('x = 0.25時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')d = f.subs([(x, 0.5), (a1, res[0]), (a2, res[1]), (a3, res[2]), (a4, res[3])])d1 = ((d - 0.06975) / 0.06975) * 100print('x = 0.5時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')d = f.subs([(x, 0.75), (a1, res[0]), (a2, res[1]), (a3, res[2]), (a4, res[3])])d1 = ((d - 0.06006) / 0.06006) * 100print('x = 0.75時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')elif i == 5:d = f.subs([(x, 0.25), (a1, res[0]), (a2, res[1]), (a3, res[2]), (a4, res[3]), (a5, res[4])])d1 = ((d - 0.04401) / 0.04401) * 100print('x = 0.25時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')d = f.subs([(x, 0.5), (a1, res[0]), (a2, res[1]), (a3, res[2]), (a4, res[3]), (a5, res[4])])d1 = ((d - 0.06975) / 0.06975) * 100print('x = 0.5時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')d = f.subs([(x, 0.75), (a1, res[0]), (a2, res[1]), (a3, res[2]), (a4, res[3]), (a5, res[4])])d1 = ((d - 0.06006) / 0.06006) * 100print('x = 0.75時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')else :d = f.subs([(x, 0.25), (a1, res[0]), (a2, res[1]), (a3, res[2]), (a4, res[3]), (a5, res[4]), (a6, res[5])])d1 = ((d - 0.04401) / 0.04401) * 100print('x = 0.25時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')d = f.subs([(x, 0.5), (a1, res[0]), (a2, res[1]), (a3, res[2]), (a4, res[3]), (a5, res[4]), (a6, res[5])])d1 = ((d - 0.06975) / 0.06975) * 100print('x = 0.5時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')d = f.subs([(x, 0.75), (a1, res[0]), (a2, res[1]), (a3, res[2]), (a4, res[3]), (a5, res[4]), (a6, res[5])])d1 = ((d - 0.06006) / 0.06006) * 100print('x = 0.75時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')print('\n')下面是代碼的運行結果:
配點法 1 項近似解如下:
{a1: 0.285714285714286}
x = 0.25時,近似值為: 0.05357
誤差為: 21.72558 %
x = 0.5時,近似值為: 0.07143
誤差為: 2.40655 %
x = 0.75時,近似值為: 0.05357
誤差為: -10.80348 %
配點法 2 項近似解如下:
{a1: 0.194711538461538, a2: 0.173076923076923}
x = 0.25時,近似值為: 0.04462
誤差為: 1.38922 %
x = 0.5時,近似值為: 0.07031
誤差為: 0.80645 %
x = 0.75時,近似值為: 0.06085
誤差為: 1.31095 %
配點法 3 項近似解如下:
{a1: 0.187041225250962, a2: 0.195659246915050, a3: -0.0236162361623616}
x = 0.25時,近似值為: 0.04397
誤差為: -0.10224 %
x = 0.5時,近似值為: 0.06974
誤差為: -0.01190 %
x = 0.75時,近似值為: 0.06009
誤差為: 0.05667 %
配點法 4 項近似解如下:
{a1: 0.188343316345612, a2: 0.188712310390586, a3: -0.0105707933858539, a4: -0.00864764645654039}
x = 0.25時,近似值為: 0.04401
誤差為: 0.00239 %
x = 0.5時,近似值為: 0.06974
誤差為: -0.00867 %
x = 0.75時,近似值為: 0.06005
誤差為: -0.01147 %
配點法 5 項近似解如下:
{a1: 0.188401946697363, a2: 0.188332312246946, a3: -0.00941465566631577, a4: -0.0102061176364873, a5: 0.000787661908280895}
x = 0.25時,近似值為: 0.04401
誤差為: 0.00861 %
x = 0.5時,近似值為: 0.06975
誤差為: -0.00434 %
x = 0.75時,近似值為: 0.06006
誤差為: -0.00657 %
配點法 6 項近似解如下:
{a1: 0.188395294128659, a2: 0.188393202367646, a3: -0.00966093225403519, a4: -0.00969748676809025, a5: 0.000271493654245921, a6: 0.000206049827060208}
x = 0.25時,近似值為: 0.04401
誤差為: 0.00832 %
x = 0.5時,近似值為: 0.06975
誤差為: -0.00434 %
x = 0.75時,近似值為: 0.06006
誤差為: -0.00637 %
2.伽遼金法:
利用近似解的試探函數序列作為權函數。
下面是python實現的代碼:(只取前六項)
import sympyx = sympy.Symbol('x') a1, a2, a3, a4, a5, a6 = sympy.symbols('a1 a2 a3 a4 a5 a6') a = [a1, a2, a3, a4, a5, a6] b1, b2, b3, b4, b5, b6 = sympy.symbols('b1 b2 b3 b4 b5 b6') b = [b1, b2, b3, b4, b5, b6] f1, f2, f3, f4, f5, f6 = sympy.symbols('f1 f2 f3 f4 f5 f6') f = [f1, f2, f3, f4, f5, f6] u1 = x*(1-x) b[0] = x*(1-x) for i in range(1, 7):u2 = 0b[i-1] = b[0] * x ** (i-1)for j in range(0, i):u2 = u2 + a[j] * x ** ju = u1 * u2u3 = sympy.diff(u, x, 2) + u + xfor j in range(0, i):f[j] = b[j] * u3c = sympy.solve([sympy.integrate(f[0], (x, 0, 1)), sympy.integrate(f[1], (x, 0, 1)), sympy.integrate(f[2], (x, 0, 1)),sympy.integrate(f[3], (x, 0, 1)), sympy.integrate(f[4], (x, 0, 1)), sympy.integrate(f[5], (x, 0, 1))], a)print('伽遼金法', i, '項近似解如下:\n')print(c)res = []for k, j in c.items():res.append(j)if i == 1 :d = u.subs([(x, 0.25), (a1, res[0])])d1 = ((d - 0.04401) / 0.04401) * 100print('x = 0.25時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')d = u.subs([(x, 0.5), (a1, res[0])])d1 = ((d - 0.06975) / 0.06975) * 100print('x = 0.5時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')d = u.subs([(x, 0.75), (a1, res[0])])d1 = ((d - 0.06006) / 0.06006) * 100print('x = 0.75時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')elif i == 2 :d = u.subs([(x, 0.25), (a1, res[0]), (a2, res[1])])d1 = ((d - 0.04401) / 0.04401) * 100print('x = 0.25時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')d = u.subs([(x, 0.5), (a1, res[0]), (a2, res[1])])d1 = ((d - 0.06975) / 0.06975) * 100print('x = 0.5時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')d = u.subs([(x, 0.75), (a1, res[0]), (a2, res[1])])d1 = ((d - 0.06006) / 0.06006) * 100print('x = 0.75時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')elif i == 3:d = u.subs([(x, 0.25), (a1, res[0]), (a2, res[1]), (a3, res[2])])d1 = ((d - 0.04401) / 0.04401) * 100print('x = 0.25時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')d = u.subs([(x, 0.5), (a1, res[0]), (a2, res[1]), (a3, res[2])])d1 = ((d - 0.06975) / 0.06975) * 100print('x = 0.5時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')d = u.subs([(x, 0.75), (a1, res[0]), (a2, res[1]), (a3, res[2])])d1 = ((d - 0.06006) / 0.06006) * 100print('x = 0.75時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')elif i == 4:d = u.subs([(x, 0.25), (a1, res[0]), (a2, res[1]), (a3, res[2]), (a4, res[3])])d1 = ((d - 0.04401) / 0.04401) * 100print('x = 0.25時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')d = u.subs([(x, 0.5), (a1, res[0]), (a2, res[1]), (a3, res[2]), (a4, res[3])])d1 = ((d - 0.06975) / 0.06975) * 100print('x = 0.5時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')d = u.subs([(x, 0.75), (a1, res[0]), (a2, res[1]), (a3, res[2]), (a4, res[3])])d1 = ((d - 0.06006) / 0.06006) * 100print('x = 0.75時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')elif i == 5:d = u.subs([(x, 0.25), (a1, res[0]), (a2, res[1]), (a3, res[2]), (a4, res[3]), (a5, res[4])])d1 = ((d - 0.04401) / 0.04401) * 100print('x = 0.25時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')d = u.subs([(x, 0.5), (a1, res[0]), (a2, res[1]), (a3, res[2]), (a4, res[3]), (a5, res[4])])d1 = ((d - 0.06975) / 0.06975) * 100print('x = 0.5時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')d = u.subs([(x, 0.75), (a1, res[0]), (a2, res[1]), (a3, res[2]), (a4, res[3]), (a5, res[4])])d1 = ((d - 0.06006) / 0.06006) * 100print('x = 0.75時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')else :d = u.subs([(x, 0.25), (a1, res[0]), (a2, res[1]), (a3, res[2]), (a4, res[3]), (a5, res[4]), (a6, res[5])])d1 = ((d - 0.04401) / 0.04401) * 100print('x = 0.25時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')d = u.subs([(x, 0.5), (a1, res[0]), (a2, res[1]), (a3, res[2]), (a4, res[3]), (a5, res[4]), (a6, res[5])])d1 = ((d - 0.06975) / 0.06975) * 100print('x = 0.5時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')d = u.subs([(x, 0.75), (a1, res[0]), (a2, res[1]), (a3, res[2]), (a4, res[3]), (a5, res[4]), (a6, res[5])])d1 = ((d - 0.06006) / 0.06006) * 100print('x = 0.75時,近似值為:', d.round(5))print('誤差為:', d1.round(5), '%')print('\n')下面是運行結果:
伽遼金法 1 項近似解如下:
{a1: 5/18}
x = 0.25時,近似值為: 0.05208
誤差為: 18.34432 %
x = 0.5時,近似值為: 0.06944
誤差為: -0.43807 %
x = 0.75時,近似值為: 0.05208
誤差為: -13.28116 %
伽遼金法 2 項近似解如下:
{a1: 71/369, a2: 7/41}
x = 0.25時,近似值為: 0.04408
誤差為: 0.15970 %
x = 0.5時,近似值為: 0.06944
誤差為: -0.43807 %
x = 0.75時,近似值為: 0.06009
誤差為: 0.04393 %
伽遼金法 3 項近似解如下:
{a1: 13811/73554, a2: 2380/12259, a3: -7/299}
x = 0.25時,近似值為: 0.04403
誤差為: 0.05086 %
x = 0.5時,近似值為: 0.06975
誤差為: -0.00519 %
x = 0.75時,近似值為: 0.06004
誤差為: -0.03583 %
伽遼金法 4 項近似解如下:
{a1: 1297898/6889857, a2: 433198/2296619, a3: -24166/2296619, a4: -66/7681}
x = 0.25時,近似值為: 0.04401
誤差為: 0.00947 %
x = 0.5時,近似值為: 0.06975
誤差為: -0.00519 %
x = 0.75時,近似值為: 0.06006
誤差為: -0.00550 %
伽遼金法 5 項近似解如下:
{a1: 21408027/113632714, a2: 395978157/2102205209, a3: -39848061/4204410418, a4: -1642971/161708093, a5: 33/42106}
x = 0.25時,近似值為: 0.04401
誤差為: 0.00829 %
x = 0.5時,近似值為: 0.06975
誤差為: -0.00435 %
x = 0.75時,近似值為: 0.06006
誤差為: -0.00637 %
伽遼金法 6 項近似解如下:
{a1: 4855505939/25772989853, a2: 179652917103/953600624561, a3: -9215765647/953600624561, a4: -711074859/73353894197, a5: 19857871/73353894197, a6: 715/3484249}
x = 0.25時,近似值為: 0.04401
誤差為: 0.00830 %
x = 0.5時,近似值為: 0.06975
誤差為: -0.00435 %
x = 0.75時,近似值為: 0.06006
誤差為: -0.00638 %
總結
以上是生活随笔為你收集整理的基于等效积分形式的近似方法——加权余量法(配点法,伽辽金法)求解微分方程近似解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 帆软之FineReport填报报表
- 下一篇: btr如何修改服务器手机版我的世界,我的