0% found this document useful (0 votes)
25 views14 pages

Tugas 1

Uploaded by

rikommunity89
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views14 pages

Tugas 1

Uploaded by

rikommunity89
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Table of Contents

Materi 3,4 .......................................................................................................................... 1


Hal 6 ................................................................................................................................ 1
Hal 7 ................................................................................................................................ 1
Hal 9 ................................................................................................................................ 2
Hal 10 ............................................................................................................................... 5
Hal 21 ............................................................................................................................... 7
Hal 27 ............................................................................................................................... 8
Hal 28 ............................................................................................................................... 9
Hal 32 ............................................................................................................................. 10
Materi 5 ........................................................................................................................... 12
Hal 6 ............................................................................................................................... 12
Hal 11 ............................................................................................................................. 13

Nama : Riko Setiawan

NPM : 23310730034P

Program dijalankan menggunakan Matlab ver. 2014, R2014b

Materi 3,4
Hal 6
R=9:-2:-21

R =

Columns 1 through 13

9 7 5 3 1 -1 -3 -5 -7 -9 -11 -13 -15

Columns 14 through 16

-17 -19 -21

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 =

Empty matrix: 1-by-0

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

3.5000 4.0000 4.5000 5.0000

linspace (3,4,11)

ans =

Columns 1 through 7

3.0000 3.1000 3.2000 3.3000 3.4000 3.5000 3.6000

Columns 8 through 11

3.7000 3.8000 3.9000 4.0000

M=linspace(1,10)

M =

Columns 1 through 7

1.0000 1.0909 1.1818 1.2727 1.3636 1.4545 1.5455

Columns 8 through 14

1.6364 1.7273 1.8182 1.9091 2.0000 2.0909 2.1818

Columns 15 through 21

2.2727 2.3636 2.4545 2.5455 2.6364 2.7273 2.8182

Columns 22 through 28

2.9091 3.0000 3.0909 3.1818 3.2727 3.3636 3.4545

Columns 29 through 35

3.5455 3.6364 3.7273 3.8182 3.9091 4.0000 4.0909

Columns 36 through 42

4.1818 4.2727 4.3636 4.4545 4.5455 4.6364 4.7273

Columns 43 through 49

4.8182 4.9091 5.0000 5.0909 5.1818 5.2727 5.3636

Columns 50 through 56

3
5.4545 5.5455 5.6364 5.7273 5.8182 5.9091 6.0000

Columns 57 through 63

6.0909 6.1818 6.2727 6.3636 6.4545 6.5455 6.6364

Columns 64 through 70

6.7273 6.8182 6.9091 7.0000 7.0909 7.1818 7.2727

Columns 71 through 77

7.3636 7.4545 7.5455 7.6364 7.7273 7.8182 7.9091

Columns 78 through 84

8.0000 8.0909 8.1818 8.2727 8.3636 8.4545 8.5455

Columns 85 through 91

8.6364 8.7273 8.8182 8.9091 9.0000 9.0909 9.1818

Columns 92 through 98

9.2727 9.3636 9.4545 9.5455 9.6364 9.7273 9.8182

Columns 99 through 100

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

0 0.0505 0.1010 0.1515 0.2020 0.2525 0.3030

Columns 8 through 14

0.3535 0.4040 0.4545 0.5051 0.5556 0.6061 0.6566

Columns 15 through 21

0.7071 0.7576 0.8081 0.8586 0.9091 0.9596 1.0101

Columns 22 through 28

4
1.0606 1.1111 1.1616 1.2121 1.2626 1.3131 1.3636

Columns 29 through 35

1.4141 1.4646 1.5152 1.5657 1.6162 1.6667 1.7172

Columns 36 through 42

1.7677 1.8182 1.8687 1.9192 1.9697 2.0202 2.0707

Columns 43 through 49

2.1212 2.1717 2.2222 2.2727 2.3232 2.3737 2.4242

Columns 50 through 56

2.4747 2.5253 2.5758 2.6263 2.6768 2.7273 2.7778

Columns 57 through 63

2.8283 2.8788 2.9293 2.9798 3.0303 3.0808 3.1313

Columns 64 through 70

3.1818 3.2323 3.2828 3.3333 3.3838 3.4343 3.4848

Columns 71 through 77

3.5354 3.5859 3.6364 3.6869 3.7374 3.7879 3.8384

Columns 78 through 84

3.8889 3.9394 3.9899 4.0404 4.0909 4.1414 4.1919

Columns 85 through 91

4.2424 4.2929 4.3434 4.3939 4.4444 4.4949 4.5455

Columns 92 through 98

