Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Tried to create gaussian elimination as python code
- Eventually foudn a script on a site that would do it out.
- The website promptly stopped working around 4pm today, but it was from the umbc math department
- '''
- def gausselim1(themat):
- for i in range(len(themat)):
- for j in range(i+1, len(themat)):
- m = themat[j][i]/themat[i][1]
- themat[j] = [themat[j][k] - m*themat[i][k] for k in range(len(themat[0]))]
- return themat
- # wanted ot check it
- check_matrix = [
- [2,3,4],
- [6,7,8],
- [11,6,9]]
- gausselim1(check_matrix)
- '''
- I tested it against a 2 by 2 matrix - worked fine.
- check1 = [
- [2,4],
- [5,2]]
- gausselim1(check1)
- >>[[1.0, 2.0], [0.0, -8.0]]
- Which is correct.
- Then against a 3 by 3 (see the object check_matrix in the code above). No luck.
- The result was -
- >>
- [ 2.0000 3.0000 4.0000]
- [ 2.0000 1.0000 0.0000]
- [ 13.6667 0.0000 -5.6667]
- Yes, I'm using a formatting script to change it into something that's neater,
- as opposed to the list of lists that it would give. No, it's not the formatting
- script that has the problem - *that* works fine.
- I did the gaussian elimination by hand - here are the steps I got
- R1 (for Row 1), etc -
- R1/2 ->
- [1 3/2 2]
- [6 7 8]
- [11 6 9]
- R2 - 6R1 ->
- [1 3/2 2]
- [0 -2 -4]
- [11 6 9]
- R3 - 11R1 ->
- [1 3/2 2]
- [0 -2 -4]
- [0 -21/2 -13]
- R2/-2 ->
- [1 3/2 2]
- [0 1 2]
- [0 -21/2 -13]
- R3 + (21/2)R2 ->
- [1 3/2 2]
- [0 1 2]
- [0 0 8]
- R3/8 ->
- [1 3/2 2]
- [0 1 2]
- [0 0 1]
- I need someone to -
- a) check that the steps I did out by hand are correct -
- I've gone over them, but it's late and
- it's possible my eyes are playing tricks on me -
- if I made an error it would be on the third step (R3-11R1). I've checked and double checked,
- but there was a moment where I ran out of space on the scrap of paper I was working on,
- and...well, it would be there if it was anywhere.
- b) check the code to tell me where it's going wrong
- '''
Advertisement
Add Comment
Please, Sign In to add comment