필터 지우기
필터 지우기

using fminsearch with matrices

조회 수: 12 (최근 30일)
alex
alex 2012년 4월 17일
hi. I am trying to find a minimum value for the next argument-
sum(Y1-x(1)*exp(-((m_mat-x(2))^2+(n_mat-x(3))^2)/(2*sigmasq)))
when Y1,m_mat,n_mat,sigmasq are all known matrices in size of 11*11
how should I write it so it woulfd work? because for now the matlab writes an error of "Subscripted assignment dimension mismatch." ?
  댓글 수: 1
Sean de Wolski
Sean de Wolski 2012년 4월 17일
This isn't really clear. You have to formulate the above to take an input argument and return a scalar while will be this value. FMINSEARCH will then minimize this scalar by changing the input. Please clarify the question and post the code.

댓글을 달려면 로그인하십시오.

채택된 답변

Sargondjani
Sargondjani 2012년 4월 17일
yep sean is right: your objective function should return a scaler if you want to use fminsearch. anyway, this is how you would do it, IF you have function that returns a scalar and x(1),x(2) and x(3) are the choice variables:
%give value for parameters Y1, ... etc.
Y1=...
%give objective function
scalar_function = @(x)sum(Y1-x(1)*exp(-((m_mat-x(2))^2 +...
(n_mat-x(3))^2)/(2*sigmasq)))
%solve
x0=[...,...,...];
[x,value]=fminsearch(scalar_function,x0);
i want to note that 'fminunc' might be a better option, because it seems you can easily supply the gradient as well. that might speed things up...
  댓글 수: 1
Sean de Wolski
Sean de Wolski 2012년 4월 17일
FMINUNC is usually faster, but it requires the Optimization Toolbox. FMINSEARCH is in base MATLAB

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by