File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
contents/thomas_algorithm/code/clisp Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ ; ;;; Thomas algorithm implementation in Common Lisp
2
+
3
+ (defun thomas (a b c d)
4
+ " Returns the solutions to a tri-diagonal matrix destructively"
5
+ (setf (svref c 0 ) (/ (svref c 0 ) (svref b 0 )))
6
+ (setf (svref d 0 ) (/ (svref d 0 ) (svref b 0 )))
7
+
8
+ (loop
9
+ for i from 1 upto (1- (length a)) do
10
+ (setf
11
+ (svref c i)
12
+ (/ (svref c i) (- (svref b i) (* (svref a i) (svref c (1- i))))))
13
+ (setf
14
+ (svref d i)
15
+ (/
16
+ (- (svref d i) (* (svref a i) (svref d (1- i))))
17
+ (- (svref b i) (* (svref a i) (svref c (1- i)))))))
18
+
19
+ (loop
20
+ for i from (- (length a) 2 ) downto 0 do
21
+ (setf (svref d i) (- (svref d i) (* (svref c i) (svref d (1+ i))))))
22
+
23
+ (return-from thomas d))
24
+
25
+ (defvar diagonal-a # (0 2 3 ))
26
+ (defvar diagonal-b # (1 3 6 ))
27
+ (defvar diagonal-c # (4 5 0 ))
28
+ (defvar last-column # (7 5 3 ))
29
+
30
+ (print (thomas diagonal-a diagonal-b diagonal-c last-column))
You can’t perform that action at this time.
0 commit comments