Bab 3 Grafik

You might also like

You are on page 1of 21

Nama : Dona Alvionita Putri

Nim : 208180006
Kelas : Tadris Matematika (4A)
Makul : Algoritma dan Pemograman

TUGAS PRAKTEK HAL 22-35


 Praktek 1
Gambarkan fungsi y = 2 sin 2t pada rentangan (0,2π)
Jawab :

>> t=0:0.01:2*pi ;
>> y=2*sin(2.*t) ;
>> plot(t,y)

1.5

0.5

-0.5

-1

-1.5

-2
0 1 2 3 4 5 6 7

 Praktek 2

>> t=0:0.01:2*pi;
>> y=2*sin(2.*t);
>> plot(t,y)
>> grid
>> ylabel ('fungsiy')
>> xlabel ('waktu')
>> title ('fungsi sinus')

fungsi sinus
2

1.5

0.5
fungsiy

-0.5

-1

-1.5

-2
0 1 2 3 4 5 6 7
waktu

 Praktek 3

>> t=0:0.01:2*pi;
>> y1=2*sin(2.*t);
>> y2=1.5*sin(2.*t+pi/3);
>> plot(t,y1,'r-',t,y2,'k-')
>> grid
2

1.5

0.5

-0.5

-1

-1.5

-2
0 1 2 3 4 5 6 7

 Praktek 4

>> t=0:0.01:2*pi;
>> y1=2*sin(2.*t);
>> y2=1.5*sin(2.*t+pi/3);
>> plot(t,y1,'r-',t,y2,'k-')
>> grid
>> hold on
>> plot(2.*t,2.*y1)
4

-1

-2

-3

-4
0 2 4 6 8 10 12 14

 Praktek 5

>> q=[1 1 1 2; 2 3 4 5; 3 4 5 6; 4 5 6 7]

q=

1 1 1 2
2 3 4 5
3 4 5 6
4 5 6 7

>> q(:,1)

ans =

1
2
3
4

>> q(:,2)
ans =

1
3
4
5

>> plot(q)
>> grid

1
1 1.5 2 2.5 3 3.5 4

 Praktek 6

>> clf
>> clear
>> t=0:0.01:4*pi;
>> y1=2*sin(2.*t);
>> y2=1.5*sin(2.*t+pi/3);
>> plot(t,y1,t,y2,'linewidth',1)
>> grid
2

1.5

0.5

-0.5

-1

-1.5

-2
0 2 4 6 8 10 12 14

 Praktek 7

Buatlah tabel dari fungsi berikut


y1 = 2 sin 4t
y2 = 1.2sin(2t+π/3)
y3= 5sin(5t+π/2)
y4= y1+y2+y3

Jawab :

>> clf
>> clear
>> t=0:0.1:2*pi;
>> y1=2*sin(4*t);
>> y2=1.2*sin(2*t+pi/3);
>> y3=5*sin(5*t+pi/2);
>> y4=y1+y2+y3;
>> disp(['t y1 y2 y3 y4 '])
t y1 y2 y3 y4
>> [y1.' y2.' y3.' y4.']

ans =
0 1.0392 5.0000 6.0392
0.7788 1.1377 4.3879 6.3045
1.4347 1.1908 2.7015 5.3271
1.8641 1.1965 0.3537 3.4143
1.9991 1.1545 -2.0807 1.0729
1.8186 1.0664 -4.0057 -1.1207
1.3509 0.9358 -4.9500 -2.6632
0.6700 0.7679 -4.6823 -3.2444
-0.1167 0.5694 -3.2682 -2.8156
-0.8850 0.3482 -1.0540 -1.5908
-1.5136 0.1131 1.4183 0.0178
-1.9032 -0.1265 3.5433 1.5137
-1.9923 -0.3610 4.8009 2.4475
-1.7669 -0.5812 4.8829 2.5348
-1.2625 -0.7782 3.7695 1.7288
-0.5588 -0.9442 1.7332 0.2302
0.2331 -1.0725 -0.7275 -1.5669
0.9882 -1.1581 -3.0101 -3.1799
1.5873 -1.1975 -4.5557 -4.1658
1.9358 -1.1891 -4.9859 -4.2391
1.9787 -1.1334 -4.1954 -3.3500
1.7092 -1.0324 -2.3777 -1.7009
1.1698 -0.8904 0.0221 0.3016
0.4458 -0.7128 2.4165 2.1495
-0.3487 -0.5068 4.2193 3.3638
-1.0880 -0.2806 4.9890 3.6204
-1.6557 -0.0432 4.5372 2.8384
-1.9619 0.1959 2.9746 1.2087
-1.9584 0.4272 0.6837 -0.8474
-1.6457 0.6415 -1.7746 -2.7788
-1.0731 0.8302 -3.7984 -4.0414
-0.3312 0.9858 -4.8923 -4.2377
0.4630 1.1021 -4.7883 -3.2232
1.1841 1.1744 -3.5120 -1.1534
1.7183 1.2000 -1.3758 1.5425
1.9812 1.1777 1.0972 4.2561
1.9313 1.1084 3.3016 6.3413
1.5765 0.9950 4.6976 7.2691
0.9728 0.8419 4.9435 6.7582
0.2155 0.6552 3.9791 4.8498
-0.5758 0.4424 2.0404 1.9070
-1.2762 0.2120 -0.3978 -1.4621
-1.7751 -0.0269 -2.7386 -4.5407
-1.9938 -0.2647 -4.4090 -6.6675
-1.8977 -0.4920 -4.9998 -7.3895
-1.5020 -0.6996 -4.3665 -6.5681
-0.8691 -0.8794 -2.6642 -4.4126
-0.0991 -1.0240 -0.3095 -1.4326
0.6866 -1.1279 2.1209 1.6796
1.3639 -1.1868 4.0320 4.2092
1.8259 -1.1984 4.9560 5.5835
1.9996 -1.1622 4.6666 5.5039
1.8576 -1.0797 3.2346 4.0125
1.4223 -0.9541 1.0107 1.4789
0.7625 -0.7905 -1.4607 -1.4887
-0.0177 -0.5954 -3.5744 -4.1875
-0.7951 -0.3765 -4.8130 -5.9847
-1.4470 -0.1427 -4.8732 -6.4629
-1.8704 0.0969 -3.7403 -5.5138
-1.9986 0.3326 -1.6916 -3.3576
-1.8112 0.5550 0.7713 -0.4849
-1.3378 0.7553 3.0453 2.4628
-0.6533 0.9255 4.5737 4.8460

 Praktek 8

