Borrar filtros
Borrar filtros

How do I get the error of a fitting function?

5 visualizaciones (últimos 30 días)
JJH
JJH el 14 de En. de 2019
Comentada: Star Strider el 16 de En. de 2019
I've written a function that does a Lorentzian fit on a set of data. I want to calculate an error bar for the accuray of this fit with respect to the x coordinates (the parameter Wavelength). Is this a built in command or is it more difficult?
function [params, Wavelength, Intensity, wavpeak]=SpectrumPeakFitCSV(filename)
SpectrumData=csvread(filename);
Wavelength=SpectrumData(2:end-1,1);
Intensity=SpectrumData(2:end-1,2);
Max = max(Intensity);
peak = find(Intensity==Max(1));
wavpeak = Wavelength(peak(1));
fun=@(x,Wav)Lorentzian(x(1),x(2),x(3),Wav)+x(4);
dark=Intensity(1);
opts = optimset('Display','off');
x=lsqcurvefit(fun,[Max(1),1,wavpeak,dark],Wavelength,Intensity,[0.5*Max(1) 0 wavpeak-0.2 0.9*dark],[2*Max(1) 3 wavpeak+0.2 1.5*dark],opts);
params=x; %scale, width, centre, dark
end

Respuesta aceptada

Star Strider
Star Strider el 14 de En. de 2019
If I understand correctly what you want to do, the Statistics and Machine Learning Toolbox function nlpredci (link) is likely what you are looking for. Use the ‘jacobian’ output (last output) from lsqcurvefit with it.
  5 comentarios
Janna Hinchliff
Janna Hinchliff el 16 de En. de 2019
Thanks, nlinfit seems to be a bit easier!
Star Strider
Star Strider el 16 de En. de 2019
@Janna Hinchliff — Please see my Comment to your Question.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by