variance including in non linear fit

Hello, I acquired a set of samples in a time window (100sample/sec), and I considered my final data as the mean of each measurement. I would like to fit (I used the lsqcurvefit matlab method, fitting an erfc function) a set of this measurement but I would like also to include the variance of each measurement in the fit....how could I do this?
In particular what I want to do is to fit an erfc function but the source of my data is a pawermeter which measures the power from a laser which is not so stable than each measurement presents a no-negligible variance.

 Respuesta aceptada

Matt J
Matt J el 14 de Oct. de 2020
Editada: Matt J el 14 de Oct. de 2020
If you mean you want to inversely weight by the variance, just pre-weight your ydata and your model function output,
x=lsqcurvefit(@(x,xdata) mdl(x,xdata)./weights, x0,xdata, ydata./weights,....)

2 comentarios

Sorry the ignorance, but with mdl what do you mean? I'm not sure how should I use this method.
This is my function : f=@(p,x)(p(1)*(erfc(p(2)*(x-p(3))))+p(4));
To determine the variances of sample I simply used the var() function.
and this is where I fit the data (I have a matrix of samples):
for i=1:zSampNum
p0(i,:)=[max(sample(i,:)),(2^.5)/(6*stepX(i)),stepX(i)*10,0];
distance(i,:)=linspace(-stepX(i)*10,stepX(i)*10,xSampNum);
fit=lsqcurvefit(f,p0(i,:),distance(i,:),sample(i,:));
fitDistance(i,:)=linspace(-stepX(i)*10,stepX(i)*10,2000);
fitSample(i,:)=f(fit,fitDistance(i,:));
waist(i)=(2^.5)/fit(2);
figure()
plot(distance(i,:),sample(i,:),'*')
hold on
plot(fitDistance(i,:),fitSample(i,:))
title(['Plot relative to measurement' num2str(i)])
end
Sorry for this but I tried to used your approach (from a theoretical point of view I understand) but I'm not sure to understand the implementation.
fit=lsqcurvefit(@(p,x)(p(1)*(erfc(p(2)*(x-p(3))))+p(4))./weights,...
p0(i,:),distance(i,:),sample(i,:)./weights);

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Centro de ayuda y File Exchange.

Preguntada:

el 14 de Oct. de 2020

Comentada:

el 14 de Oct. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by