필터 지우기
필터 지우기

How to fit to an infinite series function?

조회 수: 1 (최근 30일)
Qili Hu
Qili Hu 2021년 1월 24일
댓글: Vladimir Sovkov 2024년 3월 19일
qt is a dependent variable; t is an independent variable; qe B are undetermined parameters.
syms n t;
x=[0 5 10 15 20 30 45 60 75 90 105 120];
y=[0 3.87 4.62 4.98 5.21 5.40 5.45 5.50 5.51 5.52 5.54 5.53];
plot(x,y,'bo');
hold on
beta0=[39,0.002];
fun=@(beta,xdata) beta(1)*(1-6/(pi^2)*symsum((1/n^2)*exp(-beta(2)*(n^2)*t),n,1,inf))
betafit = nlinfit(x,y,fun,beta0);
plot(x,y,fun,beta0)
However, it does not work well. How to do it in MATLAB? Help me. Many thanks.

채택된 답변

Vladimir Sovkov
Vladimir Sovkov 2021년 1월 24일
An iterative solution instead of the symbolic one can be more productive this case, like this one
x=[0 5 10 15 20 30 45 60 75 90 105 120];
y=[0 3.87 4.62 4.98 5.21 5.40 5.45 5.50 5.51 5.52 5.54 5.53];
plot(x,y,'bo');
hold on
pause(0.1);
beta0=[39,0.002];
% syms n t
% fun=@(beta,t) beta(1)*(1-6/(pi^2)*symsum((1./n.^2).*exp(-beta(2)*(n.^2).*t),n,1,Inf));
% betafit = nlinfit(x,y,fun,beta0);
beta1=beta0;
delta = 1e-8; % desired objective accuracy
R0=Inf; % initial objective function
for K=1:10000
fun=@(beta,t) beta(1)*(1-6/(pi^2)*sum((1./(1:K)'.^2).*exp(-beta(2)*((1:K)'.^2).*t),1));
[betafit,R] = nlinfit(x,y,fun,beta1);
R = sum(R.^2);
if abs(R0-R)<delta
break;
end
beta1=betafit;
R0 = R;
end
plot(x,fun(betafit,x),'.-r');
xlabel('x');
ylabel('y');
legend('experiment','model');
title(strcat('\beta=[',num2str(betafit),'];----stopped at--','K=',num2str(K)));
  댓글 수: 8
Vladimir Sovkov
Vladimir Sovkov 2024년 3월 19일
Hi! The mathematics of how to estimate the standard deviations in LSF using the local linear approximation is described in many textbooks. Briefly, it requires estimating derivatives of your computed function over its parameters, construction from them the design matrix (Jacoby matrix), and applying some standard equations to find the covariance matrix of the parameters; its diagonal elements are the squares of the sought standard deviation. Programming of all this "from scratch" is somewhat complucated, and I do not have time to do it for you now. However, you can download my package Optimizer from https://sourceforge.net/projects/optimizer-sovkov/, adopt the interface of your program to its regulations, and this would privide you with those estimates automatuclly. If you believe that the linear appriximation is not enough in your case, the Monter-Carlo-type computation can be used, in which you generate pseudo-randomly the cloud in your parameter space and estimate its spread within the spread of the computed data around your experimental curve.
Vladimir Sovkov
Vladimir Sovkov 2024년 3월 19일
Sorry for the misprints, I was in a hurry. Hope, it is still understandable.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by