Tugas 1
Tugas 1
NPM : 23310730034P
Materi 3,4
Hal 6
R=9:-2:-21
R =
Columns 1 through 13
Columns 14 through 16
U=0:-10:-100
U =
0 -10 -20 -30 -40 -50 -60 -70 -80 -90 -100
Hal 7
h= 0:2:11
1
h =
0 2 4 6 8 10
Kesimpulan : Tidak terjadi error, namun hasil deret angkanya tidak sesuai. karena ketidaksesuaian antar
nilai awal, step, dan nilai akhir
i= -3:10
i =
Columns 1 through 13
-3 -2 -1 0 1 2 3 4 5 6 7 8 9
Column 14
10
Kesimpulan : Karena nilai step tidak ditentukan, deret angka dari -3 sampai -10 secara default menggu-
nakan step +1
j= 10:-3
j =
Kesimpulan : Tidak terjadi error, muncul keterangan "Empty matrix: 1-by-0", dikarenakan ketidaksesuain
antara nilai awal, step, dan nilai akhir. nilai awal 10, step tidak ditentukan maka secara default step menjadi
+1, sedangkan nilai akhir -3. Maka secara aritmatika tidak sesuai.
Hal 9
linspace (0,100,11)
ans =
0 10 20 30 40 50 60 70 80 90 100
linspace (0,5,11)
ans =
Columns 1 through 7
2
0 0.5000 1.0000 1.5000 2.0000 2.5000 3.0000
Columns 8 through 11
linspace (3,4,11)
ans =
Columns 1 through 7
Columns 8 through 11
M=linspace(1,10)
M =
Columns 1 through 7
Columns 8 through 14
Columns 15 through 21
Columns 22 through 28
Columns 29 through 35
Columns 36 through 42
Columns 43 through 49
Columns 50 through 56
3
5.4545 5.5455 5.6364 5.7273 5.8182 5.9091 6.0000
Columns 57 through 63
Columns 64 through 70
Columns 71 through 77
Columns 78 through 84
Columns 85 through 91
Columns 92 through 98
9.9091 10.0000
Kesimpulan : Karena jumlah elemen tidak ditentukan, maka program secara default membuat vector baris
dari 1 sampai 10 sejumlah 100
N=linspace(0,5)
N =
Columns 1 through 7
Columns 8 through 14
Columns 15 through 21
Columns 22 through 28
4
1.0606 1.1111 1.1616 1.2121 1.2626 1.3131 1.3636
Columns 29 through 35
Columns 36 through 42
Columns 43 through 49
Columns 50 through 56
Columns 57 through 63
Columns 64 through 70
Columns 71 through 77
Columns 78 through 84
Columns 85 through 91
Columns 92 through 98
4.9495 5.0000
Kesimpulan : Karena jumlah elemen tidak ditentukan, maka program secara default membuat vector baris
dari 0 sampai 5 sejumlah 100
Hal 10
X=linspace (0,2,21)
5
X =
Columns 1 through 7
Columns 8 through 14
Columns 15 through 21
Y=logspace (0,2,21)
Y =
Columns 1 through 7
Columns 8 through 14
Columns 15 through 21
plot (X,Y,'-o')
6
Hal 21
r=[1,2,3];
s=[4,5,6];
A=[r;s]
A =
1 2 3
4 5 6
t=[2,1,2];
u=[1,3,2];
B=[t;u]
B =
2 1 2
1 3 2
C=A.*B
7
C =
2 2 6
4 15 12
D=A./B
D =
E=A.\B
E =
A.^2
ans =
1 4 9
16 25 36
2.^A
ans =
2 4 8
16 32 64
Kesimpulan : hasilnya matrik dari nilai 2 dipangkatkan nilai yang ada di matrik A
Hal 27
y=poly([-1,2,5])
y =
1 -6 3 10
p1 = poly([-3, 4])
8
p1 =
1 -1 -12
p2 = poly([-2, 0, 4])
p2 =
1 -2 -8 0
p3 = poly([-5, 3, 7, 11])
p3 =
Hal 28
c=roots([1,5,6])
c =
-3.0000
-2.0000
soal no.1
ans =
2.3533 + 1.2223i
2.3533 - 1.2223i
-1.7065 + 0.0000i
soal no.2
ans =
-0.5000 + 1.4434i
-0.5000 - 1.4434i
1.0000 + 0.0000i
9
Hal 32
a=[1,-6,3,10]
a =
1 -6 3 10
x=-3:0.1:6
x =
Columns 1 through 7
Columns 8 through 14
Columns 15 through 21
Columns 22 through 28
Columns 29 through 35
Columns 36 through 42
Columns 43 through 49
Columns 50 through 56
Columns 57 through 63
Columns 64 through 70
10
Columns 71 through 77
Columns 78 through 84
Columns 85 through 91
b=polyval(a,x)
b =
Columns 1 through 7
Columns 8 through 14
Columns 15 through 21
Columns 22 through 28
Columns 29 through 35
Columns 36 through 42
Columns 43 through 49
Columns 50 through 56
Columns 57 through 63
11
Columns 64 through 70
Columns 71 through 77
Columns 78 through 84
Columns 85 through 91
Materi 5
Hal 6
soal no 1
12
s=0;
for i = 1:1000
s = s + i^2;
end
disp('hasilnya:')
display(s);
hasilnya:
s =
333833500
soal no 2
N = 1003;
s=0;
ganjil = 1./(1:2:N);
tanda = (-1).^(0:numel(ganjil)-1);
s = sum(ganjil.*tanda);
disp('hasilnya:')
display(s)
hasilnya:
s =
0.7849
Hal 11
r = rand;
d = floor(10*rand);
display(d);
d =
switch d
case {2, 4, 6, 8}
disp('genap'); % Muncul ket. genap jika angka random genap
case {1, 3, 5, 7, 9}
disp('ganjil'); % Muncul ket. ganjil jika angka random ganjil
otherwise
disp('zero'); % Muncul ket. genap jika angka random 0
end
ganjil
13
Published with MATLAB® R2014b
14