How to write matlab code for optimization of this equation ?
Show older comments
Hello, I want to optimize the following equation with particle swarm optimization algorithm.
margin(d)=-13.4-(8.686.*((d/0.5).^2))+30 ;
where range of d is (0.1, 3) and range of margin is (6,20). Need optimum margin with optimum value of d within those boundary value.
Answers (1)
Walter Roberson
on 9 Oct 2017
margin = @(d) -13.4-(8.686.*((d/0.5).^2))+30;
A = []; b = [];
Aeq = []; beq = [];
lb = 0.1; ub = 3;
mlb = 6; mub = 20;
nonlcon = @(d) deal([mlb - margin(d), margin(d)-mub], []);
d_min_margin = ga(margin, 1, A, b, Aeq, beq, lb, ub, nonlcon);
d_max_margin = ga(@(d) -margin(d), 1, A, b, Aeq, beq, lb, ub, nonlcon);
It was not clear from your "optimum" whether you were looking to minimize or maximize, so I show both.
However, there is really no point in using genetic algorithms for this function. The function is quadratic, so you can solve directly. Expand the function and you will find it is 16.6 - 34.744*d^2 . So you can
t = roots([-34.744, 0, 16.6-mlb]);
t(imag(g) == 0 & t>0)
to solve for the exact point at which margin(d) = mlb, and the location of the 0 is going to be sqrt(16.6/34.744)
Categories
Find more on Systems of Nonlinear Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!