Function with multiple input parameters to be determined through fitting

조회 수: 5 (최근 30일)
Jack
Jack 2024년 6월 7일
댓글: Jack 2024년 6월 8일
Hi, I have a function to be fitted to some experimental data, but this function has multiple fitting parameters (6 parameters). I know that one of the ways to find these fitting parameters is to pass the function, the inital guess to the parameters and the lower and upper bounds into the lsqcurvefit function.
I have already created the function, but it seems like the software doesn't know that the p(1),p(2), p(3)... are parameters. Sorry if the function is very long.
What I wanted was p to be a vector with 6 elements p(1) p(2) p(3) p(4) p(5) p(6) but it seems like the software cant differentiate betwen p and p(1) p(2) p(3) p(4) p(5) p(6). When I try running the code, the error message I got was "Not enough input arguments"
Thank you for helping
function F = EM_SS(p, E_p)
F = p(1)*(2*pi*sqrt(p(4))/E_p)*(1/p(6))*(int(sech(((E_p - E)./p(6)))*(1 + 10*p(5)*(E - p(3)) + 126*p(5)^2*(E - p(3))^2)/(1 - exp(-2*pi*sqrt(p(4)/(E - p(3))))), E, p(3), Inf, 'ArrayValued', 1)) + p(2)*(2*pi*p(4)^3/2)*1/p(6)*((1/1^3)*sech((E_p - p(3) + p(4)/1^2)./p(6)) + (1/2^3)*sech((E_p - p(3) + p(4)/2^2)./p(6)) + (1/3^3)*sech((E_p - p(3) + p(4)/3^2)./p(6)) + (1/4^3)*sech((E_p - p(3) + p(4)/4^2)./p(6)) + (1/5^3)*sech((E_p - p(3) + p(4)/5^2)./p(6)) + (1/6^3)*sech((E_p - p(3) + p(4)/6^2)./p(6)) + (1/7^3)*sech((E_p - p(3) + p(4)/7^2)./p(6)));
end
  댓글 수: 1
Jack
Jack 2024년 6월 7일
please refer to this picture for the function to be fitted. everything other than and π is a fitting parameter. is given by: where R is also a fitting parameter. There should be a total pf 6 fitting parameters.

댓글을 달려면 로그인하십시오.

채택된 답변

Torsten
Torsten 2024년 6월 7일
편집: Torsten 2024년 6월 8일
You have to use "integral" instead of "int" and loop over the elements in E_p:
EM_SS([1 1 1 1 1 1],1)
ans = 3.2940e+03
function F = EM_SS(p, e_p)
for i = 1:numel(e_p)
E_p = e_p(i);
F(i) = p(1)*(2*pi*sqrt(p(4))/E_p)*(1/p(6))*...
(integral(@(E)sech(((E_p - E)./p(6)))*(1 + 10*p(5)*(E - p(3)) + ...
126*p(5)^2*(E - p(3))^2)/(1 - exp(-2*pi*sqrt(p(4)/(E - p(3))))), p(3), Inf, 'ArrayValued', 1)) + ...
p(2)*(2*pi*p(4)^3/2)*1/p(6)*(...
(1/1^3)*sech((E_p - p(3) + p(4)/1^2)./p(6)) + ...
(1/2^3)*sech((E_p - p(3) + p(4)/2^2)./p(6)) + ...
(1/3^3)*sech((E_p - p(3) + p(4)/3^2)./p(6)) + ...
(1/4^3)*sech((E_p - p(3) + p(4)/4^2)./p(6)) + ...
(1/5^3)*sech((E_p - p(3) + p(4)/5^2)./p(6)) + ...
(1/6^3)*sech((E_p - p(3) + p(4)/6^2)./p(6)) + ...
(1/7^3)*sech((E_p - p(3) + p(4)/7^2)./p(6)));
end
end
  댓글 수: 15
Torsten
Torsten 2024년 6월 8일
I think the problems will be too problem-specific to find general ressources. As said: less parameters and good initial guesses for them would be helpful. Did you plot Abs against E_p for the initial guesses you provided to get an impression of the "initial fitting quality" ?
Jack
Jack 2024년 6월 8일
I have tried doing the scatter plot of Abs against E_p but I have been trying for days to plot the curve that will fit the scatter plot.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by