Effacer les filtres
Effacer les filtres

fminsearch with 2 variables - help please!

58 vues (au cours des 30 derniers jours)
darksideofthemoon101
darksideofthemoon101 le 22 Fév 2011
Hi,
I want to use fminsearch to find the minimum of 2 variables, but I don't understand how the fminsearch function works in this case. The basic outline of my code is as follows.
function y=myfunction(x,y)
constants not including x & y
m=1
for z=start:spacing:stop
some calculations involving x & y
m=m+1
end
y= figure of merit for minimisation
How do I use fminsearch to account for the variables x & y? If I try to use
fminsearch(myfunction(x,y),[x0 y0])
I get an error message
??? Error using ==> fcnchk at 109
FUN must be a function, a valid string expression,
or an inline function object.
Error in ==> fminsearch at 178
funfcn = fcnchk(funfcn,length(varargin));
Please help!

Réponses (1)

Baileycat
Baileycat le 1 Mar 2011
Instead of having them as two separate variables, set the problem up with each variable as part of one overall variable.
So, x -> x(1) and y -> x(2)
Then, y=myfunction(x)
[x, fval, exitflag] = fminsearch(@myfunction, [x0;y0])

Catégories

En savoir plus sur Get Started with Optimization Toolbox dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by