
error window to a model function after nlinfit
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
DebiPrasad
el 14 de Mzo. de 2017
Comentada: Star Strider
el 14 de Mzo. de 2017
Hi I use nlinfit to fit an equation to a model, and get the value of the parameter with its associated error. Now I want to use this parameter with its error and plot another function, which should show the error region as well! For example: Equation 1: y=Acos(x)+Bsin(x) is fitted using nlinfit to give this. A=5 +- 0.1 B=3+-0.2 Now I want to use these values of A and B (with errors) to plot a function Y+-delY=(A+-delA)cosx +(B+-delB)sinx where del is the error .
Thanks
0 comentarios
Respuesta aceptada
John BG
el 14 de Mzo. de 2017
Hi Debi
clear all
dx=.001;x=[-2*pi:dx:2*pi];
a0=5;
da=.1;
alow=a0-da;
ahigh=a0+da;
a=[alow:0.1*da:ahigh];
b0=3;
db=.2;
blow=b0-db;
bhigh=b0+db;
b=[blow:0.1*db:bhigh];
y2low=0;
y2high=0;
for k=1:1:numel(x)
y2=a*cos(x(k))+b*sin(x(k));
y2low = [y2low min(y2)];
y2high = [y2high max(y2)];
end
y=a0*cos(x)+b0*sin(x);
ny=[1:1:numel(y)];
plot(ny,y,'r');grid on
hold all;
plot(ny,y2low([2:end]),'b');
plot(ny,y2high([2:end]),'b');

.
the error function you want delY is
delY=y2high-y2low
if you find this answer useful would you please be so kind to mark my answer as Accepted Answer?
To any other reader, please if you find this answer
please click on the thumbs-up vote link
thanks in advance
John BG
2 comentarios
John BG
el 14 de Mzo. de 2017
Thanks Debi, any more questions? if so feel free to ask
regards
John BG
Más respuestas (2)
Star Strider
el 14 de Mzo. de 2017
You have used the nlparci function to get the parameter confidence intervals.
The correct way to do what you want, that is to express the errors in the fit with respect to your data, is to calculate the confidence intervals on the prediction with the nlpredci function. That will give you the correct statistical result. It is also much more straightforward to implement.
The initially accepted answer is incorrect.
2 comentarios
Star Strider
el 14 de Mzo. de 2017
Hi Debi,
The nlinfit function does not allow you to constrain the parameters. The lsqcurvefit function does.
If you have the Optimization Toolbox, see if using the lsqcurvefit function with constraints on the parameter you want to limit will give you an acceptable fit to your data. I believe you can use nlparci and nlpredci with constrained parameter estimation outputs returned by lsqcurvefit, and I see nothing in the documentation for either function that indicates it would not be appropriate. (I know you can use them with lsqcurvefit with unconstrained parameters.)
Ver también
Categorías
Más información sobre Gaussian Process Regression 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!