QandA
QandA

Reputation: 11

Could I find a variable in the bessel function in python?

I am using Python to solve an equation. I added the 'Bessel function' in scipy.special, It was working. Now I want to find a variable using Bessel function. For example, I added the order(1) and value(0.44005058574) in Python, but it is not working. (in order to find the variable, I also used solver)

How I can solve the problem?

import numpy as np
import scipy.special as sc
import math
from sympy import Symbol
from sympy.solvers import solve

x=Symbol('x')
y=sc.jn(1,x)-0.44005058574
print(solve(x))

Upvotes: 0

Views: 257

Answers (1)

caverac
caverac

Reputation: 1637

As the output is hinting, the function scipy.special.jn does not know how to handle the object x from simpy. Instead, you should use a numerical approach

>>> from scipy import optimize
>>> f = lambda x: sc.jn(1, x) - 0.44005058574
>>> root = optimize.newton(f, 1.0)
>>> print(root)
0.9999999999848267

Upvotes: 1

Related Questions