Optimization involving dot and cross product of two unit length variables

조회 수: 2 (최근 30일)
Hi all,
I am trying to minimize the following function w.r.t. ,
, such that and
where are scalars and known. are known. the (.) and the(x) are the dot and cross products respectively.
Is there any way I could implement this using matlab?

채택된 답변

William Rose
William Rose 2021년 4월 2일
The function you want to minimze is below.
function y=AhmadsFunc(p)
%Ahmad Hamad's function to be minimized
s1=p(1:3); %extract s1 from p
s2=p(4:6); %extract s2 from p
j=1; %insert desired values for j,k,ahat,D,B
k=2;
ahat=[1,2,3];
D=[4,5,6];
B=[7,8,9];
y=-j*dot(s1,s2)-dot(D,cross(s1,s2))-k*(dot(ahat,s1))^2-dot(B,s1)-dot(B,s2);
end
p=[s1;s2] is a 6x1 vector containing s1 and s2.
The nonlinear constraint function is
function [c,ceq]=AhmadsConstraints(p)
%Nonlinear constraints for Ahmad's problem.
%There are no inequality constraints.
%The equality constraints should each equal zero.
c=-1; %inequality constraint, must be <=0
ceq(1)=p(1)^2+p(2)^2+p(3)^2-1; %||s1||=1
ceq(2)=p(4)^2+p(5)^2+p(6)^2-1; %||s2||=1
end
The main program, below, makes an initial guess for p0=[s10;s20]. It calls fmincon(). Pass to fmincon() the initial guess, and the functon to be minimzed, and the function that returns the nonlinear contraints. fmincon() returns the best-fit parameter values.
%AhmadsMain.m Ahmad Hamad & WCR
%Calls AhmadsFunc.m and AhmadsConstraints.m.
s10=[1;0;0]; s20=[0;1;0];
p0=[s10;s20];
p=fmincon(@AhmadsFunc,p0,[],[],[],[],[],[],@AhmadsConstraints);
fprintf('s1=%.3f,%.3f,%.3f, s2=%.3f,%.3f,%.3f\n',p);
fprintf('Length of s1=%.3f, length of s2=%.3f\n',norm(p(1:3)),norm(p(4:6)));
Here's the result I get.
>> AhmadsMain
Local minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in
feasible directions, to within the default value of the optimality tolerance,
and constraints are satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
s1=0.300,0.538,0.788, s2=0.521,0.484,0.703
Length of s1=1.000, length of s2=1.000
>>
You may get a different "best fit" if you change the initial guess, because fmincon() may find a local mimimum that is not a global minimum. Try different initial guesses, if this is a concern. I always do. I put the fitting routine inside a loop. I use a different initial guess on each pass. I save the fits from each pass and then, when the loop is done, I choose the best of them.

추가 답변 (1개)

Matt J
Matt J 2021년 4월 2일
Yes, with fmincon()

카테고리

Help CenterFile Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by