I have the following
import math
import matplotlib.pyplot as plt
def nraphson(fn, dfn, x, tol, maxiter):
for i in range(maxiter):
xnew = x - fn(x)/dfn(x)
if abs(xnew - x) < tol: break
x = xnew
return xnew, i
y = lambda x: math.exp(x) - x**2
dy = lambda x: math.exp(x) - 2*x
x, n = nraphson(y, dy, j, 10**-5, 100)
guess = range(-10,6)
for j in guess:
print(nraphson(y, dy, j, 10**-5, 100))
my output is of the form
(-0.7034674225098828, 6)
(-0.7034674224990228, 6)
(-0.7034674224984084, 6)
(-0.7034674224983918, 6)
(-0.7034674224983917, 6)
(-0.703467422509882, 5)
(-0.7034674224984084, 5)
(-0.7034674224983917, 5)
(-0.7034674224984067, 4)
(-0.7034674224983924, 3)
(-0.7034674224983924, 4)
(-0.7034674224983917, 5)
(-0.7034674224983917, 6)
(-0.7034674224983917, 6)
(-0.7034674224984245, 8)
(-0.7034674224983917, 10)
I am attempting to isolate the second number from my output to form a list or array to us to plot a graph, how can I adjust my code as to give me a list or array like the following?
[6, 6, 6, 6, 6, 5, 5, 5, 4, 3, 4, 5, 6, 6, 8, 10]