Problem with fitting curve with a user defined function directly
1 view (last 30 days)
Show older comments
sepideh naserbakht
on 1 Feb 2019
Answered: Bjorn Gustavsson
on 1 Feb 2019
I want to fit my data with following function:
I can't fit directly. P and γ have fixed values. How can I do that?
0 Comments
Accepted Answer
Bjorn Gustavsson
on 1 Feb 2019
Well replace P and γ in your equation with those fixed values - that should leave you with A, β and w, as free parameters to fit for? Then you get to write your error-function either for optimization with fminsearch:
function err = my_errfcn(pars,X,Y)
A = pars(1);
beta = pars(2);
w = pars(3);
P = your-fixed-value;
gamma = your-other-fixed-value;
err = sum((Y(:)-A*P./((w^2*(1+beta*Y(:))-X(:).^2).^2+gamma^2*X(:).^2)).^2);
end
Then you'd be nicely set up for parameter fitting with fminsearch. Or for lsqnonlin:
function err = my_residualfcn(pars,X,Y)
A = pars(1);
beta = pars(2);
w = pars(3);
P = your-fixed-value;
gamma = your-other-fixed-value;
err = (Y(:)-A*P./((w^2*(1+beta*Y(:))-X(:).^2).^2+gamma^2*X(:).^2));
end
That function should be possible to use with lsqnonlin. I inserted an additional ')' into your equation since it has 2 '(' and 3 ')'...
HTH
0 Comments
More Answers (0)
See Also
Categories
Find more on Interpolation 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!