How to write matlab code for optimization of this equation ?
显示 更早的评论
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.
回答(1 个)
Walter Roberson
2017-10-9
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)
类别
在 帮助中心 和 File Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!