Problem with fitting curve with a user defined function directly

I want to fit my data with following function:
I can't fit directly. P and γ have fixed values. How can I do that?

 采纳的回答

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 个)

类别

帮助中心File Exchange 中查找有关 Least Squares 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by