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 vue (au cours des 30 derniers jours)
========================================= 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)));

Réponses (2)

Torsten
Torsten le 15 Avr 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 commentaires
Torsten
Torsten le 23 Avr 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
Nitin Rawal le 24 Avr 2015
Modifié(e) : Nitin Rawal le 24 Avr 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

Connectez-vous pour commenter.


Torsten
Torsten le 24 Avr 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.

Catégories

En savoir plus sur Surrogate Optimization dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by