I am trying to minimize the function ARE in file abc.m. But I m getting the error "your objective function must return a scalar value", I know that I minimizing this function with a variable which is not constant. It works when I take any single val
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
========================================= mytest.m file ========================================= close all; clear all; clc;
a0 = [.0001 .0001 .0001 .0001 .0001 ]
f =@(a)abc(a);
[a fval] = simulannealbnd(f,a0);
disp(a); ===============================================
second file =============================================== abc.m ===============================================
function ARE = abc(a) ;
w = linspace(0,pi,1000)
ARE = ((1/(j*w)) - ((a(1)*exp(2*j*w) + a(2)*exp(j*w) + a(3)) / (exp(2*j*w)+a(4)*exp(j*w) + a(5)))/(1/(j*w)));
0 Kommentare
Antworten (2)
Torsten
am 15 Apr. 2015
What are you trying to do ?
Find different a(1),...,a(5) that minimize ARE for each single value of w ?
Best wishes
Torsten.
3 Kommentare
Torsten
am 23 Apr. 2015
What exactly do you mean by
"I want the function to be minimized with range of values at a time"
?
If you want to minimize f for a range of values for w, use a for-loop over the elements of the w-array and therein, call "simulannealbnd" for each element of w separately.
Best wishes
Torsten.
Nitin Rawal
am 24 Apr. 2015
Bearbeitet: Nitin Rawal
am 24 Apr. 2015
I already tried what are you saying. It comes up with an error message:
??? Error using ==> samakedata at 28 Your objective function must return a scalar value.
Error in ==> simulannealcommon at 113 solverData = samakedata(solverData,problem,options);
Error in ==> simulanneal at 44 [x,fval,exitflag,output,solverData,problem,options] = ...
Error in ==> simulannealbnd at 129 [x, fval, exitflag, output] = simulanneal(FUN, x0, [], [], [], [], lb, ub, options);
Error in ==> simul at 6 [x,fval]= simulannealbnd(fh,x0);
This is because simulannealbnd's objective function can work properly with constant parameters But here I m using w =linspace(0,pi,10) stat# which evaluates ARE for each value of w but simulannealbnd's objective function can return only scalar value not a vector.
So please help me that how should I code objective function that my objective function minimized: Following is code of objective function
function ARE = abc(a) ; w = linspace(0,pi,1000) ARE =abs(((1./(j*w))-((a(1)*exp(2*j*w)+a(2)*exp(j*w)+a(3))./(exp(2*j*w)+a(4)*exp(j*w)+a(5))))./(1/(j*w)));
If it works like lsqcurvefit non linear function of matlab it is done with my work.
So please also have a look in lsqcurvefit function.
Thanks
Nitin Rawal
Torsten
am 24 Apr. 2015
a0 = [.0001 .0001 .0001 .0001 .0001 ];
w = linspace(0,pi,1000);
for i=1:length(w)
w_scal=w(i);
f =@(a)abc(a,w_scal);
[a_vec fval] = simulannealbnd(f,a0);
a_mat(:,i)=a_vec(:);
end
function ARE = abc(a,w)
ARE = ((1/(j*w)) - ((a(1)*exp(2*j*w) + a(2)*exp(j*w) + a(3)) / (exp(2*j*w)+a(4)*exp(j*w) + a(5)))/(1/(j*w)));
I wonder what j is - the imaginary unit ?
Best wishes
Torsten.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Surrogate Optimization finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!