http://www.ilovematlab.cn/thread-2437-1-1.html
看点:
(1)圆方程进行线性拟合的思路
(2)num2str的简单应用
clear
clc
% x^2+2*y^2=4
X=(0:0.1:2)';
Y=sqrt((4-X.^2)/2)+rand(size(X))*0.5;
x=[X;X;-X;-X];
y=[Y;-Y;Y;-Y];
plot(x,y,'r*')
ML=[2*x,2*y,-y.^2,ones(size(x))];
MR=x.^2;
S=ML\MR;
whos S
X0=S(1)
e=S(3)
Y0=S(2)/e
a=S(4)+X0^2+Y0^2
hold on
str=['(x-' num2str(X0) ')^2+' num2str(e) '*(y-' num2str(Y0) ')^2-' num2str(a)];
ezplot(str)
程序运行结果:
Name Size Bytes Class Attributes
S 4x1 32 double
X0 =
3.3246e-017
e =
1.2816
Y0 =
-1.5947e-017
a =
3.7418
画图结果: