abs cannot be used in problem-based optimization expression

5 ビュー (過去 30 日間)
Bruno Luong
Bruno Luong 2023 年 7 月 29 日
コメント済み: Bruno Luong 2023 年 7 月 29 日
Can someone tell me why I cannot use abs() in this simple setup.
prob = optimproblem();
x = optimvar('x',1,1);
y = 1;
x0 = struct('x',0);
prob.Objective = abs(x-y); % sum(abs(x-y)) also doesn't work
Incorrect number or types of inputs or outputs for function 'abs'.
%prob.Objective = norm(x-y,1); % this however works
sol = solve(prob,x0)
If I use prob.Objective = norm(x-y,1) it wokks just fine

採用された回答

Bruno Luong
Bruno Luong 2023 年 7 月 29 日
  2 件のコメント
Torsten
Torsten 2023 年 7 月 29 日
sqrt((x-y).^2) doesn't seem to work, either.
Bruno Luong
Bruno Luong 2023 年 7 月 29 日
Syntaxically it works, but I have to add a small margin to avoid singularity of the derivative at 0
prob = optimproblem();
x = optimvar('x',1,1);
y = 1;
x0 = struct('x',0);
prob.Objective = sqrt((x-y).^2+eps); % sum(abs(x-y)) also doesn't work
sol = solve(prob,x0)
Solving problem using fminunc. Local minimum found. Optimization completed because the size of the gradient is less than the value of the optimality tolerance.
sol = struct with fields:
x: 1

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with Problem-Based Optimization and Equations についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by