I want to find the minimum output of the function, as shown below, which contains 4 variables (bolded & emphasised), also with multiple constraints.
(width * length * t_base * rho) + (n_fin * t_fin * length * h_fin * rho)
Two constraints are function of variables such that the function output is less than the certain value.
Other constraints are that the varialbes should be strictly positive as these values are physical parameters (length etc.)
I was trying to use scipy.optimize.minimize module to solve this problem but I stuck at setting multiple constraints in the code.
def objective(w, l, n_f, h_f):
return (w * l * t_base * rho_cp) + (n_f * t_fin * l * h_f * rho_cp)
const_T = dict(type='eq', fun=lambda w, l, n_f, h_f: 333 - (310 + (151.73 * l * ((w / (n_f - 1)) * 39.3701) / ((n_f - 1) * (h_f * 39.3701)))) #First constraint function with variables
const_P = dict(type='eq', fun=lambda w, l, n_f, h_f: 3.04 - (0.914 * (461.42 / n_f) / (w / n_f * 39.3701 * h_f * 39.3701 * l * 0.001))) #Second constraint function with variables
x0 = np.array([width, length, n_fin, h_fin])
res = optimize.minimize(objective, constraints=[const_T, const_P], x0=x0)
Note that other variables beside w, l, n_f and h_f are known and treated as constant in the calculation.
But I got error in the code stated as "Expected type 'dict | None', got 'list[dict[str, str | (w: Any, l: Any, n_f: Any, h_f: Any) -> float | Any] | dict[str, str | (w: Any, l: Any, n_f: Any, h_f: Any) -> float | Any]]' instead"
Also, I got error message when I try to run the code just with one constraint: TypeError: cold_plate_optimize..() missing 3 required positional arguments: 'l', 'n_f', and 'h_f'
I am wondering whether scipy.optimize.minimize module is appropriate approach to solve such problem.
If not, it would be really appreciated if anyone can guide me better method on solving this problem.
Thank you very much in advance.
Edit1: Sorry, I have simplified the constraint functions that contain variables. Frankly speaking, the constraint function doesn't have to be the function written above, as I just want to know how to set multiple constraints which are the function of multiple variables.