Filter löschen
Filter löschen

fminsearch with 2 variables - help please!

58 Ansichten (letzte 30 Tage)
darksideofthemoon101
darksideofthemoon101 am 22 Feb. 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!

Antworten (1)

Baileycat
Baileycat am 1 Mär. 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])

Kategorien

Mehr zu Get Started with Optimization Toolbox finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by