Fmincon - error using barrier
Show older comments
Hi,
I have a minimisation problem that I am trying to solve using matlab. I am pretty new to the general optimization toolbox and I dont fully understand all of the functions in it, such as the barrier function. I am getting the following error:
Error using barrier
Objective function is undefined at initial point. Fmincon cannot continue.
Error in fmincon (line 861)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] = barrier(funfcn,X,A,B,Aeq,Beq,l,u,confcn,options.HessFcn, ...
Error in main (line 43)
[x,fvals] = fmincon(obj,nvars,[],[],[],[],LB,UB,@constraint);
From what I understand the error is coming from the fact that my objective function is non-real at the starting postion, but I tried fixing it by making obj real using real(obj), and yet it doesnt work.
My code is as follows:
%% Parameters
l_0 = 3;
R = 5;
r=0.15*R:0.0425*R:R;
aoa = 15; %need to make a matrix out of this for the baseline blade
x = [4 5];
nvars = [2 3];
LB = [1 1];
UB = [5 6];
%% Constraint
function[c,ceq] = constraint(x,F,l_i)
l_i = 4;
F = 2;
c = (x(1)^2) * F + x(2) * l_i.^2 - x(2) * x(1) * l_i.^2 - x(1);
ceq = [];
end
%% Loop
k = 0;
for i = 1:length(r)
l_i = (l_0 * r(i)) / R;
% disp(l_i)
phi = atan(((1 - x(1)) / (1 + x(2))) * (1/l_i(i)));
% disp(phi)
f = B / 2 * ((R - r(i)) / (R * sin(phi(i))));
% disp(f)
F = 2 / pi * acos(exp(1).^(-f(i)));
% disp(F)
twist_angle = phi(i) - aoa(i);
% disp(twist_angle)
obj = @(x)(8/((l_i).^2))*x(2)*(x(1)-1)*F*(l_i).^3;
% disp(obj)
[x,fvals] = fmincon(obj,nvars,[],[],[],[],LB,UB,@constraint);
k = k+1;
end
Any help would be greatly appreciated.
1 Comment
Reorganizing and running your code below leads to an error because B has not been provided.
%% Parameters
l_0 = 3;
R = 5;
r=0.15*R:0.0425*R:R;
aoa = 15; %need to make a matrix out of this for the baseline blade
x = [4 5];
nvars = [2 3];
LB = [1 1];
UB = [5 6];
%% Loop
k = 0;
for i = 1:length(r)
l_i = (l_0 * r(i)) / R;
% disp(l_i)
phi = atan(((1 - x(1)) / (1 + x(2))) * (1/l_i(i)));
% disp(phi)
f = B / 2 * ((R - r(i)) / (R * sin(phi(i))));
% disp(f)
F = 2 / pi * acos(exp(1).^(-f(i)));
% disp(F)
twist_angle = phi(i) - aoa(i);
% disp(twist_angle)
obj = @(x)(8/((l_i).^2))*x(2)*(x(1)-1)*F*(l_i).^3;
% disp(obj)
[x,fvals] = fmincon(obj,nvars,[],[],[],[],LB,UB,@constraint);
k = k+1;
end
%% Constraint
function[c,ceq] = constraint(x,F,l_i)
l_i = 4;
F = 2;
c = (x(1)^2) * F + x(2) * l_i.^2 - x(2) * x(1) * l_i.^2 - x(1);
ceq = [];
end
Answers (0)
Categories
Find more on Surrogate Optimization 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!