-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregression.m
87 lines (71 loc) · 1.36 KB
/
regression.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
close all
clear all
x=[ 1 2 5 7 9 5 6 4 12 3];
y =[3 6 9 14 19 33 5 5 24 6];
figure(1)
plot(x,y,'o','MarkerFaceColor','b')
hold on
figure(1)
plot([1,12],[1.5,20] )
hold on
xvec=[1:25];
m=((20-1.5)/11)
c=0;
yvec=m*xvec+c;
plot(xvec,yvec)
d1 = [];
for i= 1:10
d1(i)=abs(y(i)-m*x(i)+c);
end
figure(2)
plot(d1,'o')
m=m+2;
sum=0;
for mm= m-2:0.1:m+1
for cc=c-2:0.1:c+1
dd=[];
for i= 1:10
dd(i)=abs(y(i)-mm*x(i)+cc);
sum=sum+dd(i);
end
figure(3)
%plot(mm,cc,sum);
plot(sum,mm,'or')
hold on
plot(sum,cc,'.b')
%mesh(mm,cc,sum)
%contour(sum)
%figure(3)
%surf(mm,cc,sum)
% hold on
sum=0;
end
end
for mm= m-2:0.1:m+2
for cc=c-2:0.1:c+2
dd=[];
for i= 1:10
dd(i)=abs(y(i)-mm*x(i)+cc);
sum=sum+dd(i)*dd(i);
end
figure(4)
%plot(mm,cc,sum);
plot(sum,mm,'or')
hold on
plot(sum,cc,'.b')
%mesh(mm,cc,sum)
%contour(sum)
%figure(3)
%surf(mm,cc,sum)
% hold on
sum=0;
end
end
finalm=1.98;
finalc=-0.1;
finaly=finalm*x+finalc;
figure(5)
plot(x,finaly);
hold on
plot(x,y,'o','MarkerFaceColor','b')
hold off