# Revision history [back]

### TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

Here is the code

import scipy.optimize
var('x')
f(x) = x^2 - 4*sin(x)
fp(x) = diff(f(x),x)
scipy.optimize.newton(f,1.5,fp)


and get type error

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

 2 None slelievre 16319 ●19 ●146 ●324 http://carva.org/samue...

### TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

Here is the code

import scipy.optimize
var('x')
f(x) = x^2 - 4*sin(x)
fp(x) = diff(f(x),x)
scipy.optimize.newton(f,1.5,fp)


and get type error

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

### scipy.optimize.newton gives TypeError: ufunc 'isfinite' not supported

Here is the code

import scipy.optimize
f(x) = x^2 - 4*sin(x)
fp(x) = diff(f(x),x)
scipy.optimize.newton(f,1.5,fp)


and get type error

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

Here is the code

How to solve this error?

Some other information:

Run in Sagemath 9.4 on Cocalc.com

This code from the book "Numerical Analysis Using Sage by George A. Anastassiou, Razvan A. Mezei" which use "Sage Version 6.3, Release Date: 2014-08-10". Here, I edited the origin code (removing comment, and print command), the original code is:

#import the following library
import scipy.optimize
var('x')
#the function f(x) = x^2 - 4*sin(x)
fp(x) = diff(f(x),x)
scipy.optimize.newton(f,1.5,fp)
from our problem
f(x) = x^2-4*sin(x)
#compute the derivative of f
fp(x)=diff(f(x),x)
#call the Newton’s method and output the result
print "solution = " , scipy.optimize.newton(f, 1.5, fp)


and get type error

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

An extra question, is this code work on the old version of Sage in the above book, i.e. "Sage Version 6.3, Release Date: 2014-08-10"?