sin(y) results in “can’t convert expression to float” error

Your problem lies in this line:

bounds = [abs(round(float(solve(lowerProfile)[0]),5)),

Specifically this part:


Here the solve() function returns complex solutions in a list. See this:

[1.5707963267949 - 1.04696791500319*I, 1.5707963267949 + 1.04696791500319*I]

So, when you pick the 0 index it will be a complex result like this one:

1.5707963267949 - 1.04696791500319*I

So, you are trying to cast float() to this solution which results in error. Instead you can remove the bounds for solutions having complex results by using try-except block like this:

  bounds = [abs(round(float(solve(lowerProfile)[0]),5)),
  lowerBound = np.amin(bounds)
  upperBound = np.amax(bounds)
  print("The solutions are complex. Cant find a result")

Also import like this:

from vpython import *
from scipy.optimize import fsolve
import math
import numpy as np
import sympy as sp
from sympy import *
import matplotlib.pyplot as plt

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top