Permalink
Browse files

Change tabs to 4 spaces

  • Loading branch information...
1 parent a79e094 commit 455e72905f8c9cbf284c9cc22859b2bca4991b5d Andreas Pauley committed Sep 2, 2010
Showing with 16 additions and 16 deletions.
  1. +16 −16 Chapter1/Python/secant.py
View
@@ -6,22 +6,22 @@
from helpers import *
def secant(func, a, b, max_steps=MaxSteps, tolerance=Tolerance):
- print_header("secant method",func)
- if (abs(evaluate(func,float(a))) < abs(evaluate(func,float(b)))):
- t = b
- b = a
- a = t
- print "a = %.9f b = %.9f" % (a,b)
- for loopCount in range(max_steps):
- p = b - (evaluate(func,float(a)) * ((a-b)/(evaluate(func,float(a))-evaluate(func,float(b)))))
- print "Current approximation is %.9f" % p
- if (abs(evaluate(func,float(p))) < tolerance):
- print "Root is %.9f (%d iterations)" % (p,loopCount+1)
- return
- a = b
- b = p
- print "Root find stopped at %.9f" % p
- print_end()
+ print_header("secant method",func)
+ if (abs(evaluate(func,float(a))) < abs(evaluate(func,float(b)))):
+ t = b
+ b = a
+ a = t
+ print "a = %.9f b = %.9f" % (a,b)
+ for loopCount in range(max_steps):
+ p = b - (evaluate(func,float(a)) * ((a-b)/(evaluate(func,float(a))-evaluate(func,float(b)))))
+ print "Current approximation is %.9f" % p
+ if (abs(evaluate(func,float(p))) < tolerance):
+ print "Root is %.9f (%d iterations)" % (p,loopCount+1)
+ return
+ a = b
+ b = p
+ print "Root find stopped at %.9f" % p
+ print_end()
if __name__ == '__main__':
secant(example_f, 1, 0)

0 comments on commit 455e729

Please sign in to comment.