Borrar filtros
Borrar filtros

fminsearch with 2 variables - help please!

58 visualizaciones (últimos 30 días)
darksideofthemoon101
darksideofthemoon101 el 22 de Feb. de 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!

Respuestas (1)

Baileycat
Baileycat el 1 de Mzo. de 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])

Categorías

Más información sobre Get Started with Optimization Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by