필터 지우기
필터 지우기

fminsearch

조회 수: 7 (최근 30일)
Giuseppe
Giuseppe 2012년 5월 3일
Hi, I need to find the best set of paramethers to minimize a chi-squared function. I wrote the function chi.m:
function chi = chi(theta, comp, sumcutmean);
model = theta * comp;
f = 0.0;
for i=1:1936
f = f + (sumcutmean(i) - model(i))^2;
end
chi = f;
end
where theta is 1x4 matrix of paramethers, comp is a 4x1936 matrix, of course model and sumcutmean are 1x1936. I tried to typing fminsearch in several ways, always obtaining errors. What is the correct expression to use?

답변 (3개)

Taniadi
Taniadi 2012년 5월 3일
i think that one of your errors is writing the function. the function should use different name for output variables.

Giuseppe
Giuseppe 2012년 5월 14일
Thanks for the answer, but I'm not sure it was the problem. I modified the function:
function [chi] = f(theta, comp, sum1minus589cutmean);
model = theta * comp;
somma = 0.0;
for i=1:1935
somma = somma + (sum1minus589cutmean(i) - model(i))^2;
end
chi = somma;
end
Typing
>> [theta] = fminsearch(@(theta0) f(theta0, comp, sum1minus589cutmean), theta0);
I obtain:
Undefined function 'f' for input arguments of type 'double'.
Error in @(theta0)f(theta0,comp,sum1minus589cutmean)
Error in fminsearch (line 191) fv(:,1) = funfcn(x,varargin{:});

Taniadi
Taniadi 2012년 5월 15일
I think that you can try to save your file using the filename "f.m" (equating your function name in function definition". And try to solve by using : theta = fminsearch(@f, guess,[],parameter). where parameter is list of parameters you try to include.
  댓글 수: 1
Walter Roberson
Walter Roberson 2012년 5월 15일
Adding the parameters at the end of the fminsearch() call is not documented as a possibility. Instead, using function handles and anonymous functions is recommended.

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by