adding constaints to fmincon code

1 Ansicht (letzte 30 Tage)
fima v
fima v am 11 Feb. 2022
Beantwortet: Steven Lord am 11 Feb. 2022
hello,i have wrote the following code for optimization.
how do i add the following constraints that my fmincon will run so that
0.5<p(1)<1
0.7<p(2)<0.8
0.5<p(3)<0.9
Thanks
clear all; close all; clc
xm = [18.3447,79.86538,85.09788,10.5211,44.4556, ...
69.567,8.960,86.197,66.857,16.875, ...
52.2697,93.917,24.35,5.118,25.126, ...
34.037,61.4445,42.704,39.531,29.988];
ym = [5.072,7.1588,7.263,4.255,6.282, ...
6.9118,4.044,7.2595,6.898,4.8744, ...
6.5179,7.3434,5.4316,3.38,5.464, ...
5.90,6.80,6.193,6.070,5.737];
p0 = [1,1,1];
yp = @(p) p(1) + p(2)./xm + p(3).*log(xm);
objective = @(p) sum(((yp(p)-ym)./ym).^2);
popt = fmincon(objective,p0);
plot(xm,yp(p0),'bx')
hold on
plot(xm,ym,'ro')
plot(xm,yp(popt),'gs')

Akzeptierte Antwort

Steven Lord
Steven Lord am 11 Feb. 2022
See the description of the lb and ub input arguments and the "Minimize with Bound Constraints" example on the documentation page for fmincon

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by