Can I use if statement in constraint function for optimization ?

2 ビュー (過去 30 日間)
siddhesh rane
siddhesh rane 2017 年 10 月 30 日
コメント済み: Weihan Lin 2021 年 8 月 27 日
I have a constraint functions which call another function(inverse_kinematics) for calculating some of the constraints, inverse_kinematics() will give error if c(1) and c(2) are not satisfied, how can I ensure that c(1) and c(2) are satisfied before calling inverse_kinematics() function? Can I address it by using if condition in my constraint function? Below is code of my optimizatio0n function,
function [c, ceq] = simple_constraint(l1,l2,l3)
c(1) = l3^2 + 200*l3*cos(30) + 10000 - (l1 + l2)^2;
c(2) = (100- l3*cos(30))^2 + (100*sin(30))^2 - (l1-l2)^2;
thetas = inverse_kinematics(l1,l2,l3);
c(3) = thetas(4,1) - 160;
c(4) = thetas(4,2) - 160;
c(5) = thetas(4,3) - 160;
c(6) = 20 - thetas(4,1);
c(7) = 20 - thetas(4,2);
c(8) = 20 - thetas(4,3);
c(9) = thetas(5,1) - 340;
c(10) = thetas(5,2) - 340;
c(11) = thetas(5,3) - 340;
c(12) = 200 - thetas(5,1);
c(13) = 200 - thetas(5,2);
c(14) = 200 - thetas(5,3);
c(15) = thetas(6,1) - 340;
c(16) = thetas(6,2) - 340;
c(17) = thetas(6,3) - 340;
c(18) = 200 - thetas(6,1);
c(19) = 200 - thetas(6,2);
c(20) = 200 - thetas(6,3);
ceq = [];
end
Thanks in advance !
  1 件のコメント
Weihan Lin
Weihan Lin 2021 年 8 月 27 日
Did you find the solution for it?

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeSurrogate Optimization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by