fitting a curve for multiple parameters and specific x values
Mostrar comentarios más antiguos
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.
Respuestas (1)
f = sum((pow - (x(1)*frequency.^x(2) + x(3))).^2);
Best wishes
Torsten.
1 comentario
Samson Chota
el 20 de Nov. de 2015
Categorías
Más información sobre Get Started with Curve Fitting Toolbox en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!