Method of Weighted Residual on the HP 28S
03-11-2017, 03:18 AM (This post was last modified: 02-08-2022 07:54 PM by mbrethen.)
Post: #1
 mbrethen Junior Member Posts: 40 Joined: Dec 2013
Method of Weighted Residual on the HP 28S
Prior to development of the Finite Element Method, there existed an approximation technique for solving differential equations called the Weighted Residual Method (WRM). In order to explain the method, consider the example problem in the attached pdf. A trial function, u = ax(1-x), is selected as an approximate solution to the differential equation. The trial function is chosen such that it satisfies the boundary conditions and it has one unknown coefficient to be determined. Once a trial function is selected, the residual R is computed by substituting the trial function into the differential equation. Because u is different from the exact solution, the residual does not vanish for all values of x within the boundary values. The next step is to determine the unknown constant a such that the chosen test function best approximates the exact solution. For Galerkin's method, the test function w comes from the chosen trial function, i.e. w = du/da and the weighted average of the residual over the problem domain is set to zero.

Code:
WRU1 ( Weighted Residual 1 ) Utility Program:                                Comments: «   → n                                   Save parameter.   «     LIST→ DROP 1 n                      Put x, a & b on stack. Drop size.     FOR m       "I" 48 m + CHR + STR→             I1 … In      NEXT     n →LIST                             Make weighted residual list.   » » WRU2 ( Weighted Residual 2 ) Utility Required Program:  • MSLV Program:                                Comments: «   DO                     GETI 1E-3 SWAP STO                  Store initial guesses.   UNTIL     46 FS?   END   DROP   1E-5 DUP                              Acceptable error and delta.   MSLV CLMF DROP                        Run the solver. » CMWR ( Collocation Method of Weighted Residual ) Main -------------------------------------------------------------------------------- |  Level 3     Level 2      Level 1     |     Level 1                          | -------------------------------------------------------------------------------- |  'symb'      {list}     {global a b}  →     'symb'                           | -------------------------------------------------------------------------------- Required Program:  • DEQ  • WRU1  • WRU2 Program:                                Comments: «   OVER SIZE → n                         n = number of unknown coefficients.   «     n WRU1 → uc x a b wr                Save parameters.     «        DUP x       DEQ       1. n       FOR j         'W' j GET                       xᵢ         x STO R EVAL                    δ(xᵢ)R (x {aᵢ})         x 4 ∫ DUP         a b                             Boundary values         FOR k           k x STO EVAL SWAP             Compute the weighted average of the         b a - STEP -                    residual over the problem domain.         wr j GET STO                    Store I1 … In.         x PURGE       NEXT                              Collect weighted residuals.       wr uc 1 WRU2                      Evaluate trial function.     »   » » LSMWR ( Least-Squares Method of Weighted Residual ) Main -------------------------------------------------------------------------------- |  Level 3     Level 2      Level 1     |     Level 1                          | -------------------------------------------------------------------------------- |  'symb'      {list}     {global a b}  →     'symb'                           | -------------------------------------------------------------------------------- Required Program:  • DEQ  • WRU1  • WRU2 Program:                                Comments: «   OVER SIZE → n   «     n WRU1 → uc x a b wr     «        DUP x       DEQ       { }       1. n       FOR i         R         uc i GET                        aᵢ         ∂ +                             dR/daᵢ       NEXT       'W' STO       1. n       FOR j         'W' j GET                       Put wᵢ on the stack.         R *                                     x 6 ∫ DUP         a b         FOR k            k x STO EVAL SWAP         b a - STEP -         wr j GET STO         x PURGE       NEXT       wr uc 1 WRU2     »   » » GMWR ( Galerkin's Method of Weighted Residual ) Main -------------------------------------------------------------------------------- |  Level 3     Level 2      Level 1     |     Level 1                          | -------------------------------------------------------------------------------- |  'symb'      {list}     {global a b}  →     'symb'                           | -------------------------------------------------------------------------------- Required Program:  • DEQ  • WRU1  • WRU2 Program:                                Comments: «   OVER SIZE → n   «     n WRU1 → uc x a b wr     «        DUP x       DEQ       { }       1. n       FOR i         OVER                            û         uc i GET                        aᵢ         ∂ +                             dũ/daᵢ       NEXT       'W' STO       1. n       FOR j         'W' j GET                       Put wᵢ on the stack.         R *         x 6 ∫ DUP         a b         FOR k            k x STO EVAL SWAP         b a - STEP -         wr j GET STO         x PURGE       NEXT       wr uc 1 WRU2     »   » »

The most straightforward method of defining R is to store the program DEQ:
Code:
<< → u x << u x ∂ x ∂ u - x + 'R' STO >> >>

Execute GWRM with three arguments, as follows:
1. The level 3 argument is an algebraic object that represents the trial function, e.g. 'A*X*(1-X)'.
2. The level 2 argument is a list containing the unknown coefficients, e.g. { A }.
3. The level 1 argument is a list containing the independent variable and boundary values, e.g. { 'X' 0 1}.

The program returns the trial function with a = 0.22727 (runtime ~1 min 48 sec). It is shown plotted with the exact solution for 0<x<1. In order to improve the approximation another term is added to the trial function, u = a1x(1-x) + a2x^2(1-x). This solution took about 31 min.

RPL calculators did not have a simultaneous equation solver until the 49 series introduced the MSLV function. Mike Ingle wrote the code TMSLV for the 48GX and HP-28C&S. It can be found elsewhere on the web.

Edit: Program now includes the Collocation and Least Squares methods.

Attached File(s)