-
-
Notifications
You must be signed in to change notification settings - Fork 360
thomas python example #191
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
fdaef2e
3563e6d
d7f0169
454f5ad
af16b12
e453395
e07f3a7
4ca6840
02e964e
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 |
---|---|---|
|
@@ -13,4 +13,5 @@ Chinmaya Mahesh | |
Unlambder | ||
Kjetil Johannessen | ||
CDsigma | ||
Gammison | ||
DominikRafacz |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#Author: gammison | ||
|
||
#note this example is inplace and destructive | ||
def thomas(a,b,c,d): | ||
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. There should be spaces after every comma in the parameter list. |
||
|
||
#set the initial elements | ||
c[0] = c[0] / b[0] | ||
d[0] = d[0] / b[0] | ||
|
||
n = len(d) #number of equations to solve | ||
#range is exclusive, loop will run from 1 to n-1 | ||
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. I think |
||
for i in range(1,n): | ||
#scale factor for c and d | ||
scale = 1 / (b[i] - c[i-1]*a[i]) | ||
|
||
c[i] = c[i] * scale | ||
d[i] = (d[i] -a[i] * d[i-1]) * scale | ||
|
||
|
||
#do the back substitution, will loop n-2 to 0 inclusive | ||
for i in range(n-2,-1,-1): | ||
d[i] = d[i] - c[i]*d[i+1] | ||
|
||
return d | ||
|
||
def main(): | ||
#example for matrix | ||
#[1 4 0][x] [7] | ||
#[2 3 5][y] = [5] | ||
#[0 3 6][z] [3] | ||
# [.8666] | ||
#soln will equal [1.533] | ||
# [-.266] | ||
#note we index a from 1 and c from 0 | ||
a=[0,2,3] | ||
b=[1,3,6] | ||
c=[4,5,0] | ||
d=[7,5,3] | ||
soln = thomas(a,b,c,d) | ||
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. Again, add some spaces before and after 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. Done |
||
print(soln) | ||
|
||
if __name__ == '__main__': | ||
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the other Python code in the project puts a space between
#
and the comment text.