fitting a curve for multiple parameters and specific x values
이전 댓글 표시
Hi everyone, I am trying to fit a function to data points. I am starting off with two arrays of equal size lowfreq and lowmeanmale which contain x and y values respectively. The code goes like this:
x0 = [1,-1,0]; %initial parameters
x = fminsearch(@(x)myfun(x,lowfreq,lowmeanmale),x0); %here i try to find the minimum for three parameters x(1,2,3)
where myfun is defined as:
function f = myfun(x, frequency, pow)
f = pow - x(1)*frequency.^x(2) + x(3); %here i find the difference between my data pow, and the function created by parameters for each x value of frequency
end
The error message goes like this:
Subscripted assignment dimension mismatch.
Error in fminsearch (line 191)
fv(:,1) = funfcn(x,varargin{:});
Anyone know what i am doing wrong?
Thanks for the help.
답변 (1개)
f = sum((pow - (x(1)*frequency.^x(2) + x(3))).^2);
Best wishes
Torsten.
카테고리
도움말 센터 및 File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!