0% found this document useful (0 votes)
18 views

Matlab Kel8

The document discusses various methods of defining, manipulating, and operating on arrays in MATLAB. It shows how to: 1) Define arrays using vectors, ranges, and the linspace function. 2) Access elements and subsets of arrays using indexing and slicing operations. 3) Perform basic arithmetic operations on arrays and between arrays and scalars. 4) Construct arrays and combine them using concatenation. 5) Handle both row and column orientations of arrays through transposition.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Matlab Kel8

The document discusses various methods of defining, manipulating, and operating on arrays in MATLAB. It shows how to: 1) Define arrays using vectors, ranges, and the linspace function. 2) Access elements and subsets of arrays using indexing and slicing operations. 3) Perform basic arithmetic operations on arrays and between arrays and scalars. 4) Construct arrays and combine them using concatenation. 5) Handle both row and column orientations of arrays through transposition.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Menyatakan Array

Contoh 2.1:

A = [-15 -10 -5 0 1] %array A mempunyai 5 anggota.

Contoh 2.2:

x=[-5 -4 -3 -2 -1 0 1 2 3 4 5 6]

x= -5 -4 -3 -2 -1 0 1 2 3 4 5 6

y=2*x+3

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

Pengalamatan Array

Contoh 2.3:

x=[-5 -4 -3 -2 -1 0 1 2 3 4 5 6]

x= -5 -4 -3 -2 -1 0 1 2 3 4 5 6

y=2*x+3

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

x(5) %anggota kelima dari x

Ans= -1

y(10) %anggota kesepuluh dari y

Ans=11

Anggota array range terterntu

Contoh 2.4:

x(2:7) %menampilkan anggota ke 2 sampai ke 7 dari x

Ans= -4 -3 -2 -1 0 1

y(6:11) %menampilkan anggota ke 6 sampai ke 11 dari y


Ans= 3 5 7 9 11 13

Contoh 2.5:

x(5:2:12) %anggota 5,7,……,11 dari array x

Ans= -1 1 3 5

x(12:-1:5) %anggota ke 12,11,….,5 dari array y

Ans= 15 13 11 9 7 5 3 1

Mengkonstruksi array

Contoh 2.6:

x=(-5:1:6) %mengkonstruksi x,dengan nilai -5, -4, … ,6.

X= -5 -4 -3 -2 -1 0 1 2 3 4 5 6

Contoh 2.7:

Pecah= (0.5:-0.75:-2.5)) %mengkonstruksi array pecah

Pecah= 0.5000 -0.2500 -1.0000 -1.7500 -2.5000

Array linspace

Contoh 2.8:

Pecah=linspace(0.5,-2.5,5)

Pecah= 0.5000 -0.2500 -1.0000 -1.7500 -2.5000

X=linspace(-5,6,12)

X= -5 -4 -3 -2 -1 0 1 2 3 4 5 6

Contoh 2.9:

P=(-3:1.5:4.5)

P= -3.0000 -1.5000 0 1.5000 3.0000 4.5000


q=linspace(-1,5,5)

q=-1.0000 0.5000 2.0000 3.5000 5.0000

r=[p q] %array r berdasarkan array p dan q

r= columns 1 through 7

-3.0000 -1.5000 0 1.5000 3.0000 4.5000 1.0000

Columns 8 through 11

0.5000 2.0000 3.5000 5.0000

Contoh 2.10:

a= (5:-2:-1)

a= -5 3 1 -1

b= linspace(2,4,5)

b= 2.0000 2.5000 3.0000 3.5000 4.0000

array c gabungan array a dan anggota ke 1,3 dan 5 dari b

c=[a b(1:2:5)]

c= 5 3 1 -1 2 3 4

operasi scalar dengan array

contoh 2.11:

k=5;

a=[-1 2 1 3];

k+a

ans= 4 7 6 8

a+k

ans=4 7 6 8

a-k
ans=-6 -3 -4 -2

k-a

ans=6 3 4 2

k*a

ans= -5 10 5 15

a*k

ans= -5 10 5 15

a/k

ans= -0.2000 0.4000 0.2000 0.6000

k./a

ans= -5.0000 2.5000 5.0000 1.6667

a.^k

ans=-1 32 1 243

k.^a

ans= 0.2000 25.0000 5.0000 125.0000

contoh 2.12:

p=[2 -1 3 1];

q=[1 5 0 -2];

p+q

ans= 3 4 3 -1

q-p

ans= -1 6 -3 -3

p.*q

ans= 2 -5 0 -2
q.*p

ans= 2 -5 0 -2

p./q

warning: divide by zero.

Ans= 2.0000 -0.2000 inf -0.5000

q./p

ans= 0.5000 -50000 0 -2.0000

p.^q

ans= 2 -1 1 1

q.^p

ans= 1.0000 0.2000 0 -2.0000

Orientasi Array

Contoh 2.13:

x= [-2;3;4;5;1]

x=

-2

Contoh 2.14:

a=(-2:3:7) %array baris a

a= -2 1 4 7

b=a’ %array kolom b dari transpose array a


b=

-2

Contoh 2.15:

x= [2-5i 7 -3+2i -9i 4+8i];

z=x.’ %array z= dot-transpose dari array x

z=

2.0000 – 5.0000i

7.0000

-3.0000 + 8.0000i

y=x’ % array y= transpose dari array x

y=

2.0000 + 5.0000i

7.0000

-3.0000 – 2.0000i

0+9.0000i

4.0000-8.0000i

Contoh 2.16:

B=[-1 0 3 5;2 4 1 -3;7 9 -8 6]

B=

-1 0 3 5

2 4 1 -3
7 9 -8 6

Contoh 2.17:

B= [-1,0,3,5;2,4,1,-3;7,9,-8,6]

B=

-1 0 3 5

2 4 1 -3

7 9 -8 6

You might also like