# Issues with numerically integrating a complex value function. Any way of getting around the 'Unable to convert 5.0 + 1.0*I to float; use abs() or real_part() as desired' error?

x = var('x') a = 5.0 + I
b = 3.0 + I
numerical_integral((1/sqrt(x^3 + a*x + b)).real(), 0, 3)

edit retag close merge delete

Sort by » oldest newest most voted

When you write 1/sqrt(x^3 + a*x + b), you define a symbolic function. In particular:

sage: (1/sqrt(x^3 + a*x + b)).real()
cos(-1/2*arctan2(-imag_part(x)^3 + 3*imag_part(x)*real_part(x)^2 + 5.00000000000000*imag_part(x) + 1.00000000000000*real_part(x) + 1.00000000000000, -3*imag_part(x)^2*real_part(x) + real_part(x)^3 - 1.00000000000000*imag_part(x) + 5.00000000000000*real_part(x) + 3.00000000000000))/sqrt(abs(x^3 + (5.00000000000000 + 1.00000000000000*I)*x + 3.00000000000000 + 1.00000000000000*I))


Since you are looking for numerical integral, you should instead define a Python function:

sage: f = lambda x : (1/sqrt(x^3 + a*x + b)).real_part()
sage: numerical_integral(f, 0, 3)
(0.8675472324763669, 9.631709124450959e-15)

more