MATLABÇúÏßÄâºÏ(º¬ÊµÀý) ÏÂÔØ±¾ÎÄ

function [xc,yc,r,fval,exitflag,output] = tlscirc(x,y) % TLS circle fit

options=optimset('TolFun',1e-10); [x0,y0]=circfit(x,y); % center estimate

[z,fval,exitflag,output]=fminsearch(@circobj,[x0,y0],options,x,y);

[f,r]=circobj(z,x,y); xc=z(1); yc=z(2); function [f,r] = circobj(z,x,y)

% TLS circle fit objective f and radius r n=length(x);

X=x-z(1); Y=y-z(2); X2=X'*X; Y2=Y'*Y; r=sum(sqrt(X.^2+Y.^2))/n; f=X2+Y2-n*r^2;

The circfit function is used above as an initial estimator. The objective values of tlscirc and circfit differ by nearly 14% in the example below.

x=[1;2;3;5;7;9]; y=[7;6;7;8;7;5]; plot(x,y,'bo'), hold on [xc,yc,r,f]=tlscirc(x,y)

% [xc,yc,r,f]=[4.7398, 2.9835, 4.7142, 1.2276] rectangle('Position', [1,1],'EdgeColor','b')

[xc,yc,r] = circfit(x,y)

X=x-xc; Y=y-yc; f=sum((sqrt(X.^2+Y.^2)-r).^2) % [xc,yc,r,f]=[4.7423, 3.8351, 4.1088, 1.3983] rectangle('Position', [1,1],'EdgeColor','r')

hold off, axis equal Genial @ USTC 2004-4-17

[xc-r,yc-r,2*r,2*r],

'Curvature',

[xc-r,yc-r,2*r,2*r],

'Curvature',

matlab·ÇÏßÐÔÇúÏßÄâºÏ

×î½üÔÚÓÃmatlab×ö·ÇÏßÐÔÇúÏßÄâºÏ£¬·¢ÏÖmatlab¹¦ÄÜȷʵºÜÇ¿´ó£¬×ܽáÆä·½·¨ÓÐÈçϼ¸ÖÖ£º

Ò»¡¢Matlab·ÇÏßÐÔÄâºÏ¹¤¾ßÏä µ¥Ò»±äÁ¿µÄÇúÏ߱ƽü

MatlabÓÐÒ»¸ö¹¦ÄÜÇ¿´óµÄÇúÏßÄâºÏ¹¤¾ßÏä cftool £¬Ê¹Ó÷½±ã£¬ÄÜʵÏÖ¶àÖÖÀàÐ͵ÄÏßÐÔ¡¢·ÇÏßÐÔÇúÏßÄâºÏ¡£ ¼ÙÉèÎÒÃÇÒªÄâºÏµÄº¯ÊýÐÎʽÊÇy=a+(b-a)*c^2*(c^2-x^2)/((c^2-x^2)^2+(2*d*x)^2);ÆäÖÐa,b,c,dÊÇ´ý¶¨ÏµÊý¡£

ÔÚÃüÁîÐÐÊäÈëÊý¾Ý£º x=8:0.01:12.4; y=real(epsilon); 2¡¢Æô¶¯ÇúÏßÄâºÏ¹¤¾ßÏä ¡·cftool

3¡¢½øÈëÇúÏßÄâºÏ¹¤¾ßÏä½çÃæ¡°Curve Fitting tool¡± £¨1£©µã»÷¡°Data¡±°´Å¥£¬µ¯³ö¡°Data¡±´°¿Ú£»

£¨2£©ÀûÓÃX dataºÍY dataµÄÏÂÀ­²Ëµ¥¶ÁÈëÊý¾Ýx,y£¬¿ÉÐÞ¸ÄÊý¾Ý¼¯Ãû¡°Data set name¡±£¬È»ºóµã»÷¡°Create data set¡±°´Å¥£¬Í˳ö¡°Data¡±´°¿Ú£¬·µ»Ø¹¤¾ßÏä½çÃæ£¬Õâʱ»á×Ô¶¯»­³öÊý¾Ý¼¯µÄÇúÏßͼ£»

£¨3£©µã»÷¡°Fitting¡±°´Å¥£¬µ¯³ö¡°Fitting¡±´°¿Ú£»

£¨4£©µã»÷¡°New fit¡±°´Å¥£¬¿ÉÐÞ¸ÄÄâºÏÏîÄ¿Ãû³Æ¡°Fit name¡±£¬Í¨¹ý¡°Data set¡±ÏÂÀ­²Ëµ¥Ñ¡ÔñÊý¾Ý¼¯£¬È»ºóͨ¹ýÏÂÀ­²Ëµ¥¡°Type of fit¡±Ñ¡ÔñÄâºÏÇúÏßµÄÀàÐÍ£¬¹¤¾ßÏäÌṩµÄÄâºÏÀàÐÍÓУº

Custom Equations£ºÓû§×Ô¶¨ÒåµÄº¯ÊýÀàÐÍ