Buatlah gambar yang terdiri dari 4 buah grafik berdasarkan contoh soal
sebelumnya,

Jawab :

>> clf
>> clear
>> t=0:0.1:2*pi;
>> y1=2*sin(4*t);
>> y2=1.2*sin(2*t+pi/3);
>> y3=5*sin(5*t+pi/2);
>> y4=y1+y2+y3 ;
Subplot
>> subplot(221)
>> plot(t,y1)
2

-1

-2
0 2 4 6 8

>> subplot(224)
>> plot(t,y4)
Maka akan muncul
2

-1

-2
0 2 4 6 8

10

-5

-10
0 2 4 6 8

Kemudian jika kita tuliskan dalam MATLAB akan menjadi :


>> subplot(222)
>> plot(t,y2)
>> subplot(223)
>> plot(t,y3)
Sehingga akan muncul
2 2

1 1

0 0

-1 -1

-2 -2
0 2 4 6 8 0 2 4 6 8

5 10

0 0

-5

-5 -10
0 2 4 6 8 0 2 4 6 8

 Praktek 9

>> clf
>> figure(1)
>> subplot(121)
>> plot(t,y1)
>> subplot(122)
>> plot(t,y2)
Sehingga akan muncul
2 1.5

1.5
1

0.5
0.5

0 0

-0.5
-0.5

-1

-1
-1.5

-2 -1.5
0 2 4 6 8 0 2 4 6 8

Kemudian masukan :
>> figure(2)
>> subplot(121)
>> plot(t,y3)
>> axis([0 2*pi -6 6])
>> grid
>> ylabel('y3')
>> xlabel('t')
>> subplot(122)
>> plot(t,y4)
>> axis([0 2*pi -9 9])
>> ylabel('y4')
>> xlabel('t')
>> grid
Maka akan muncul
6
8

4 6

4
2
2
y3

y4
0 0

-2
-2
-4

-4 -6

-8
-6
0 2 4 6 0 2 4 6
t t

 Praktek 10

>> clf
>> t=0:0.1:2*pi;
>> y1=cos(2.*t);
>> y2=sin(2.*t);
>> plot3(y1,y2,t)
>> grid
8

0
1
0.5 1
0 0.5
0
-0.5
-0.5
-1 -1

Kita dapat merotasikan grafik dengan perintah


>> rotate3d
Kemudian dengan menggunakan mouse, kita dapat merotasikan grafik sehingga
diperoleh hasil seperti ini
7

0
1
0 1
0 0.5
-1 -1 -0.5

Atau

0
1

0.5

-0.5

0.5 1
-1 0
-1 -0.5
 Praktek 11

Buatlah grafik dari fungsi x,y berikut :

>> [x,y]=meshgrid(1:4)

x=

1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4

y=

1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4

Kemudian kita masukan persamaan z = √ x 2+ y 2 pada MATLAB.

>> z=sqrt(x.^2+y.^2)

z=

1.4142 2.2361 3.1623 4.1231


2.2361 2.8284 3.6056 4.4721
3.1623 3.6056 4.2426 5.0000
4.1231 4.4721 5.0000 5.6569
Lalu gambarkan dalam MATLAB dengan perintah
>> mesh(x,y,z)
6

1
4
4
3
3
2
2
1 1

Selanjutnya, kita akan mengembangkannya dengan menambahkan input.


>> [x,y]=meshgrid(-20:20);
>> z=sqrt(x.^2+y.^2);
>> mesh(x,y,z)
30

25

20

15

10

0
20
10 20
0 10
0
-10
-10
-20 -20

Kita juga dapat melanjutkan dengan perintah MATLAB berikut


>> [x,y,z]=peaks;
>> colormap(gray)
30

25

20

15

10

0
20
10 20
0 10
0
-10
-10
-20 -20

 Praktek 12

Buatlah grafik polar dari fungsi berikut

>> t=0:.01:2*pi;
>> y=2.*ones(size(t));
>> polar(t,y,'r-')
>> axis([-pi pi -2.1 2.1])
>> axis on
90 2
2 120 60
1.5
1.5

150 1 30
1
0.5
0.5

0 180 0

-0.5

-1
210 330

-1.5

-2 240 300
270
-3 -2 -1 0 1 2 3

 Praktek 13

>> clear
>> clf
>> w=0:0.1:1000;
>> g=20.*sqrt(1+(0.1.*w).^2)./w;
>> semilogx(w,g,'linewidth',2)
>> axis ([0 1000 -10 210])
>> grid
>> axis([0 1000 -10 210])
>> grid
200

180

160

140

120

100

80

60

40

20

10 -1 10 0 101 102 103

You might also like