Ask Your Question

ttdsmt's profile - activity

2021-12-18 11:46:46 +0200 marked best answer 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''

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
#the function f(x) 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)

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"?

2021-12-18 09:35:33 +0200 marked best answer Can declare symbolic variable with specific type?

I know syntax to declare symbolic variable is

var('x')

What I want is associating type to this variable, say like var('x', type=float). Can we do it in Sagemath

2021-12-18 09:35:33 +0200 received badge  Scholar (source)
2021-12-17 15:31:03 +0200 edited question scipy.optimize.newton gives TypeError: ufunc 'isfinite' not supported

scipy.optimize.newton gives TypeError: ufunc 'isfinite' not supported Here is the code import scipy.optimize f(x) = x^2

2021-12-17 14:20:41 +0200 received badge  Supporter (source)
2021-12-17 11:57:39 +0200 received badge  Editor (source)
2021-12-17 11:57:39 +0200 edited question Can declare symbolic variable with specific type?

Can declare symbolic variable with specific type? I know syntax to declare symbolic variable is var('x') What I want

2021-12-17 11:57:15 +0200 asked a question Can declare symbolic variable with specific type?

Can declare symbolic variable with specific type? I know syntax to declare symbolic variable is var('x') What I want

2021-12-12 04:27:52 +0200 received badge  Student (source)
2021-12-12 04:25:33 +0200 asked a question scipy.optimize.newton gives TypeError: ufunc 'isfinite' not supported

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