You are on page 1of 3

Hazrlayan: Erim KOYUN

erimkoyun@gmail.com

En kk Kareler Yntemi kullanarak


lineer denklem uydurma
veriler

In[312]:=

Clear@x, y, n, xy, sumx, sumx2, sumxy, sumy, xav, yav, a1, a0, fD
x = 80, 2, 3, 4, 5, 6, 7, 8, 9, 10<;
x ve y
y = 827, 30, 33, 34, 35, 37, 38, 39, 41, 42<;
deerlerini
n = Abs@Dimensions@xD@@1DDD;
xy = Table@0, 8i, n<, 8j, 2<D;
xy deikeninde
Do@xy@@i, 1DD = x@@iDD; xy@@i, 2DD = y@@iDD, 8i, 1, n<D
matris olarak yazma
data = ListPlot@xy, PlotStyle PointSize@0.02D,
PlotLabel -> "Given y vs x data points", TextStyle 8FontSize 11<D
sumx = 0; Do@sumx = x@@iDD + sumx, 8i, 1, 10<D; Print@"sum of x: ", sumxD
sumxy = 0; Do@sumxy = x@@iDD * y@@iDD + sumxy, 8i, 1, 10<D;
Print@"sum of xi *yi : ", sumxyD
sumy = 0; Do@sumy = y@@iDD + sumy, 8i, 1, 10<D; Print@"sum of yi : ", sumyD

xy matrisini
grafikte
gsterme

sumx2 = 0; Do@sumx2 = Hx@@iDDL ^ 2 + sumx2, 8i, 1, 10<D; PrintA"sum of xi 2 : ", sumx2E

En kk
kareler kodu

sumy2 = 0; Do@sumy2 = Hy@@iDDL ^ 2 + sumy2, 8i, 1, 10<D


xav = sumx 10; Print@"avarage of xi : ", xav D
yav = sumy 10; Print@"avarage of yi : ", yav D
10. * HsumxyL - sumx * sumy
a1 =
; Print@"a1 : ", a1 D
10 * Hsumx2L - HsumxL ^ 2
a0 = yav - a1 * HxavL; Print@"a0 : ", a0 D
f@t_D := N@a0D + N@a1D * t
n = 10; sr = 0; Do@sr = sr + Hy@@nDD - a0 - a1 * x@@nDDL ^ 2, 8n, 1, 10<D
error =
r = NB

sr Hn - 2L ; Print@"standart error: ", errorD


n * sumxy - sumx * sumy
F;
n * sumx2 - HsumxL ^ 2 * n * sumy2 - HsumyL ^ 2

Tablo ve grafikleri
gsterme

Print@"correlation coefficient: ", rD


TableFormATable@8x@@nDD, y@@nDD, N@Hy@@nDD - yavL ^ 2D,

ScientificForm@Hy@@nDD - a0 - a1 * x@@nDDL ^ 2D<, 8n, 1, 10<D,

TableHeadings 98"", "", "", ""<, 9"xi ", "yu ", "Hyi -yavL2 ", "Hyi -a0 -a1 xi L2 "==E

line = Plot@f@tD, 8t, 0, 10<, PlotStyle RedD


Show@data, line, PlotRange AllD

Sonular

Given y vs x data points


42
40
38
36

Out[318]=

34
32
30
2

10

least-sqr.nb

sum of x: 54
sum of xi *yi : 2059
sum of yi : 356
sum of xi 2 : 384
avarage of xi :
avarage of yi :

27
5
178

Denklem katsaylar

a1 : 1.47835
a0 : 27.6169
standart error: 0.554156
correlation coefficient: 0.993972
xi

yu

Hyi -yavL2

Hyi -a0 -a1 xi L2

27

73.96

3.80545 10-1

30

31.36

3.29009 10-1

33

6.76

8.98802 10-1

34

2.56

2.20615 10-1

35

0.36

7.49611 10-5

37

1.96

2.63156 10-1

38

5.76

1.19938 10-3

39

11.56

1.9689 10-1

41

29.16

6.07185 10-3

10

42

40.96

1.60347 10-1

Out[332]//TableForm=

42

Katsaylar yukarda elde edilen


doru denkleminin grafii

40
38
36
Out[333]=

34
32
30

10

least-sqr.nb

Uydurulan doru veriler ile birlikte gsterilmitir.


Given y vs x data points

40

Out[334]=

35

10

You might also like