# TypeError: 'float' object is not subscriptable scipy minimize

I am trying to minimize the function using the constrains and bounds as below, however after running it I am getting error:

TypeError: 'float' object is not subscriptable.


Can you tell me how to avoid it?

I am also not sure if I am doing well with using the main function as a integrate.

import numpy as np
from scipy.optimize import minimize
import matplotlib.pyplot as plt
import sympy as sp
import math

# obj funtion
def f(x):
l = sp.Symbol('l')
Ep = 45000
Gc = 1
F = 1080
ep = x[0]
ec = x[1]
return (((F ** 2 * (l - x)) / (Ep * ec * l * (ec + ep) ** 2)) + (F ** 2) / (2 * (ec + 2 * ec) * Gc * l)) / 100

# constrain 1 - mass

def constrain1(x):
pc = 4.5 * 10 ** (-5)
pp = 2.1 * 10 ** (-3)
V = 3.1 * 10 ** 7
ep = x[0]
ec = x[1]
return ((((pp * V * ((2 * ep + ec) / 50) * ep) / (ec + 2 * ep)) + (
(pc * V * ((2 * ep + ec) / 50) * ec) / (ec + 2 * ep))) / 1000) - 4.5

def constrain2(x):
ep = x[0]
ec = x[1]
return (3.13107 * 10 ** 3) * ep * np.sqrt(ep / ec) - 1080

# initial guesses
x_init = [2, 50]

# bounds

b1 = (0, 3)
b2 = (30, 70)
bnds = (b1, b2)
con1 = {'type': 'ineq', 'fun': constrain1}
con2 = {'type': 'ineq', 'fun': constrain2}
cons = [con1, con2]

sol = minimize(mainf,x0=x_init,method='SLSQP',bounds=bnds,constraints=cons)