kill(all)$

maxima: Weighted residual methods,version 1.0
peter.vlasschaert@gmail.com,14/12/2020

ref 1:
===

youtube:https://www.youtube.com/watch?
v=M2AwacE25iI&list=PLVLLmrCGvV_zgEABjq4JCRK9B25imxt6S&index=14

ref 2:
====
ortho collocation method , my website

2e) orthogonal collocation method.
----------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------

new: 03/09/2019:ortho collocation method :  shifted legendre polynomials,  'version 1.0',part 1
download  (Maxima,code)       :orthocolshiftedlegendrepolynomialszeroto1version1finalpart1
download  (Maxima,png)         :orthocolshiftedlegendrepolynomialszeroto1version1finalpart1outp
new: 17/09/2019:ortho collocation method :  shifted legendre polynomials,  'version 1.0',part 2
download  (Maxima,code)       :orthocolshiftedlegendredifferentialeqversion1finalpart2
download  (Maxima,png)         :orthocolshiftedlegendredifferentialeqversion1finalpart2outp
new: 17/09/2019:ortho collocation method :  shifted legendre polynomials (hypergeometric :2F1), 
 'version 1.0',part3
download  (Maxima,code)       :orthocolshiftedlegendredifferentialeqversion1finalpart3
download  (Maxima,png)         :orthocolshiftedlegendredifferentialeqversion1finalpart3outp
new: 09/11/2020:maxima : appendix : 'ortho collocation method :sum,legendre',version 1.0
download  (Maxima,code)       :maximaappendixorthocollocationsumlegversion1final
download  (Maxima,png)         :maximaappendixorthocollocationsumlegversion1finaloutp
new: 16/11/2020:maxima : point collocation  method,version 1.0,part 1
download  (Maxima,code)       :maximapointcollocationversion1finalpart1
download  (Maxima,png)         :maximapointcollocationversion1finalpart1outp
new: 17/11/2020:maxima : point collocation  method,version 1.0,part 2
download  (Maxima,code)       :maximapointcollocationversion1finalpart2
download  (Maxima,png)         :maximapointcollocationversion1finalpart2outp
new: 27/11/2020:maxima : orthogonal collocation BVP :ODE,c(x) ,iso TRAM, vesion 1.0
youtube :Orthogonal Collocations Method for Solving ODE - BVPs and PDEs
download  (Maxima,code)       :maximaorthocollocisotramversion1final
download  (Maxima,png)         :maximaorthocollocisotramversion1finaloutp
new: 01/12/2020:maxima : orthogonal collocation BVP :PDE c(x,t),iso TRAM, version 1.0
download  (Maxima,code)       :maximaorthocollocpdetimeisotramversion1final
download  (Maxima,png)         :maximaorthocollocpdetimeisotramversion1finaloutp
--------------------------------------------------------------------------------------------------------------------------------
other examples :on my website.

load packages,option 
=================

load(lrats)$ ratprint:false $

Model : Differential Equation ( :BVP)
============================

→ Differential Equation (1)
     Domain : 0 < x <1

p1a:-1*'diff(u,x,2)=sin(%pi*x);

exact :solution (1)

Menu : Equations:Solve ODE

p1a1:ode2(p1a,u,x);

→ Boundary Conditions 

first :     BC (begin,x=0), (2)

p1a2a:[x=0,u=0];

second :BC (end,x=1   ),(3)

p1a2b:[x=1,u=0];

Menu:Equations:Boundary Value Problem:'BC2'

solution :(1) & (2),(3), 'exact solution'

sol:bc2(p1a1,p1a2a[1],p1a2a[2], p1a2b[1],p1a2b[2]);

solexact:rhs(sol);

Weighted Residual Methods
======================
check this :
-------------------------------------------------------------------------------------
step 1:trial solution :satisfy BC .
step  2:assumed trial solution (not exact) → Residual Error ( =R)
step  3:residual @ point ,sum up all points → total residual
step  4:"danger of cancelation" → multiply this residual with weight 
            function(=W) and integrate over the domain[begin to end].
---------------------------------------------------------------------------------------

general consideration
------------------------------

powerdisp:true$

a) trial solution:uu, (1) & ((2),(3))
-------------------------------------------

→  polynomial

p2:uu=sum(a[i]*x^i,i,0,2);

→ satisfy:BC,see above (2) & (3)

1e BC :(2)

p2a1:[reverse(subst([uu=0,x=0],p2))];

2e BC :(3)

p2a2:subst([uu=0,x=1],p2);

p2a3:subst(p2a1,p2a2);

p2a4:solve(p2a3,a[1]);

→ find :uu ,satisfy BC

p2b:subst([p2a1],p2);

use :p2a4

final:uu

p2b1:subst(p2a4,p2b);

b) residual :R, trial function.
-------------------------------------

→  use (1), u=uu

p3a:subst([u=uu],lhs(p1a)-rhs(p1a));

p3a1:factor(p3a);

→ R 'see above'

p3a2:R=p3a1;

use :final(uu),p2b1

p3a3:factor(subst([p2b1],p3a2));

p3a4:ev(p3a3,diff);

p3a4a:rhs(p3a4);

p3a41:listofvars(rhs(p3a4));

p3a42:makelist(p3a41[i],i,1,length(p3a41)-1);

question arise here : How to find a[i], i=2 → a[2]

c)integral :with R, W=W(x)
-----------------------------------
domain:y1=0 < x < y2=1, d(x) =dx ' symbolic integration '

representation: problem:

p4:I = 'integrate(rhs(p3a4)*W(x)*'d(x),x,y1,y2);

   => input :domain,begin = y1,end = y2

