Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Make function parameters conform to the Python Style Guide http://www…

  • Loading branch information...
commit 8b04f36e1f1b29dcd1eef9a171cb62325b402f83 1 parent c79ac39
Andreas Pauley authored September 02, 2010

Showing 1 changed file with 8 additions and 8 deletions. Show diff stats Hide diff stats

  1. 16  Chapter1/Python/numerical-methods.py
16  Chapter1/Python/numerical-methods.py
@@ -20,14 +20,14 @@ def swap_points(x):
20 20
 def sub_dict(somedict, somekeys, default=math):
21 21
 		return dict([ (k, somedict.get(k, default)) for k in somekeys ])
22 22
 
23  
-def evaluate(func,x):
  23
+def evaluate(func, x):
24 24
 	safe_list = ['math','acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'cosh', 'de grees', 'e', 'exp', 'fabs', 'floor', 'fmod', 'frexp', 'hypot', 'ldexp', 'log', 'log10', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh'] #use the list to filter the local namespace
25 25
 	safe_dict = sub_dict(locals(),safe_list)
26 26
 	safe_dict['abs'] = abs
27 27
 	safe_dict['x']=x
28 28
 	return eval(compile(func,"",'eval'),{"__builtins__":{}},safe_dict)
29 29
 
30  
-def mullers_method(func,a,b,r, maxSteps = 30, tolerance = 0.0001):
  30
+def mullers_method(func, a, b, r, maxSteps=30, tolerance=0.0001):
31 31
 	print_header("Muller's method",func)
32 32
 	x = [a,b,r]
33 33
 	for loopCount in range(maxSteps):
@@ -53,7 +53,7 @@ def mullers_method(func,a,b,r, maxSteps = 30, tolerance = 0.0001):
53 53
 		x = swap_points(x)
54 54
 	print_end()
55 55
 
56  
-def bisection(func, a,b,maxSteps = 30, tolerance = 0.0001):
  56
+def bisection(func, a, b, maxSteps=30, tolerance=0.0001):
57 57
 	print_header("Bisection Method", func)
58 58
 	initial = evaluate(func,float(a))
59 59
 	for loopCounter in range(maxSteps):
@@ -67,7 +67,7 @@ def bisection(func, a,b,maxSteps = 30, tolerance = 0.0001):
67 67
 			b = midPoint
68 68
 	print_end()
69 69
 
70  
-def secant(func,a,b,maxSteps=30, tolerance = 0.0001):
  70
+def secant(func, a, b, maxSteps=30, tolerance=0.0001):
71 71
 	print_header("secant method",func)
72 72
 	if (abs(evaluate(func,float(a))) < abs(evaluate(func,float(b)))):
73 73
 		t = b
@@ -85,7 +85,7 @@ def secant(func,a,b,maxSteps=30, tolerance = 0.0001):
85 85
 	print "Root find stopped at %.9f" % p
86 86
 	print_end()
87 87
 
88  
-def regula_falsi(func, a,b, maxSteps = 30, tolerance = 0.0001):
  88
+def regula_falsi(func, a, b, maxSteps=30, tolerance=0.0001):
89 89
 	print_header("regula falsi (false position)",func)
90 90
 	p = 0.0
91 91
 	for loopCount in range(maxSteps):
@@ -101,7 +101,7 @@ def regula_falsi(func, a,b, maxSteps = 30, tolerance = 0.0001):
101 101
 	print "Root find cancelled at %.9f" % p
102 102
 	print_end()
103 103
 
104  
-def print_header(t,f):
  104
+def print_header(t, f):
105 105
 	print "\n"
106 106
 	print "-" * 50
107 107
 	print "Using %s to solve %s" % (t,f)
@@ -124,7 +124,7 @@ def fixed_point(func, initialApproximation, maxSteps=30, tolerance=0.0001):
124 124
 		p = oldP
125 125
 	print_end()
126 126
 
127  
-def newton_raphson(func, derFunc, initialApproximation, maxSteps = 30, tolerance= 0.0001):
  127
+def newton_raphson(func, derFunc, initialApproximation, maxSteps=30, tolerance=0.0001):
128 128
 	print_header("newton/raphson",func + " with " + defFunc + " as derivative")
129 129
 	for loopCounter in range(maxSteps):
130 130
 		p = initialApproximation - (evaluate(func,float(initialApproximation))/evaluate(derFunc,float(initialApproximation)))
@@ -138,6 +138,6 @@ def newton_raphson(func, derFunc, initialApproximation, maxSteps = 30, tolerance
138 138
 if __name__ == '__main__':
139 139
 	try:
140 140
 		print "in __main__"
141  
-		mullers_method("math.cos(x) - x",0.0,0.5,1.0)
  141
+		mullers_method("math.cos(x) - x", 0.0, 0.5, 1.0)
142 142
 	finally:
143 143
 		print "Fully done."

0 notes on commit 8b04f36

Please sign in to comment.
Something went wrong with that request. Please try again.