Assuming that x is the hourly wind speed I am trying to fit using the Newton Raphson Method as shown below. K is a dimensionless parameter that I intend to solve by using the x values. def f(k) is the actual equation, def d_f(k) is the derivative for the equation and def f2(c) solves for a second parameter c. By default the Scipy optimization library requires the following inputs to find a zero using the Newton-Raphson or secant method.
scipy.optimize.newton(func, x0, fprime=None, args=(), tol=1.48e-08, maxiter=50, fprime2=None)
Therefore my question, is what could be wrong with my Newton Raphson iteration, Or How would you go about the Iteration. Is something wrong with my Inputs or what other inputs do I require? My error results can be seen below output generated.
import warnings
import numpy as np
import scipy
import scipy.stats
import sympy
from scipy import stats as st
x = np.random.randint(1, 23, size=3000)
x0 = np.random.choice(x, 100, replace=True)
def f(k):
return np.sum(x**k*np.log (x))/np.sum(x**k)-1/k- \
1/len(x)*np.sum(np.log(x))
def d_f(k):
return len(x)*np.sum(np.log (x)*np.log(np.log-[1-f(k)])- \
np.sum(np.log(x)*np.sum(np.log(np.log-[1-f(k)]))))
def f2(c):
return np.exp(k*np.sum(np.log (x))-np.sum(np.log(x)* \
np.sum(np.log(np.log-[1-f(k)]))))
#Initial Guess
k = 1.2
scipy.optimize.newton(f(k), x0, fprime=d_f(k))
Generated Output
AttributeError: 'numpy.float64' object has no attribute 'concatenate'