-
-
Notifications
You must be signed in to change notification settings - Fork 359
Thomas algorithm implementation in Common Lisp #604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
7b5c628
131ae54
0b2b247
d953323
ca3d80b
ffff663
4aadc56
f4a5770
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
;;;; Thomas algorithm implementation in Common Lisp | ||
|
||
(defun thomas (a b c d) | ||
"Returns the solutions to a tri-diagonal matrix destructively" | ||
(setf (svref c 0) (/ (svref c 0) (svref b 0))) | ||
(setf (svref d 0) (/ (svref d 0) (svref b 0))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment about the macro here. Give them good docstrings. |
||
|
||
(loop | ||
for i from 1 upto (1- (length a)) do | ||
(setf | ||
Trashtalk217 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(svref c i) | ||
(/ (svref c i) (- (svref b i) (* (svref a i) (svref c (1- i)))))) | ||
(setf | ||
(svref d i) | ||
(/ | ||
(- (svref d i) (* (svref a i) (svref d (1- i)))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want to write a macro, |
||
(- (svref b i) (* (svref a i) (svref c (1- i))))))) | ||
|
||
(loop | ||
for i from (- (length a) 2) downto 0 do | ||
(decf (svref d i) (* (svref c i) (svref d (1+ i)))) | ||
finally (return d))) | ||
|
||
(defvar diagonal-a #(0 2 3)) | ||
(defvar diagonal-b #(1 3 6)) | ||
(defvar diagonal-c #(4 5 0)) | ||
(defvar last-column #(7 5 3)) | ||
|
||
(print (thomas diagonal-a diagonal-b diagonal-c last-column)) | ||
Trashtalk217 marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.