fitting a curve for multiple parameters and specific x values
Show older comments
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.
Answers (1)
f = sum((pow - (x(1)*frequency.^x(2) + x(3))).^2);
Best wishes
Torsten.
1 Comment
Samson Chota
on 20 Nov 2015
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!