0
votes

I am solving a physical problem in which I have to work with the unbounded radial solution of the Schroedinger equation in the presence of a point-like charged particle Zeff.

I define the UNBRWAVE function in python as:

import numpy as np
import math as mh
from mpmath import *
a0 = 1/3.7 #edited new
Zeff = 1.0 #edited new

def UNBRWAVE(r, k, L, n, l):
      return (2.0*np.pi)**(3.0/2.0)*(2.0*k*r)**L*(np.sqrt(2.0/np.pi)*np.abs(mh.gamma(L+1.0-(1j*Zeff)/(k*a0)))*np.exp(np.pi*Zeff/(2.0*k*a0)))/nh.gamma(2.0*L+1.0+1.0)*np.exp(-1j*k*r)*hyp1f1(L+1.0-(1j*Zeff)/(k*a0), 2.0*(L+1.0), 2.0*1j*k*r)

Where Zeff=1, 1j is the imaginary unit and hyp1f1 is the hypergeometric 1F1 function. The input parameters are r(a real number), k (a real number), L (an integer number), n (an integer number), l(an integer number). Whenever I call this function, like in

UNBRWAVE(10.0, 5.0, 5, 1, 0) 

I get the error message

TypeError: can't convert complex to float

I am new in python so I would like to know how to code better this complex function of real arguments to get the values and perform operations with them.

1
perhaps break your long return expression into multiple variables, and then operate on them – Devesh Kumar Singh
that could help to identify where the error is, but i guess it is because working with the complex numbers that gives me the error – Ernesto Lopez Fune
Yes breaking down the code will help you look which part of the long expression is throwing the error because honestly it’s unreadable mumbo jumbo for me now – Devesh Kumar Singh

1 Answers

0
votes

Use scipy.special.gamma() instead of math.gamma(). The latter does not support complex argument and complains that it cannot convert the complex to float.

Following @devesh-kumar-singh advice would help you find the problematic part of the long expression.

The code lacks definition of a0, and nh.gamma contains a typo.