File: test_trisol.pro

package info (click to toggle)
gnudatalanguage 1.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 80,832 kB
  • sloc: cpp: 198,435; ansic: 47,740; sh: 691; python: 474; makefile: 149; xml: 69; f90: 28
file content (62 lines) | stat: -rw-r--r-- 1,659 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
;
; Alain Coulais, 03 Fevrier 2012,
; under GNU GPL v2 or later
;
; basic tests for TRISOL
;
pro TEST_TRISOL, double=double, verbose=verbose, $
                 help=help, test=test, debug=debug
;
if KEYWORD_SET(help) then begin
    print, 'pro TEST_TRISOL, double=double, verbose=verbose, $'
    print, '                 help=help, test=test, debug=debug'
    return
endif
;
; Define Sub Diag Vect. containing the sub-diagonal elements
; with a strarting  0.0 element:  
subdiag=REPLICATE(1.0,4)*2.
subdiag[0]=0.0
;
; Define "diag" containing the main diagonal elements:  
diag=REPLICATE(-4.0,4)
;
; Define Sup Diag Vect. containing the super-diagonal elements
; with a trailing  0.0 element:  
supdiag=REPLICATE(1.0,4)
supdiag[-1]=0.0
; 
; Define the right-hand side vector:  
RHSvect = [6.0, -8.0, -5.0, 8.0]
;
; Compute the solution and print:  
result = TRISOL(subdiag*1D, diag*1D, supdiag*1D, RHSvect*1D, double=double)
;result = TRISOL(subdiag, diag, supdiag, RHSvect, double=double)
PRINT, result
;
TheMatrix=DIAG_MATRIX(diag)
TheMatrix=TheMatrix+DIAG_MATRIX(subdiag[1:*],-1)
TheMatrix=TheMatrix+DIAG_MATRIX(supdiag[0:-1-1],1)
if KEYWORD_SET(debug) then begin
   print, TheMatrix
endif
;
LHSvect=TheMatrix##result
error=TOTAL((LHSvect-RHSvect)^2)
;
if (error GT 1e-10) then begin
   if KEYWORD_SET(test) then STOP
   ;; please notice the error may also come from other parts of codes
   ;; (e.g. bug in DIAG_MATRIX)
   MESSAGE, /continue, 'Numerical error founded.'
   EXIT, status=1
endif else begin
   if ~KEYWORD_SET(verbose) then begin
      MESSAGE, /continue, 'TRISOL succesfully tested'
   endif
endelse
;
if KEYWORD_SET(test) then STOP
;
end