fminsearch with 2 variables - help please!

조회 수: 101 (최근 30일)
darksideofthemoon101
darksideofthemoon101 2011년 2월 22일
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!

답변 (1개)

Baileycat
Baileycat 2011년 3월 1일
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])

카테고리

Help CenterFile Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by