ERROR: FMINCON requires all values returned by functions to be of data type double.

3 次查看(过去 30 天)
This is the main running code, once started will always report this error.
Func is my object function.
Func = @(x) WW_Period_Sum(x);
options = optimoptions('fmincon','Display','iter');
nonlcon = [];%@myConstraintFunction;
a = fmincon(Func, x0, [], [], [], [], [], [], nonlcon, options);%x0 is already assigned.
Unrecognized function or variable 'x0'.
I have this nonlcon function. ce and ceq are all array of cells about x
function [ce, ceq] = myConstraintFunction(x)
ce = @(x) ineq_temp;
ceq = @(x) eq_temp;
end
H is a matrix, and I'm trying to find its Condition Number.
function cond_value = calcCond(x,t);
cond_value = @(x,t) cond(H);
end
Sum of all values within 0.01s.
function WW_period = WW_Period_Sum (x);
WW_period_=@(x) 0;
for t=0:0.002:0.01
cond_temp = @(x) calcCond(x, t);
WW_period_ = @(x) WW_period_(x) + cond_temp(x);
end
WW_period = WW_period_;
end
And Keep reporting errors "Error using fmincon (line 19)
FMINCON requires all values returned by functions to be of data type double."
Thanks for giving me a lift to the station.!!!

回答(1 个)

Walter Roberson
Walter Roberson 2023-11-16
WW_period_=@(x) 0;
You are returning a function handle. You need to return a scalar numeric value instead.

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by