Reputation: 1
So, the issue I have been having is trying to find a solution to a transcedent function. I have found a root finding in the scipy module and it works wonderfully. My only issue now is how do I manipulate its output.
import numpy as np
from scipy.optimize import root
import random
x_r = random.random()
R_0 = 2500
def func(r):
a = 1-x_r #Calculate "new number"
return ((1+(r/R_0))*np.e**(-r/R_0)) - a #List function
solution = root(func, R_0) #Use python modules to solve.
print solution
The output of this solution is:
status: 1
success: True
qtf: array([ -2.94808622e-12])
nfev: 7
r: array([ 0.00013916])
fun: array([ 1.11022302e-16])
x: array([ 3430.8709539])
message: 'The solution converged.'
fjac: array([[-1.]])
The only numbers I want to keep and store is the r and x values. But I am not exactly sure how I would go about doing that. I would like to avoid writing the data out since this program will run too much data to make that useful.
Upvotes: 0
Views: 83
Reputation: 9940
Simply store the attributes as variables. Use the dot property notation to get the r
and x
values from the solution
object:
r_value = solution.r
x_value = solution.x
Upvotes: 1