[error] - Error "Your objective function must return a scalar value.''

Hello everyone, I run my code and got this error " Failure in initial user-supplied objective function evaluation." I don't know how to solve it. Hope you can help me, Thank
function y=annealing(x,C,P,T,R)
y=log(x(1))+x(2)*log(C-0.15)+x(3)*log(P)-x(4)*log(T)-log(R/273);
>> a=xlsread('hydrogen.xlsx');
C=a(:,1);
P=a(:,2);
T=a(:,3);
R=a(:,4);
ObjectiveFunction = @(x) annealing(x,C,P,T,R);
x0 = [0.5 0.5 0.5 0.5]; % Starting point
[x,fval] = simulannealbnd(ObjectiveFunction,x0)
This is error: Error using samakedata (line 29) Your objective function must return a scalar value.
Error in simulannealcommon (line 118) solverData = samakedata(solverData,problem,options);
Error in simulanneal (line 44) simulannealcommon(FUN,x0,Aineq, bineq, Aeq, beq, lb, ub,options,defaultopt);
Error in simulannealbnd (line 137) [x, fval, exitflag, output] = simulanneal(FUN, x0, [], [], [], [], lb, ub, options);

9 件のコメント

KSSV
KSSV 2016 年 10 月 21 日
You have showed errors...which function you want us to see?
viet le
viet le 2016 年 10 月 21 日
I've already fixed my question. Thank for your time.
KSSV
KSSV 2016 年 10 月 21 日
ObjectiveFunction = @(x) annealing(x,C,P,T,R); ?????
simply try:
ObjectiveFunction = annealing(x,C,P,T,R);
viet le
viet le 2016 年 10 月 21 日
it is still not working
Undefined function or variable 'x'.
KSSV
KSSV 2016 年 10 月 21 日
Define the value of x.
a=xlsread('hydrogen.xlsx');
C=a(:,1);
P=a(:,2);
T=a(:,3);
R=a(:,4);
ObjectiveFunction = annealing(x,C,P,T,R);
Torsten
Torsten 2016 年 10 月 21 日
Your function "annealing" must return a single (scalar) value. At the moment - since C,P,T and R are vectors - it returns a vector.
The other settings in your original post are ok. Don't change to
ObjectiveFunction = annealing(x,C,P,T,R);
Best wishes
Torsten.
viet le
viet le 2016 年 10 月 21 日
it is result, Dr.Siva
viet le
viet le 2016 年 10 月 21 日
Hello Torsten , But if I keep the original, it could not run. Could you give me some solution? Thanks.
Torsten
Torsten 2016 年 10 月 21 日
編集済み: Torsten 2016 年 10 月 21 日
I can't give advise since I don't know which value you are trying to minimize in your function "annealing". You can imagine that it doesn't make sense to minimize several values simultaneously (i.e. return a vector for y as you do).
Best wishes
Torsten.

サインインしてコメントする。

回答 (0 件)

カテゴリ

タグ

質問済み:

2016 年 10 月 21 日

編集済み:

2016 年 10 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by