Running into issue using fsolve
Mostrar comentarios más antiguos
Trying to solve a problem while using fsolve and fmincon. I am getting correct values, but the solvers are running into a large amount of issues. Getting the following error message:
"Warning: Trust-region-dogleg algorithim of FSOLVE cannot handle non-square systems; using Levenberg-Marquardt algorithim instead."
and
"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."
Here is my code:
% solve the optimization problem here
options = optimoptions('fmincon','Algorithm','sqp'); % use SQP algorithm
A = []; % linear inequality constraints - NONE
b = []; % NONE
Aeq = []; % linear equality constraints - NONE
beq = []; % NONE
lb = [0.36, 0.05]; % lower bounds on x
ub = [0.44, 0.06]; % upper bounds on x
f=@(p)obj(p,yData);% objective function
nonlcon=[];
p0 = [0.4,0.055];% initial guess from previous problems
[p,fval,exitflag,output,lambda] = fmincon(f,p0,A,b,Aeq,beq,lb,ub,nonlcon,options);
idata = length(yData);
yModel = zeros(idata,1);
for i = 1:idata
F1 = yData(i,1);
x = [0.33; yData(i,2); 0.33; F1];
x = fsolve(@(x)model(x, F1, p),x);
yModel(i) = x(2);
end
function f = obj(p,yData)
% implement your objective function here - using least-squares method
% p are uncertain model parameters (optimization variables)
% yData is the matrix of experimental data (inputs & outputs)
idata = length(yData);
yModel = zeros(idata,1);
options2 = optimoptions(@fsolve,'Display','off');
for i = 1:idata
F1 = yData(i,1);
x0 = [0.33; 0.33; 0.33; F1];
in = @(x)model(x, F1, p);
out = fsolve(in, x0, options2);
yModel(i) = out(2);
end
f = norm(yData(:,2) - yModel)^2;
end
function h = model(x, F1, p)
% Implement the constraints that define the model
k1 = p(1);
k2 = p(2);
Va = 0.08937;
Vb = 0.1018;
Vc = 0.113;
Ya0 = 1;
Yb0 = 0;
Yc0 = 0;
V = 10;
r1 = (k1*x(1))/(x(1)*Va + x(2)*Vb + x(3)*Vc);
r2 = (k2*x(2))/(x(1)*Va + x(2)*Vb + x(3)*Vc);
h = zeros(1:4);
h(1) = x(1)*x(4) + V*r1 - F1;
h(2) = x(2)*x(4) + V*(r2 - r1);
h(3) = x(3)*x(4) - V*r2;
h(4) = x(1) + x(2) + x(3) - 1;
end
Any help is greatly appreciated!
1 comentario
Justyn Welsh
el 8 de Mzo. de 2024
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Solver Outputs and Iterative Display en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!