steepest and shallowest linear fits of error-affected y data

steepest and shallowest linear fits of error-affected y data

The title pretty much says what Id like to do. I belief theres no built-in method in matlab to do so. Actually this is really easy to do by hand but I couldnt figure out an algorithm to mimic this. My compromise solution is the following: x1;2;3;4;5;6;7;8;9;10; y10;9;8.5;7.8;7.5;7;6.6;6.0;5;5.0; err0.5;1.0;0.8;0.6;1.0;0.8;1.2;0.9;0.5;0.5; errorbarx,y,err,.; hold on; maxgrady; maxgradx; maxgrade; mingrady; mingradx; mingrade; m0; nlengthy; if remn,20 mn2; else mn-12; end for k1:m maxgradykykerrk; maxgradxkxk; maxgradekerrk; mingradykyk-errk; mingradxkxk; mingradekerrk; end r0; for kn-m1:n if remn,20 rk; else rk-1; end maxgradyryk-errk; maxgradxrxk; maxgradererrk; mingradyrykerrk; mingradxrxk; mingradererrk; end ft fittype axb, independent, x, dependent, y ; opts fitoptions Method, NonlinearLeastSquares ; wtmaxerr-err; opts.Weights wt; opts.StartPointx1 y1; fitmed, gof fit x, y, ft, opts; hmed plotfitmed,-k; max opts.Weightsmaxgrade; opts.StartPointmaxgradx1 maxgrady1; fitmaxfitmaxgradx,maxgrady,ft,opts; hmaxplotfitmax; Min opts.Weightsmingrade; opts.StartPointmingradx1 mingrady1; fitminfitmingradx,mingrady,ft,opts; hminplotfitmin; Im not happy with that. I couldve done better manually. BTW, Ive searched the web and to my surprise I couldnt find an algorithm to do this even though this is a very common erorr-analysis method. Any ideas EDIT: My 2nd attempt x1;2;3;4;5;6;7;8;9;10; y9.8;9;8.5;7.8;7.5;7;6.6;6.0;5.5;5.0; err0.8;1.0;0.8;0.6;1.0;0.8;1.2;0.9;0.5;0.5;; w1.err; f0fitlmx,y,linear,weight,w; y0f0.Coefficients.Estimate1; s0f0.Coefficients.Estimate2; cicoefCIf0; y0_maxci1,1 s_maxci2,1 y0_minci1,2; s_minci2,2; yfity0xs0; yfitmaxy0_maxxs_max; yfitminy0_minxs_min; errherrorbarx,y,err,o; hold on; plotx,yfit,-k; plotx,yfitmax,-r; plotx,yfitmin,-b; Dont like it...I can see with my bare eyes that theres a steeper possible fit... With this example-data I could just use the 1st and last data-points...but notice that this is not always possible

Комментарии

Популярные сообщения из этого блога

FillChar and StringOfChar under Delphi 10.2 for Win64 Release Target

TeXnicCenter does not work with Adobe anymore