Escolar Documentos
Profissional Documentos
Cultura Documentos
clear all
clc
disp ('Program Regresi linear')
disp ('Program ini akan menerima input berupa fungsi linier, kemudian akan ')
disp ('membuat data tabel dari fungsi tersebut dan meregresikan data tabel ')
disp ('tersebut menjadi suatu fungsi linier, fungsi linier tersebut seharusnya ')
disp ('sama dengan fungsi linier input')
disp ('ket : harap tidak memasukan fungsi yang menuju tak hingga secara cepat')
disp ('seperti exp(x^2), masukan variabel fungsi sesuai pada kode matlab')
n = input ('Masukan jumlah koefisien pada persamaan ');
f2 = '@(x)';
d = n+5;
for i = 1:n
disp (['koefisien ' num2str(i)])
k(i) = input('Masukan nilai koefisien : ');
f1 = input('Masukan variabel fungsi : ', 's');
f3 = strcat(f2,f1);
f = str2func(f3);
for j = 1:d
z(j,i) = f(j);
end
end
for i = 1:d
y(i,1) = 0;
for j = 1:n
y(i,1) = y(i,1) + k(j)*z(i,j);
end
end
zt = z.';
a = ((zt*z)^-1) * (zt*y);
5.
Ambil X = T1,5, Y = Cp
Persamaan menjadi Y = a + b.X + c.X2 (kasus regresi kuadrat).
Dengan meminimumkan Sr diperoleh 3 persamaan dengan 3 variabel :
X (T^1.5)
3488,122704
3718,064012
4192,374029
6269,290231
7117,092103
7701,882887
32486,82597
X^2
12167000
13824000
17576000
39304000
50653000
59319000
192843000
Y
1245
1280
1350
1480
1585
1710
8650
X^3
42439988943
51398516907
73685165936
2,46408E+11
3,60502E+11
4,56868E+11
1,2313E+12
Xi.Yi
4342712,767
4759121,936
5659704,939
9278549,542
11280590,98
13170219,74
48490899,9
X^4
1,48036E+14
1,91103E+14
3,08916E+14
1,5448E+15
2,56573E+15
3,51874E+15
8,27733E+15
X^2.Yi
15147915000
17694720000
23727600000
58169920000
80285005000
1,01435E+11
2,96461E+11
a0 = a, a1 = b, a2 = c
6.a + 32486,82597.b + 192843000.c = 8650 .. (1)
32486,82597.a + 192843000.b + 1,2313.10^12.c = 48490899,9 ..(2)
192843000.a + 1,2313.10^12.b + 8,27733.10^15.c = 2,96461.10^11 ..(3)
a. Dengan 3 persamaan dan 3 variabel yang tidak diketahui, menggunakan metode eliminasi
Gauss diperoleh :
a = 1281,434
b = -0.04702712265076421
c = 0.00001310425053620578
b. Kesalahan absolut rata-rata dari model tersebut adalah :
Y
1245
1280
1350
1480
1585
1710
= ( Y Yperhitungan)/n
= 135,614 / 6
= 22,6024
9.
10.
INPUT
clear all
close all
clc
f=@(x) (7+2*x^4);
a=0;
b=1;
h=.25;
Iquarter=0;
while (a<b)
Iquarter=Iquarter+(h/2)*(f(a)+f(a+h));
a=a+h;
end
Iquarter
a=0;
b=1;
h=.25/2;
Ieighth=0;
while (a<b)
Ieighth=Ieighth+(h/2)*(f(a)+f(a+h));
a=a+h;
end
Ieighth
a=0;
b=1;
h=.25/4;
Isixteenth=0;
while (a<b)
Isixteenth=Isixteenth+(h/2)*(f(a)+f(a+h));
a=a+h;
end
Isixteenth
a=0;
b=1;
h=.25/4;
Ithirtysecond=0;
while (a<b)
Ithirtysecond=Ithirtysecond+(h/2)*(f(a)+f(a+h));
a=a+h;
end
Ithirtysecond
I1=(4/3)*Iquarter-(1/3)*Ieighth
I2=(4/3)*Ieighth-(1/3)*Isixteenth
I3=(4/3)*Isixteenth-(1/3)*Ithirtysecond
I12=(16/15)*I1-(1/15)*I2
I23=(16/15)*I2-(1/15)*I3
I123=(64/63)*I2-(1/63)*I3
OUTPUT
Iquarter =7.4414
Ieighth =7.4104
Isixteenth =7.4026
Ithirtysecond =7.4026
I1 =7.4517
I2 =7.4130
I3 =7.4026
I12 =7.4543
I23 =7.4137
I123 =7.4132
>>