2

I have a function defined f(x) = acos(x) in python, and want to solve for its zeroes given an initial value. However, fsolve seems to return a math domain error even when my initial guess is well within the domain of the cosine inverse function, or if I start with the actual root as the initial guess.

from math import *
from scipy.optimize import fsolve

def funct(x):
    temp = acos(x)
    return(temp)

print(fsolve(funct, 1))

How do I debug this?

DentPanic42
  • 121
  • 4

1 Answers1

1

You need to do it this way:

from scipy.optimize import fsolve
import numpy as np


def funct(x,a):
    eq = math.acos(x)-a
    return eq 

print(fsolve(funct,0,args=a))

In your case above it is:

print(fsolve(funct,0,args=1))

which return:

[0.76484219]