p4a:subst([y1=0,y2=1],p4);

Weighted Residual Method  :
---------------------------------------
------------------------------------------------------------------
first       method : Least Square Method       (LSM)
second method  : Point Collocation Method (PCM)
third      method  : Sub   Domain Method       (SDM)
fourth    method  : Galerkin Method               (GM)
-------------------------------------------------------------------

use : methods above for : Finite Element Method (FEM)

first       method : Least Square Method       (LSM)
=======================================
W(x) =R, representation 'p4a', find a[i], i=2,.. →a[2]
reason :integral  of weighted  square of the residual → minimum

→ integrandum (use:p3a4)

p5a:p3a4*p3a4;

p5a1:rhs(p5a);

→integral

p5b:I='integrate(p5a1,x,0,1);

→ ∂I/∂a[i], i=2,.. only here :a[2] 'problem : trial ',p3a42

p5c:'diff(I,p3a42[1])='diff(rhs(p5b),p3a42[1]);

→ ∂I/∂a[i] =0, i=2,.. minimum

p5d:rhs(p5c)=0;

→ evaluation

p5e:ev(p5d,diff,integrate);

→ find : a[i],i=2,...→ a[2],use p3a42

p5f:solve(p5e,p3a42);

→ solution (= LSM),use:p2b1

p5g:factor(subst(p5f,p2b1));

sollsm:rhs(p5g);

second method  : Point Collocation Method (PCM)
=========================================
W=W[i]=δ(x-x[i]),i=1,2,...n, i = specific points
reason:residual(=R) set equal to zero @ n: specific points
-----------------------------------------------------------------------------
rule :
-------
δ(x-x[i]) = 0  when  x≠x[i]
δ(x-x[i]) = 1  when  x=x[i]

representation: d(x) =dx, R='p3a4a' ,see above

property : dirac delta function ( see :rule)
--------------------------------------

p6:'integrate(δ(x-x[i])*p3a4a*d(x),x,0,1)=subst([x=x[i]],p3a4a);

→  x[i] , i=1 => x[1]  =>a[2]    :  ' 0< x[1] < 1'  => R(x[1])=0
------------------------------------------------------------------------------
general :x[i] => a[i]  i=0,1,2,..n  :   '0< x[i] < 1'   => R(x[i])=0
------------------------------------------------------------------------------
rem :problem "uu=-a[2]*x+a[2]*x^2" ,approximation of u

→ x[i]=x[1] =0.5,  0< x[1] < 1,example value , select other values also.

p6a:R=subst([x[i]=0.5],rhs(p6));

→ R(x[i])=0  i=0,1,2,...;n

p6b:rhs(p6a) = 0;

→ solve a[i], i=0,1,2,..n , here a[2] = p3a42

p6c:solve(p6b,p3a42);

→ solution (= PCM),use:p2b1

p6d:factor(subst(p6c,p2b1));

solpcm:rhs(p6d);

third      method  : Sub   Domain Method       (SDM)
=======================================
W(x)=W[i] =1,domain subdivided → n :sub-domains
reason : number of integration interval = number of undetermined 
              coefficent:a[i] , in the trial function (see:p2b1).

problem : a[2] , 0< x <1 , because : only one value = no sub-domains 

representation : (no :weighting function =1)
---------------------
use:p3a4a

p7:'integrate(p3a4a,x,0,1)=0;

p7a:ev(p7,integrate);

rem : option integrate p7a → nouns   'general'

→ solve a[i], i=0,1,2,..n , here a[2] = p3a42

p7b:solve(p7a,p3a42);

→ solution (= SBM),use:p2b1

p7c:factor(subst(p7b,p2b1));

solsbm:rhs(p7c);

fourth    method  : Galerkin Method               (GM)
=======================================
W(x) =W[i]

representation : (W(x)=W[i]),d(x) = dx
---------------------
use:p3a4a
---------------------------------------------------------------------------

p8:'integrate(W(x)*p3a4a*d(x),x,0,1);

→  W[i] =diff(uuu,a[i]) , i=0,1,....n ,problem a[i],i=2,p3a42

use :p2b1

p8a:W(x)='diff(rhs(p2b1),p3a42[1]);

p8b:subst([p8a],p8)=0;

----------------------------------------------------------------------------

solve :(1)

→ first : W(x)

p9a:ev(p8a,nouns);

→ second : d(x)=1,use p8b

p9b:subst([d(x)=1],p8b);

→  third:evaluation integral

p9c:ev(p9b,nouns);

→ fourth : find a[2]

p9d:solve(p9c,p3a42);

→ fifth : subst in trial function (=p2b1)

p9e:subst(p9d,p2b1);

solgm:factor(rhs(p9e));

plot 2d (all functions x, domain : 0≤x≤1)
=====
→ solexact,sollsm,solpcm,solsbm,solgm

use : maxima (wxplo2d , inside document,outside : no wx before)

use :Menu:Plot:Plot2d

rem :wxplot2d([sol(exact),sol(lsm),sol(pcm),sol(sbm),sol(gm)], [x,-1.1,1.1])$

wxplot2d([solexact,sollsm,solpcm,solsbm,solgm],
     [x,0,1.01],[y,0,0.14],grid2d)$

info :wxplot2d
----------------------------------------------
blue ' exact solution for (1) & (2,3)'
----------------------------------------------
===========================================
lsm :-((-1+x)*x)/%pi
pcm:-((-1+x)*x)/2
sbm:-((-1+x)*x)/%pi
gm  :-(12*(-1+x)*x)/%pi^3  (Best Method:black :ref blue)
===========================================
finite element : use gm : method ' = Galerkin Method '
--------------------------------------------------------------------------