An optimization with fmincon
Hello everyone, sorry for the inconvenience. I would have a problem with the optimization via the fmincon function. I wanted to ask, kindly, if anyone could help me. I need to get 3 parameters (x1, x2, x3 = 0.4242 0.2928 0.2830; max = 319). Thanks to who will answer me. Good day.
%% FITTING MODEL
%———————————————–
clc, clear
global x1s x2s x3s rs
global betax
data = [100 0 0 265
0 100 0 170
0 0 100 119
50 50 0 252
50 0 50 247
0 50 50 222
66.67 16.67 16.67 310
16.67 66.67 16.67 244
16.67 16.67 66.67 239
33.33 33.33 33.33 322
100 0 0 257
0 100 0 181
0 0 100 127];
x1s = data(:,1)/100; % values of x1
x2s = data(:,2)/100; % values of x2
x3s = data(:,3)/100; % values of x1
rs = data(:,4); % values of residual
% function
beta0 = [62.8 173.1 122.6 131.0 228.2 274.2 1597.9];
beta=lsqnonlin(‘funzione’,beta0);
for j=1:length(rs)
rc(j)= modello(x1s(j),x2s(j),x3s(j));
res(j) = rc(j) – rs(j);
end
%% data calculation
betax = beta;
ndat=10000;
for j=1:ndat
x1c(j) = rand(1,1);
x2c(j) = rand(1,1)*(1-x1c(j));
x3c(j) = 1-x1c(j)-x2c(j);
risp(j) = modello(x1c(j),x2c(j),x3c(j));
end
%% diagram
figure(1);
% plot of data
% colour
% test surface response
colormap (jet)
[hg,htick,hcb] = tersurf(x1c,x2c,x3c,risp);
% axes label
hlabels = terlabel(‘x1′,’x2′,’x3’);
%% experiment
figure(2)
%– Plot axis
[h,hg,htick] = terplot;
%– Plot data
hter = ternaryc(x1s,x2s,x3s);
set(hter,’marker’,’o’,’markerfacecolor’,’blue’,’markersize’,’8′)
hlabels = terlabel(‘x1′,’x2′,’x3’);
%% residual plot
figure(3)
plot(x1s,res,’ro’)
xlabel(‘x1’)
ylabel(‘residui’)
grid
%% NORMAL PROBABILITY GRAPH
figure(4)
res_sort = sort(res);
for j = 1:length(res)
xj(j) = j/(length(res)-1);
end
semilogy(res_sort,xj,’ko’)
grid
%% SEARCH FOR THE MINIMUM
x0 = [0.3 0.3 0.3]; % punto centrale
lb = [0 0 0]; % limite inferiore
ub = [1 1 1]; % limite superiore
Aeq = [1 1 1];
beq = 1;
y = fmincon(‘funz’,x0,[],[],Aeq,beq,lb,ub)
modello(xmax(1),xmax(2),xmax(3))
function [z] = funz (x1s,x2s,x3s)
global x1s x2s x3s
z = 62.8.*x1s+173.1.*x2s+122.6.*x3s+131.0.*x1s*x2s+228.2.*x1s*x3s+274.2.*x2s*x3s+1597.9.*x1s*x2s*x3s;
endHello everyone, sorry for the inconvenience. I would have a problem with the optimization via the fmincon function. I wanted to ask, kindly, if anyone could help me. I need to get 3 parameters (x1, x2, x3 = 0.4242 0.2928 0.2830; max = 319). Thanks to who will answer me. Good day.
%% FITTING MODEL
%———————————————–
clc, clear
global x1s x2s x3s rs
global betax
data = [100 0 0 265
0 100 0 170
0 0 100 119
50 50 0 252
50 0 50 247
0 50 50 222
66.67 16.67 16.67 310
16.67 66.67 16.67 244
16.67 16.67 66.67 239
33.33 33.33 33.33 322
100 0 0 257
0 100 0 181
0 0 100 127];
x1s = data(:,1)/100; % values of x1
x2s = data(:,2)/100; % values of x2
x3s = data(:,3)/100; % values of x1
rs = data(:,4); % values of residual
% function
beta0 = [62.8 173.1 122.6 131.0 228.2 274.2 1597.9];
beta=lsqnonlin(‘funzione’,beta0);
for j=1:length(rs)
rc(j)= modello(x1s(j),x2s(j),x3s(j));
res(j) = rc(j) – rs(j);
end
%% data calculation
betax = beta;
ndat=10000;
for j=1:ndat
x1c(j) = rand(1,1);
x2c(j) = rand(1,1)*(1-x1c(j));
x3c(j) = 1-x1c(j)-x2c(j);
risp(j) = modello(x1c(j),x2c(j),x3c(j));
end
%% diagram
figure(1);
% plot of data
% colour
% test surface response
colormap (jet)
[hg,htick,hcb] = tersurf(x1c,x2c,x3c,risp);
% axes label
hlabels = terlabel(‘x1′,’x2′,’x3’);
%% experiment
figure(2)
%– Plot axis
[h,hg,htick] = terplot;
%– Plot data
hter = ternaryc(x1s,x2s,x3s);
set(hter,’marker’,’o’,’markerfacecolor’,’blue’,’markersize’,’8′)
hlabels = terlabel(‘x1′,’x2′,’x3’);
%% residual plot
figure(3)
plot(x1s,res,’ro’)
xlabel(‘x1’)
ylabel(‘residui’)
grid
%% NORMAL PROBABILITY GRAPH
figure(4)
res_sort = sort(res);
for j = 1:length(res)
xj(j) = j/(length(res)-1);
end
semilogy(res_sort,xj,’ko’)
grid
%% SEARCH FOR THE MINIMUM
x0 = [0.3 0.3 0.3]; % punto centrale
lb = [0 0 0]; % limite inferiore
ub = [1 1 1]; % limite superiore
Aeq = [1 1 1];
beq = 1;
y = fmincon(‘funz’,x0,[],[],Aeq,beq,lb,ub)
modello(xmax(1),xmax(2),xmax(3))
function [z] = funz (x1s,x2s,x3s)
global x1s x2s x3s
z = 62.8.*x1s+173.1.*x2s+122.6.*x3s+131.0.*x1s*x2s+228.2.*x1s*x3s+274.2.*x2s*x3s+1597.9.*x1s*x2s*x3s;
end Hello everyone, sorry for the inconvenience. I would have a problem with the optimization via the fmincon function. I wanted to ask, kindly, if anyone could help me. I need to get 3 parameters (x1, x2, x3 = 0.4242 0.2928 0.2830; max = 319). Thanks to who will answer me. Good day.
%% FITTING MODEL
%———————————————–
clc, clear
global x1s x2s x3s rs
global betax
data = [100 0 0 265
0 100 0 170
0 0 100 119
50 50 0 252
50 0 50 247
0 50 50 222
66.67 16.67 16.67 310
16.67 66.67 16.67 244
16.67 16.67 66.67 239
33.33 33.33 33.33 322
100 0 0 257
0 100 0 181
0 0 100 127];
x1s = data(:,1)/100; % values of x1
x2s = data(:,2)/100; % values of x2
x3s = data(:,3)/100; % values of x1
rs = data(:,4); % values of residual
% function
beta0 = [62.8 173.1 122.6 131.0 228.2 274.2 1597.9];
beta=lsqnonlin(‘funzione’,beta0);
for j=1:length(rs)
rc(j)= modello(x1s(j),x2s(j),x3s(j));
res(j) = rc(j) – rs(j);
end
%% data calculation
betax = beta;
ndat=10000;
for j=1:ndat
x1c(j) = rand(1,1);
x2c(j) = rand(1,1)*(1-x1c(j));
x3c(j) = 1-x1c(j)-x2c(j);
risp(j) = modello(x1c(j),x2c(j),x3c(j));
end
%% diagram
figure(1);
% plot of data
% colour
% test surface response
colormap (jet)
[hg,htick,hcb] = tersurf(x1c,x2c,x3c,risp);
% axes label
hlabels = terlabel(‘x1′,’x2′,’x3’);
%% experiment
figure(2)
%– Plot axis
[h,hg,htick] = terplot;
%– Plot data
hter = ternaryc(x1s,x2s,x3s);
set(hter,’marker’,’o’,’markerfacecolor’,’blue’,’markersize’,’8′)
hlabels = terlabel(‘x1′,’x2′,’x3’);
%% residual plot
figure(3)
plot(x1s,res,’ro’)
xlabel(‘x1’)
ylabel(‘residui’)
grid
%% NORMAL PROBABILITY GRAPH
figure(4)
res_sort = sort(res);
for j = 1:length(res)
xj(j) = j/(length(res)-1);
end
semilogy(res_sort,xj,’ko’)
grid
%% SEARCH FOR THE MINIMUM
x0 = [0.3 0.3 0.3]; % punto centrale
lb = [0 0 0]; % limite inferiore
ub = [1 1 1]; % limite superiore
Aeq = [1 1 1];
beq = 1;
y = fmincon(‘funz’,x0,[],[],Aeq,beq,lb,ub)
modello(xmax(1),xmax(2),xmax(3))
function [z] = funz (x1s,x2s,x3s)
global x1s x2s x3s
z = 62.8.*x1s+173.1.*x2s+122.6.*x3s+131.0.*x1s*x2s+228.2.*x1s*x3s+274.2.*x2s*x3s+1597.9.*x1s*x2s*x3s;
end help fmincon, help-fmincon MATLAB Answers — New Questions