Borrar filtros
Borrar filtros

How to fit to an infinite series function?

6 visualizaciones (últimos 30 días)
Qili Hu
Qili Hu el 24 de En. de 2021
Comentada: Vladimir Sovkov el 19 de Mzo. de 2024
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.

Respuesta aceptada

Vladimir Sovkov
Vladimir Sovkov el 24 de En. de 2021
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 comentarios
Vladimir Sovkov
Vladimir Sovkov el 19 de Mzo. de 2024
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 el 19 de Mzo. de 2024
Sorry for the misprints, I was in a hurry. Hope, it is still understandable.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by