> restart:with(plots): Warning, the name changecoords has been redefined > nexpf:=13:cnames:=<c1|c2|c3|c4|c5|c6|c7|c8|c9|c10|c11|c12|c13>: c:=Vector[row](nexpf):for n from 1 to nexpf do c[n]:=cnames[n] end do: uexp:=<proc(x,y) 1; end proc, # define the Harmonic expansion functions proc(x,y) x; end proc, proc(x,y) y; end proc, proc(x,y) x^2-y^2; end proc, proc(x,y) 2*x*y; end proc, proc(x,y) x^3-3*x*y^2; end proc, proc(x,y) 3*x^2*y-y^3; end proc, proc(x,y) x^4-6*x^2*y^2+y^4; end proc, proc(x,y) 4*x^3*y-4*x*y^3; end proc, proc(x,y) x^5-10*x^3*y^2+5*x*y^4; end proc, proc(x,y) 5*x^4*y-10*x^2*y^3+y^5; end proc, proc(x,y) x^6-15*x^4*y^2+15*x^2*y^4-y^6; end proc, proc(x,y) 6*x^5*y-20*x^3*y^3+6*x*y^5; end proc>: bdry:=proc(x,y) x^2+y^2; end proc: # define the boundary function > u:=proc(c,x,y) sum('c[n]*uexp[n,1](x,y)','n'=1..nexpf); end proc:u(c,x,y);bdry(x,y); c1 + c2 x + c3 y + c4 ( x2 − y2 ) + 2 c5 y x + c6 ( x3 − 3 x y2 ) + c7 ( 3 x2 y − y3 ) + c8 ( x4 − 6 x2 y2 + y4 ) + c9 ( 4 x3 y − 4 x y3 ) + c10 ( x5 − 10 x3 y2 + 5 x y4 ) + c11 ( 5 x4 y − 10 x2 y3 + y5 ) + c12 ( x6 − 15 x4 y2 + 15 x2 y4 − y6 ) + c13 ( 6 x5 y − 20 x3 y3 + 6 x y5 ) x2 + y2 > linerr:=<proc (c) int((u(c,0,t)-bdry(0,t))^2,t=0..2); end proc, # line integrals proc (c) int((u(c,t,2)-bdry(t,2))^2,t=0..1); end proc, proc (c) int((u(c,1,t)-bdry(1,t))^2,t=0..2); end proc, proc (c) int((u(c,t,0)-bdry(t,0))^2,t=0..1); end proc>: err:=proc(c) sum('linerr[n,1](c)','n'=1..4); end proc: # the error expression simplify(err(c)); 43 c2 10536 c12 c9 196 360 c12 c4 2148 c72 35048 c7 c12 −24 c1 − − + + 2650 c12 c13 − + + 3 5 5 7 35 105 6699076 c122 112 c3 264 c4 482 c6 328 c7 376 c8 584 c9 4807 c10 + − + − 42 c5 + + − + − 1001 3 5 5 5 7 3 14 232 c11 2552 c12 72 c1 c8 8 c1 c11 28 c32 2 + − − 507 c13 + 6 c1 + 12 c1 c3 + − + 7 9 5 3 3 + 472 c3 c8 8 c3 c11 7788 c82 285976 c8 c11 272708 c112 168 c3 c7 + + + + − 16 c1 c7 − 15 7 35 315 231 5 − 6968 c7 c8 279592 c8 c12 3682376 c11 c12 360 c1 c12 648 c3 c12 17912 c7 c11 − − + + − 35 165 693 7 7 63 226 c1 c10 8 c22 96 c2 c6 158 c2 c8 368 c2 c10 1623 c2 c12 + 6 c1 c2 − 23 c1 c6 + + − − + + 3 3 5 15 7 14 + 3048 c62 2659 c6 c8 37568 c6 c10 111988 c6 c12 64858 c8 c10 310088 c102 + − − + + 35 70 63 105 315 231 + 2210543 c10 c12 3041120 c10 c13 4116 c8 c13 40 c1 c4 80 c3 c4 − 642 c10 c11 + + − − 693 693 5 3 3 116 c42 8488 c8 c4 1256 c11 c4 1016 c7 c4 + − − + + 108 c1 c13 − 44 c1 c9 + 12 c1 c5 5 105 21 15 − 130 c11 c2 2023 c11 c6 136856 c11 c13 36332 c11 c9 3112 c11 c5 454 c3 c10 + + + − + 3 6 693 63 21 3 + 6 c3 c2 − 43 c3 c6 + 1592 c3 c13 1288 c3 c9 56 c3 c5 10907 c4 c10 13 c4 c2 − + − − 7 15 3 42 3 + 926 c4 c6 1295 c4 c13 2063 c7 c10 − + 136 c4 c9 − 22 c4 c5 − − c7 c2 + 54 c7 c6 15 3 6 − 73054 c7 c13 5232 c7 c9 68 c7 c5 10 c8 c9 86528 c10 c9 + − + 425 c12 c5 − − 28 c8 c5 − 105 35 5 3 63 + 4448 c10 c5 416 c2 c13 512 c2 c9 32 c2 c5 83936 c6 c13 12288 c6 c9 + − + − + 21 7 15 3 105 35 352 c6 c5 318928 c132 30272 c13 c9 1824 c13 c5 13248 c92 1984 c9 c5 − + − + + − + 16 c52 5 77 15 7 35 15 > derr:=Vector(nexpf): # partial derivatives for optimum for n from 1 to nexpf do derr[n]:=diff(err(c),c[n])=0 end do:derr; ⎡ 13 Element Column Vector ⎤ ⎢ ⎥ ⎢ Data Type: anything ⎥ ⎢ ⎥ ⎢ Storage: rectangular ⎥ ⎢ ⎥ ⎣ Order: Fortran_order ⎦ # use Linear Algebra package to generate > with(LinearAlgebra): matrix equations > eqns:=[seq(derr[n],n=1..nexpf)]:var:=[seq(c[n],n=1..nexpf)]:(A,b): =GenerateMatrix(eqns,var); ⎡ 13 x 13 Matrix ⎤ ⎡ 13 Element Column Vector ⎤ ⎢ ⎥ ⎢ ⎥ ⎢ Data Type: anything ⎥ ⎢ Data Type: anything ⎥ ⎥, ⎢ ⎥ A, b := ⎢ ⎢ Storage: rectangular ⎥ ⎢ Storage: rectangular ⎥ ⎢ ⎥ ⎢ ⎥ ⎣ Order: Fortran_order ⎦ ⎣ Order: Fortran_order ⎦ > ans:=LinearSolve(A,b):for k from 1 to nexpf do c[k]:=ans[k] end do:c;"|Error| ",evalf(sqrt(err(c))); ⎡ 13 Element Row Vector ⎤ ⎢ ⎥ ⎢ Data Type: anything ⎥ ⎢ ⎥ ⎢ Storage: rectangular ⎥ ⎢ ⎥ ⎣ Order: Fortran_order ⎦ "|Error| ", 0.009249985881 > errxy:=proc(x,y) evalf(sqrt((u(c,x,y)-bdry(x,y))^2)); end proc: # boundary error as a function of (x,y) plot({u(c,0,y),bdry(0,y),errxy(0,y)},y=0..2,color=[black,blue,red] ,thickness=4,linestyle=[1,2,3]); # u(x,y) and boundary function plots plot({u(c,x,2),bdry(x,2),errxy(x,2)},x=0..1,color=[black,blue,red] ,thickness=4,linestyle=[1,2,3]); plot({u(c,1,y),bdry(1,y),errxy(1,y)},y=0..2,color=[black,blue,red] ,thickness=4,linestyle=[1,2,3]); plot({u(c,x,0),bdry(x,0),errxy(x,0)},x=0..1,color=[black,blue,red] ,thickness=4,linestyle=[1,2,3]); plot3d(u(c,x,y),x=0..1,y=0..2); contourplot(u(c,x,y),x=0..1,y=0..2,thickness=4); > evalf(maximize(errxy(0,t),t=0..2)); the boundary evalf(maximize(errxy(t,2),t=0..1)); evalf(maximize(errxy(1,t),t=0..2)); evalf(maximize(errxy(t,0),t=0..1)); # calculate maximum error on 0.01220150700 0.01220150472 0.01220150700 0.01220150472 > plot({errxy(1,y)},y=0..2,color=black,thickness=4,linestyle=3); plot({errxy(0,y)},y=0..2,color=black,thickness=4,linestyle=3); plot({errxy(x,0)},x=0..1,color=black,thickness=4,linestyle=3); plot({errxy(x,2)},x=0..1,color=black,thickness=4,linestyle=3); > >
© Copyright 2025 Paperzz