When I run my code I receive the error "unsupported operand type(s) for ** or pow(): 'numpy.ufunc' and 'float'"
The code is:
import numpy as np
import matplotlib.pyplot as plt
from numpy import sqrt,exp,log
from scipy import linalg
from scipy.optimize import curve_fit
data1 = np.loadtxt('decay1.txt', float,skiprows=1)
t = data1[:,0]
n = data1[:,1]
data2 = np.loadtxt('decay2.txt', float,skiprows=1)
T = data2[:,0]
N = data2[:,1]
def Radio(n,t,tao,b):
return (n*(exp**(-(t/tao)))) + b
guesses = (1,1,1)
guesses2 = (1,1,1)
(p0,p1,p2),cc = curve_fit(Radio,t,n,guesses)
(p02,p12,p22),cc2 = curve_fit(Radio,T,N,guesses2)
yfit = Radio(t,p0,p1,p2)
y2fit = Radio(T,p02,p12,p22)
I have to fit the function to the radioactive decay data, so tell me if I also messed up the code to fit a function to it. Thanks for any help!
scipy.optimize, but from the docs it looks right to me, with the exception that I think you switched the order of inputs between the function (n,t) and the curve fit (t,n)