Exponential£ºÖ¸Êý±Æ½ü£¬ÓÐ2ÖÖÀàÐÍ£¬ a*exp(b*x) ¡¢ a*exp(b*x) + c*exp(d*x) Fourier£º¸µÁ¢Ò¶±Æ½ü£¬ÓÐ7ÖÖÀàÐÍ£¬»ù´¡ÐÍÊÇ a0 + a1*cos(x*w) + b1*sin(x*w) Gaussian£º¸ß˹±Æ½ü£¬ÓÐ8ÖÖÀàÐÍ£¬»ù´¡ÐÍÊÇ a1*exp(-((x-b1)/c1)^2)

Interpolant£º²åÖµ±Æ½ü£¬ÓÐ4ÖÖÀàÐÍ£¬linear¡¢nearest neighbor¡¢cubic

spline¡¢shape-preserving Polynomial£º¶àÐÎʽ±Æ½ü£¬ÓÐ9ÖÖÀàÐÍ£¬linear ~¡¢quadratic ~¡¢cubic ~¡¢4-9th degree ~ Power£ºÃݱƽü£¬ÓÐ2ÖÖÀàÐÍ£¬a*x^b ¡¢a*x^b + c

Rational£ºÓÐÀíÊý±Æ½ü£¬·Ö×Ó¡¢·Öĸ¹²ÓеÄÀàÐÍÊÇlinear ~¡¢quadratic ~¡¢cubic ~¡¢4-5th degree ~£»´ËÍ⣬·Ö×Ó»¹°üÀ¨constantÐÍ

Smoothing Spline£ºÆ½»¬±Æ½ü

Sum of Sin Functions£ºÕýÏÒÇúÏ߱ƽü£¬ÓÐ8ÖÖÀàÐÍ£¬»ù´¡ÐÍÊÇ a1*sin(b1*x + c1) Weibull£ºÖ»ÓÐÒ»ÖÖ£¬a*b*x^(b-1)*exp(-a*x^b)

Ñ¡ÔñºÃËùÐèµÄÄâºÏÇúÏßÀàÐͼ°Æä×ÓÀàÐÍ£¬²¢½øÐÐÏà¹ØÉèÖãº

¡ª¡ªÈç¹ûÊÇ·Ç×Ô¶¨ÒåµÄÀàÐÍ£¬¸ù¾Ýʵ¼ÊÐèÒªµã»÷¡°Fit options¡±°´Å¥£¬ÉèÖÃÄâºÏËã·¨¡¢Ð޸Ĵý¹À¼Æ²ÎÊýµÄÉÏÏÂÏ޵ȲÎÊý£»

¡ª¡ªÈç¹ûÑ¡Custom Equations£¬µã»÷¡°New¡±°´Å¥£¬µ¯³ö×Ô¶¨Ò庯ÊýµÈʽ´°¿Ú£¬ÓС°Linear EquationsÏßÐÔµÈʽ¡±ºÍ¡°General Equations¹¹ÔìµÈʽ¡±Á½ÖÖ±êÇ©¡£

ÔÚ±¾ÀýÖÐÑ¡Custom Equations£¬µã»÷¡°New¡±°´Å¥£¬Ñ¡Ôñ¡°General Equations¡±±êÇ©£¬ÊäÈ뺯ÊýÀàÐÍy=a+(b-a)*c^2*(c^2-x^2)/((c^2-x^2)^2+(2*d*x)^2)£¬ÉèÖòÎÊýa¡¢b¡¢c¡¢dµÄÉÏÏÂÏÞ£¬È»ºóµã»÷OK¡£

5£©ÀàÐÍÉèÖÃÍê³Éºó£¬µã»÷¡°Apply¡±°´Å¥£¬¾Í¿ÉÒÔÔÚResults¿òÖеõ½ÄâºÏ½á¹û£¬ÈçÏÂÀý£º

General model:

f(x) = a+(b-a)*c^2*(c^2-x^2)/((c^2-x^2)^2+(2*d*x)^2) Coefficients (with 95% confidence bounds): a = 3.155 (3.129, 3.181) b = 3.025 (2.998, 3.051) c = 9.577 (9.572, 9.582) d = 0.1387 (0.1312, 0.1462) Goodness of fit: SSE: 32.94 R-square: 0.924

Adjusted R-square: 0.9235 RMSE: 0.2746 ÄâºÏÇúÏßÈçÏÂ

¶þ¡¢ÀûÓÃnlinfitº¯ÊýʵÏÖ£¬´úÂëÈçÏ£º clc;

x=8:0.01:12.4; x=x;

y=real(epsilon); y=y';

myfunc=inline('beta(1)+(beta(2)-beta(1))*beta(3)^2*(beta(3)^2-x.^2)./((beta(3)^2-x.^

2).^2+(2*beta(4)*x).^2)','beta','x');

my_opts = statset('MaxIter',300,'TolFun',1e-12,'TolX',1e-12); beta=nlinfit(x,y,myfunc,[1 1 10 1],my_opts); %µ÷Õû³õÖµ¿ÉÄܵ¼Ö²»Í¬½á¹û,µ«Ã²ËÆÔö¼ÓÒ»¸öoptions¶Ô½á¹ûûÆðʲô×÷ÓÃ

beta(1) beta(2) beta(3) beta(4)

%test the model xx=min(x):0.01:max(x);

yy=beta(1)+(beta(2)-beta(1))*beta(3)^2*(beta(3)^2-x.^2)./((beta(3)^2-x.^2).^2+(2*beta(4)*x).^2);