
error window to a model function after nlinfit
4 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
John BG
2017 年 3 月 14 日
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 件のコメント
John BG
2017 年 3 月 14 日
Thanks Debi, any more questions? if so feel free to ask
regards
John BG
その他の回答 (2 件)
Star Strider
2017 年 3 月 14 日
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 件のコメント
Star Strider
2017 年 3 月 14 日
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.)
参考
カテゴリ
Help Center および File Exchange で Gaussian Process Regression についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!