4.5960 4.6465 4.6970 4.7475 4.7980 4.8485 4.8990

Columns 99 through 100

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

0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000

Columns 8 through 14

0.7000 0.8000 0.9000 1.0000 1.1000 1.2000 1.3000

Columns 15 through 21

1.4000 1.5000 1.6000 1.7000 1.8000 1.9000 2.0000

Y=logspace (0,2,21)

Y =

Columns 1 through 7

1.0000 1.2589 1.5849 1.9953 2.5119 3.1623 3.9811

Columns 8 through 14

5.0119 6.3096 7.9433 10.0000 12.5893 15.8489 19.9526

Columns 15 through 21

25.1189 31.6228 39.8107 50.1187 63.0957 79.4328 100.0000

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 =

0.5000 2.0000 1.5000


4.0000 1.6667 3.0000

E=A.\B

E =

2.0000 0.5000 0.6667


0.2500 0.6000 0.3333

A.^2

ans =

1 4 9
16 25 36

Kesimpulan : hasilnya matrik A yang di pangkat 2

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 =

1 -16 26 424 -1155

Hal 28
c=roots([1,5,6])

c =

-3.0000
-2.0000

soal no.1

roots ([-1, 3, 1, -12])

ans =

2.3533 + 1.2223i
2.3533 - 1.2223i
-1.7065 + 0.0000i

soal no.2

roots ([3, 0, 4, -7])

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

-3.0000 -2.9000 -2.8000 -2.7000 -2.6000 -2.5000 -2.4000

Columns 8 through 14

-2.3000 -2.2000 -2.1000 -2.0000 -1.9000 -1.8000 -1.7000

Columns 15 through 21

-1.6000 -1.5000 -1.4000 -1.3000 -1.2000 -1.1000 -1.0000

Columns 22 through 28

-0.9000 -0.8000 -0.7000 -0.6000 -0.5000 -0.4000 -0.3000

Columns 29 through 35

-0.2000 -0.1000 0 0.1000 0.2000 0.3000 0.4000

Columns 36 through 42

0.5000 0.6000 0.7000 0.8000 0.9000 1.0000 1.1000

Columns 43 through 49

1.2000 1.3000 1.4000 1.5000 1.6000 1.7000 1.8000

Columns 50 through 56

1.9000 2.0000 2.1000 2.2000 2.3000 2.4000 2.5000

Columns 57 through 63

2.6000 2.7000 2.8000 2.9000 3.0000 3.1000 3.2000

Columns 64 through 70

3.3000 3.4000 3.5000 3.6000 3.7000 3.8000 3.9000

10
Columns 71 through 77

4.0000 4.1000 4.2000 4.3000 4.4000 4.5000 4.6000

Columns 78 through 84

4.7000 4.8000 4.9000 5.0000 5.1000 5.2000 5.3000

Columns 85 through 91

5.4000 5.5000 5.6000 5.7000 5.8000 5.9000 6.0000

b=polyval(a,x)

b =

Columns 1 through 7

-80.0000 -73.5490 -67.3920 -61.5230 -55.9360 -50.6250 -45.5840

Columns 8 through 14

-40.8070 -36.2880 -32.0210 -28.0000 -24.2190 -20.6720 -17.3530

Columns 15 through 21

-14.2560 -11.3750 -8.7040 -6.2370 -3.9680 -1.8910 0

Columns 22 through 28

1.7110 3.2480 4.6170 5.8240 6.8750 7.7760 8.5330

Columns 29 through 35

9.1520 9.6390 10.0000 10.2410 10.3680 10.3870 10.3040

Columns 36 through 42

10.1250 9.8560 9.5030 9.0720 8.5690 8.0000 7.3710

Columns 43 through 49

6.6880 5.9570 5.1840 4.3750 3.5360 2.6730 1.7920

Columns 50 through 56

0.8990 0 -0.8990 -1.7920 -2.6730 -3.5360 -4.3750

Columns 57 through 63

-5.1840 -5.9570 -6.6880 -7.3710 -8.0000 -8.5690 -9.0720

11
Columns 64 through 70

-9.5030 -9.8560 -10.1250 -10.3040 -10.3870 -10.3680 -10.2410

Columns 71 through 77

-10.0000 -9.6390 -9.1520 -8.5330 -7.7760 -6.8750 -5.8240

Columns 78 through 84

-4.6170 -3.2480 -1.7110 0 1.8910 3.9680 6.2370

Columns 85 through 91

8.7040 11.3750 14.2560 17.3530 20.6720 24.2190 28.0000

plot (x,b), title('grafik polynomial'), grid, xlabel('X')

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

You might also like