Too many output arguments while solving a constrained optimization problem.

Hello,
I'm trying to solve a optimization problem with a couple of non-linear constraints. When solving the problem I get the following error:
Error using writeCompiledFun2VirtualFile
Too many output arguments.
I tried different constraints and functions and I noticed that the error appears whenever I use multiplication and/or division with two optimvars. This might be due ot optimvar only supporting ./ and .* . However, replacing / and * with ./ and .* did not solve the problem.
You can find my code attached.
optimisation
OptimizationProblem : Solve for: K_eq, m_eq, x_max minimize : -(((1.822 - (K_eq .* x_max)) ./ m_eq) .* x_max).^0.5 variable bounds: 0 <= x_max <= 0.0064 Solving problem using fmincon.
Error using optim.problemdef.OptimizationProblem/solve
SOLVE requires a non-empty initial point structure to solve a nonlinear problem.

Error in optimisation (line 103)
prob.solve()
Thanks in advance

2 件のコメント

Cris LaPierre
Cris LaPierre 2021 年 5 月 8 日
編集済み: Cris LaPierre 2021 年 5 月 8 日
I modified your post to run your m file. It returns a different error. It's the same error I get if I run your m-file in R2019b.
Michael Christian Linder
Michael Christian Linder 2021 年 5 月 8 日
Hmm I just downloaded my code and run it again. I still get the "too many output vairables" error. I then run the code on a virtual machine (with R2018a) I have access too which resulted in the error:
Error using optim.internal.problemdef.Times.getTimesOperator
At least one argument must be numeric.
Error in *
Error in optimisation (line 37)
K_eq == J_p / (l_l2*l_l2) + (l_l1/l_l2)*(l_l1/l_l2) * J_m,
This error makes more sens. But replacing * with .* doesn't solve the problem (same error)

サインインしてコメントする。

 採用された回答

Matt J
Matt J 2021 年 5 月 8 日
編集済み: Matt J 2021 年 5 月 8 日

0 投票

You are reporting multiple different errors in multiple different places from multiple different Matlab versions, so it is a little hard to parse your question. Basically, though, in earlier version of Matlab, the problem-based framework was limited in scope to linear programming. Non-linear OptimizationVariables expressions were simply not supported. As I demonstrated in my other answer, the code runs fine on more recent Matlab versions, once you supply an initial guess. If you cannot upgrade to a more recent version, however, you will have to resort to the Optimization Toolbox's solver-based optimization tools.

1 件のコメント

Michael Christian Linder
Michael Christian Linder 2021 年 5 月 9 日
Thanks. I wasn't aware of those differences between the versions. Updating to 2021a solved the problem.

サインインしてコメントする。

その他の回答 (1 件)

Matt J
Matt J 2021 年 5 月 8 日
編集済み: Matt J 2021 年 5 月 8 日
I get no problem in R2020b once the last line is modified to,
prob.solve(x0)

1 件のコメント

Matt J
Matt J 2021 年 5 月 8 日
編集済み: Matt J 2021 年 5 月 8 日
The Matlab Online engine doesn't seem to have any problem either (R2021a).
optimisation
OptimizationProblem : Solve for: K_eq, m_eq, x_max minimize : -(((1.822 - (K_eq .* x_max)) ./ m_eq) .* x_max).^0.5 variable bounds: 0 <= x_max <= 0.0064 Solving problem using fmincon. Local minimum possible. Constraints satisfied. fmincon stopped because the size of the current step is less than the value of the step size tolerance and constraints are satisfied to within the value of the constraint tolerance.
ans = struct with fields:
K_eq: 4.0684e-06 m_eq: 1.5679e-11 x_max: 4.1737e-04

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeGet Started with Optimization Toolbox についてさらに検索

製品

リリース

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by