How can I solve an Optimization problem?

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 comentarios

Abolfazl Chaman Motlagh
Abolfazl Chaman Motlagh el 13 de Dic. de 2021
Editada: Abolfazl Chaman Motlagh el 13 de Dic. de 2021
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 ?
Juan Barrientos
Juan Barrientos el 13 de Dic. de 2021
Yes, d is the input. So is fi and psi. And the interval is between 0 and 1 for lambda.

Iniciar sesión para comentar.

Respuestas (2)

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);
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.
disp(Lambda_star)
0.1605
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 comentarios

Juan Barrientos
Juan Barrientos el 13 de Dic. de 2021
But I don't understand, Lambda_star is the value for lambda that makes the Mu the minimum? because I used d=100, psi= 30 and fi=170 because I know lambda for this case is 0.346 and Mu is 77.17, but I don't get it with this code.
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)
Warning: Imaginary parts of complex X and/or Y arguments ignored.
Juan Barrientos
Juan Barrientos el 13 de Dic. de 2021
Hmmm yes I'm sure, because I already know the solution of the problem, just don't know how to code. the solution is
c= 54.85
b= 75.34
a= 18.98
with lambda= 0.346 and if I solve the equations the answers in the program are these. But I don't really know how to use fmincon or quadprog for this.

Iniciar sesión para comentar.

Juan Barrientos
Juan Barrientos el 13 de Dic. de 2021

0 votos

So to be clear these are the equations. φ, ψ and d are parameters, so the problem is to know which value of λ makes the smaller μ.

3 comentarios

Torsten
Torsten el 13 de Dic. de 2021
For lambda = 1, I get mu = 8.4711 which is smaller than your mu = 77.17.
Or do you try to maximize mu instead of minimizing as you wrote ?
Yes maximize, but I said minimize because I think the software minimizes, so to maximize you have to multiply by (-1); that was my mistake But I already solve it. I used the function fminsearch to find the value for λ; I show you the code I used:
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_2= @(lambda) -(acosd(abs(((c(lambda)^2)+(b(lambda)^2)-((d+a(lambda))^2))/(2*b(lambda)*c(lambda)))));
min_2= abs(Mu_2(abs(lambdaMin2)));
I had to use Abs to solve for the maximum. Thank you very much for your responses, they helped me a lot.
Torsten
Torsten el 14 de Dic. de 2021
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.

Iniciar sesión para comentar.

Productos

Versión

R2021a

Etiquetas

Preguntada:

el 13 de Dic. de 2021

Comentada:

el 14 de Dic. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by