日后补充先上代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
x=linspace(1,10,1000);
y
for i=1:size(x)(2)
y(i)=x(i)*9+5+10*(rand()-0.5);
end
m=size(x)(2);
a=0.001;
t0=0;
t1=0;
temp=999;
last_temp=0;
while temp!=last_temp
last_temp=temp;
temp=t0-a*1/m*sum(t0+t1*x-y);
t1=t1-a*1/m*sum((t0+t1*x-y).*x)
t0=temp
end
hold on
plot(x,y)
z=t0+t1*x
plot(x,z)
t0
t1