Sie sind auf Seite 1von 2

clear;

close;

%data observasi
x=[1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 10.5 11.5 12.5 13.5 14.5 15.5 16.5 17.5 18.5
19.5 20.5 21.5 22.5 23.5 24.5 25.5 26.5 27.5 28.5 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 4.5 5.5 6.5 7.5 8.5 9.5 10.5 11.5 12.5 13.5
14.5 15.5 16.5 17.5 18.5 19.5 20.5 21.5 22.5 23.5 24.5 25.5 6 7 8 9 10 11 12 13 14
15 16 17 18 19 20 21 22 23 24 7.5 8.5 9.5 10.5 11.5 12.5 13.5 14.5 15.5 16.5 17.5
18.5 19.5 20.5 21.5 22.5 9 10 11 12 13 14 15 16 17 18 19 20 21];
y=[0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25
0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.75 0.75 0.75 0.75
0.75 0.75 0.75 0.75 0.75 0.75 0.75 0.75 0.75 0.75 0.75 0.75 0.75 0.75 0.75 0.75
0.75 0.75 0.75 0.75 0.75 1.25 1.25 1.25 1.25 1.25 1.25 1.25 1.25 1.25 1.25 1.25
1.25 1.25 1.25 1.25 1.25 1.25 1.25 1.25 1.25 1.25 1.25 1.85 1.85 1.85 1.85
1.85 1.85 1.85 1.85 1.85 1.85 1.85 1.85 1.85 1.85 1.85 1.85 1.85 1.85 1.85 2.5
2.5 2.5 2.5 2.5 2.5 2.5 2.5 2.5 2.5 2.5 2.5 2.5 2.5 2.5 2.5 3.2 3.2 3.2 3.2 3.2 3.2
3.2 3.2 3.2 3.2 3.2 3.2 3.2];
nilai = [25.16186667 24.99605263 25.37288591 25.58993197 24.46326797 38.2452 76.616
95.142 125.8093333 189.97 95.77 63.742 37.8684 18.7144 37.1776 31.29533333 36.9892
18.7458 19.36884211 21.038 22.49717647 23.9425 24.35019355 25.28972973 24.41763158
24.35512821 24.16607595 25.16186667 24.82983498 24.02606452 24.79055738 24.63536977
30.59616 37.994 74.8576 124.972 125.8093333 76.7416 37.8684 18.7144 18.8714 37.8684
37.68 18.8086 18.6202 20.26572973 20.61933333 21.56731429 25.58207358 25.71006711
25.24394737 24.91741935 24.1231746 24.03170455 24.18429799 24.55734104 23.97337079
43.1436 84.9684 120.576 84.0264 42.5784 56.6456 18.84 57.2736 45.7812 61.4184
18.92373333 57.6504 34.43952 24.2382808 24.47034483 24.29089888 24.69059829
24.22285714 25.12 24.54535948 24.86795987 25.79891892 77.6208 76.8672 40.85450549
43.41549133 19.154 18.9028 46.02826347 44.2112 18.5888 18.6516 37.37064039
25.79210702 25.45271523 24.54909091 24.71483871 23.18769231 23.52539185 23.08535826
23.07134146 24.29056604 23.55 22.5808642 23.59815951 23.09107692 24.02349206
24.60815047 23.57445483 22.99446154 23.27760252 24.02349206 24.0345679 20.38206406
19.63048951 19.86763636 20.52817204 20.91843416 20.68447552 21.68633094 20.61478261
19.43494737 19.04113879 20.2380212 20.34173913 20.42097902];

%plot data observasi


plot3(x,y,nilai,'*r');
grid;
xlabel('X(m)');
ylabel('Y(m)');
zlabel('Nilai');
title('\fontsize{14} Sebaran nilai terhadap X dan Y');
ndata=length(nilai);

%Membentuk matrik kernel G dan vektor d


ndata=length(x);
for k = 1:ndata;
G(k,1)=1;
G(k,2)=x(k);
G(k,3)=y(k);
end
d=nilai';

%Perhitungan inversi dengan general least-squares


m=inv(G'*G)*G'*d;

%Plot hasil inversi (berupa garis least-squares)


hold on;
[X,Y] = meshgrid(min(x):max(x),min(y):max(y));
Z = m(1) + X.*m(2)+Y.*m(3);
surf(X,Y,Z);