-
Notifications
You must be signed in to change notification settings - Fork 0
/
Solution.py
35 lines (26 loc) · 1.04 KB
/
Solution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import numpy as np
def recursive(methodToRun, upper, lower):
wv = np.linspace(lower, upper, 1001)
delta = abs(abs(upper)-abs(lower))/1001
for wv in wv:
#print(wv)
if abs(abs(methodToRun(wv)) - abs(methodToRun(wv+delta))) < 0.000001 and ((np.sign(methodToRun(wv)) + np.sign(methodToRun(wv+delta)))) == 0:
return wv
elif (np.sign(methodToRun(wv)) + np.sign(methodToRun(wv+delta))) == 0:
return recursive(methodToRun, (wv+delta), wv)
def rangeFinder(methodToRun, lower, upper):
i = np.arange(lower, upper, 0.01)
delta = 0.01#abs(abs(upper)-abs(lower))/10001
val = []
sol = []
kappas = []
for wv in i:
val.append(methodToRun(wv))
if (np.sign(methodToRun(wv)) + np.sign(methodToRun(wv+delta))) == 0:
sol.append([wv, wv+delta])
#print(wv, wv+delta)
for j in sol:
lower, upper = j
print(recursive(methodToRun, upper, lower))
kappas.append(recursive(methodToRun, upper, lower))
return kappas, sol, val, i