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

Unit 1 (19092011)

This document contains examples of using MATLAB for basic computations and operations on arrays and matrices. Some key points: 1) It shows basic arithmetic operations in MATLAB like addition, subtraction, multiplication, and division of scalars. 2) It demonstrates operations on complex numbers like retrieving the real and imaginary parts, absolute value, angle, and conjugate. 3) It provides examples of common mathematical functions in MATLAB like trigonometric, exponential, logarithmic, and rounding functions. 4) It shows how to create arrays using functions like linspace and logspace, access elements of arrays, perform element-wise and matrix operations on arrays and matrices, and get the size and dimensions of matrices.

Uploaded by

Mas Nyam
Copyright
© Attribution Non-Commercial (BY-NC)
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)
17 views

Unit 1 (19092011)

This document contains examples of using MATLAB for basic computations and operations on arrays and matrices. Some key points: 1) It shows basic arithmetic operations in MATLAB like addition, subtraction, multiplication, and division of scalars. 2) It demonstrates operations on complex numbers like retrieving the real and imaginary parts, absolute value, angle, and conjugate. 3) It provides examples of common mathematical functions in MATLAB like trigonometric, exponential, logarithmic, and rounding functions. 4) It shows how to create arrays using functions like linspace and logspace, access elements of arrays, perform element-wise and matrix operations on arrays and matrices, and get the size and dimensions of matrices.

Uploaded by

Mas Nyam
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 14

UNIT 1

1. Operator Komputasi
>> A=10;
>> B=5;
>> A+B
ans =
15
>> A-B
ans =
5
>> A*B
ans =
50
>> A/B
ans =
2
>> B\A
ans =
2
>> A^B
ans =
100000

2. Bilangan Kompleks
>> a=4+3i;
>> real(a)
ans =
4
>> imag (a)
ans =
3
>> abs (a)
ans =
5
>> angle (a)
ans =
0.6435
>> conj (a)
ans =
4.0000 - 3.0000i
3. Fungsi Matematis
>> x=pi/3
x=
1.0472
>> a=0.01
a=

0.0100
>> acos (a)
ans =
1.5608
>> acosh (a)
ans =
0 + 1.5608i
>> asin (a)
ans =
0.0100
>> atan (a)
ans =
0.0100
>> ceil(x)
ans =
2
>> exp(x)
ans =
2.8497
>> cos (x)
ans =

0.5000
>> fix(x)
ans =
1
>> floor(x)
ans =
1
>> log(x)
ans =
0.0461
>> log10(x)
ans =
0.0200
>> rem(x,a)
ans =
0.0072
>> round(x)
ans =
1
>> sin(x)
ans =

0.8660
>> sqrt(x)
ans =
1.0233
>> tan(x)
ans =
1.7321
4. Variable
>> p=10;
>> l=5;
>> L=p*l
L=
50
UNIT 2
1. Pembentukan Aray
>> x=(0:0.1:1) *pi
x=
Columns 1 through 5
0 0.3142 0.6283 0.9425 1.2566
Columns 6 through 10
1.5708 1.8850 2.1991 2.5133 2.8274
Column 11
3.1416

>> x=linspace(0,pi,11)
x=
Columns 1 through 5
0 0.3142 0.6283 0.9425 1.2566
Columns 6 through 10
1.5708 1.8850 2.1991 2.5133 2.8274
Column 11
3.1416
>> M=logspace(0,2,11)
M=
Columns 1 through 5
1.0000 1.5849 2.5119 3.9811 6.3096
Columns 6 through 10
10.0000 15.8489 25.1189 39.8107 63.0957
Column 11
100.0000
>> x=[2 2*pi sqrt(2) 2-3j]
x=
Columns 1 through 2
2.0000

6.2832

Columns 3 through 4
1.4142

2.0000 - 3.0000i

2. Pengalamatan Elemen (Aray)


>> x=[0 2 4 6 8 10 12 14 16 18 20];
>> y=[1 3 5 7 9 11 13 15 17 19 21];
>> x(7)
ans =
12
>> y(4)
ans =
7
>> y(10:-1:2)
ans =
Columns 1 through 8
19 17 15 13 11
Column 9
3
>> x(2:6)
ans =
2

8 10

>> y(1:2:8)
ans =
1

9 13

>> x(1:3:10)

ans =
0

6 12 18

>> y^2
??? Error using ==> mpower
Matrix must be square.
>> y.^2
ans =
Columns 1 through 8
1

9 25 49 81 121 169 225

Columns 9 through 11
289 361 441
>> x.^2
ans =
Columns 1 through 8
0

4 16 36 64 100 144 196

Columns 9 through 11
256 324 400
>> y./2
ans =
Columns 1 through 5
0.5000 1.5000 2.5000 3.5000 4.5000
Columns 6 through 10

5.5000 6.5000 7.5000 8.5000 9.5000


Column 11
10.5000
>> A=[1 2 3;4 5 6;7 8 9];
>> A(2,3)
ans =
6
>> A(1,:)
ans =
1

>> A(2,:)
ans =
4

>> A(:,3)
ans =
3
6
9
3. Matematika Aray
>> a=[2 4 3 5 7]
a=
2

>> b=[1 2 3 4 5]'


b=
1
2
3
4
5
>> c=a+5
c=
7

8 10 12

>> d=a+b
??? Error using ==> plus
Matrix dimensions must agree.
>> e=b-2
e=
-1
0
1
2
3
>> f=b*3
f=
3
6
9
12
15
>> g=b/2

g=
0.5000
1.0000
1.5000
2.0000
2.5000
>> h=a./b
??? Error using ==> rdivide
Matrix dimensions must agree.
>> h=a/b
??? Error using ==> mrdivide
Matrix dimensions must agree.
>> k=a.\b
??? Error using ==> ldivide
Matrix dimensions must agree.
>> x=a*b
x=
74
>> y=b*a
y=
2
4
6
8
10

4
8
12
16
20

3 5 7
6 10 14
9 15 21
12 20 28
15 25 35

>> z=a.*b
??? Error using ==> times
Matrix dimensions must agree.

4. Matriks
>> m_eye = eye(4)
m_eye =
1
0
0
0

0
1
0
0

0
0
1
0

0
0
0
1

>> m_rand = rand(3,4)


m_rand =
0.8147 0.9134 0.2785 0.9649
0.9058 0.6324 0.5469 0.1576
0.1270 0.0975 0.9575 0.9706
>> m_ones = ones(4,4)
m_ones =
1
1
1
1

1
1
1
1

1
1
1
1

1
1
1
1

>> m_zeros = zeros(3)


m_zeros =
0 0 0
0 0 0
0 0 0
Contoh :
>> A=[1 2 3;4 5 6;7 8 0]
A=
1
4
7

2
5
8

3
6
0

>> b=[366;804;351]
b=
366
804
351
>> det(A)
ans =
27
>> x=inv(A)*b
x=
25.0000
22.0000
99.0000
>> x=A\b
x=
25.0000
22.0000
99.0000
5. Ukuran Aray
>> A=[1 2 3 4;5 6 7 8]
A=
1
5

2
6

3
7

4
8

>> s=size(A)
s=
2

>> [r,c]=size(A)
r=
2

c=
4
>> r=size(A,1)
r=
2
>> c=size(A,2)
c=
4
>> length(A)
ans =
4

You might also like