I am trying to find the roots of my equation but I am getting an error that "numpy.ndarray" object is not callable

Viewed 39

I am trying to find the roots of my equation but I am getting an error that :

"numpy.ndarray" object is not callable

my code:

import numpy as np
from scipy.optimize import fsolve

q = (3 * np.sin(t / np.sqrt(2))) - (np.sin(t))

root = fsolve(q, 4)
print(root)
1 Answers

When you want to use from scipy.optimize import fsolve, You need write q as function. Try this:

import numpy as np
from scipy.optimize import fsolve

def func(x):
    return (3 * np.sin(t / np.sqrt(2))) - (np.sin(t))


root = fsolve(func, 1)
print(root)
Related