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.

Antworten (1)

Torsten
Torsten am 20 Nov. 2015
Bearbeitet: Torsten am 20 Nov. 2015
f = sum((pow - (x(1)*frequency.^x(2) + x(3))).^2);
Best wishes
Torsten.

Kategorien

Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 20 Nov. 2015

Bearbeitet:

am 20 Nov. 2015

Community Treasure Hunt

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

Start Hunting!

Translated by