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