How can I solve an Optimization problem?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello. I have not used the optimization toolbox and I need your help. I have 3 functions that depends on λ, and an function μ that depends on the 3 previous functions (so μ also depends on λ). I need to find the minimum value of μ changing λ: how can I make it? what function should I consider? Thanks in advance.
syms lambda;
c= sqrt((-(d^2)*(cosd(psi)-1))/(1+cosd(fi-psi)+(lambda^2)*(1-cosd(fi-psi))));
a= lambda*c;
b= sqrt(((d^2)*(lambda^2)*(cosd(fi)-1)-1-cosd(fi))/((lambda^2)*(cosd(fi-psi)-1)-1-cosd(fi-psi)));
Mu_1= acosd(abs(((c^2)+(b^2)-((d-a)^2))/(2*b*c)));
댓글 수: 2
Abolfazl Chaman Motlagh
2021년 12월 13일
편집: Abolfazl Chaman Motlagh
2021년 12월 13일
does lambda has any bound ? like an interval? because acosd hence Mu_1 become imaginary in larg numbers.
can you provide simple value for d ?
답변 (2개)
Abolfazl Chaman Motlagh
2021년 12월 13일
you can use fmincon, this function minimize function in a constraint problem. but only constraint here is bounds of lambda. so other fields of function are empty ([]).
i use some sample number for needed variables.
d = 1;
psi = rand * 360;
fi = rand * 360;
c=@(lambda) (sqrt((-(d^2)*(cosd(psi)-1))/(1+cosd(fi-psi)+(lambda^2)*(1-cosd(fi-psi)))));
a=@(lambda) (lambda*c(lambda));
b=@(lambda) (sqrt(((d^2)*(lambda^2)*(cosd(fi)-1)-1-cosd(fi))/((lambda^2)*(cosd(fi-psi)-1)-1-cosd(fi-psi))));
Mu_1=@(lambda) (acosd(abs(((c(lambda)^2)+(b(lambda)^2)-((d-a(lambda))^2))/(2*b(lambda)*c(lambda)))));
[Lambda_star,fval,exitflag,output]=fmincon(@(x) Mu_1(x),1,[],[],[],[],0,1);
disp(Lambda_star)
use fmincon documentation if you need more options for better convergence.it seems it reach best answer in my case : (in my code the answer changes everytime because psi and fi are random)
x = 0:1e-3:1;
for i=1:numel(x)
y(i) = Mu_1(x(i));
end
plot(x,y)
댓글 수: 3
Abolfazl Chaman Motlagh
2021년 12월 13일
Yes it is. but are you sure you wrote the equations right? because it seems it is not what you're saying. lets plot the function over lambda:
d = 100;
psi = 30;
fi = 170;
c=@(lambda) (sqrt((-(d^2)*(cosd(psi)-1))/(1+cosd(fi-psi)+(lambda^2)*(1-cosd(fi-psi)))));
a=@(lambda) (lambda*c(lambda));
b=@(lambda) (sqrt(((d^2)*(lambda^2)*(cosd(fi)-1)-1-cosd(fi))/((lambda^2)*(cosd(fi-psi)-1)-1-cosd(fi-psi))));
Mu_1=@(lambda) (acosd(abs(((c(lambda)^2)+(b(lambda)^2)-((d-a(lambda))^2))/(2*b(lambda)*c(lambda)))));
x = 0:1e-5:1;
for i=1:numel(x)
y(i) = Mu_1(x(i));
end
plot(x,y)
Juan Barrientos
2021년 12월 13일
댓글 수: 3
Torsten
2021년 12월 14일
Be careful with the objective function if the expression inside acosd becomes greater than 1. fminsearch will most probably stop if complex numbers are encountered during the optimization.
참고 항목
카테고리
Help Center 및 File 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!