You are on page 1of 8

MATHLAB

A. 1.1 Memulai Matlab


>> a = 1+6
a=7

>> g = cos (3*pi/4)


g = -0.7071
>> format long
>> g
g = -0.707106781186547
>> format bank
>> g
g = -0.71

1.2 Berbagai Karakter Spesial


>> y=2:1:5
y = 2.00

3.00

4.00

5.00

>> A = [123;456]
A = 123.00
456.00
>> B =[0:3:9]
B=0
3.00

6.00

>> A =[123;456]
A = 123.00
456.00
>> A=A'
A = 123.00

456.00

1.3 M-File

B. Bekerja dengan Matrik


>> zeros (3,3)
ans = 0
0
0
>> ones(3,3)
ans = 1.00

0
0
0

0
0
0

1.00

1.00

9.00

1.00
1.00

1.00
1.00

1.00
1.00

>> rand(3,3)
ans = 0.81
0.91
0.13

0.91
0.63
0.10

0.28
0.55
0.96

>> randn(3,3)
ans = 2.77
-1.35
3.03

0.73
-0.06
0.71

-0.20
-0.12
1.49

2.1 Fungsi Lain Dalam Matrik


>> a= [ 1 2 3 4 ; 4 5 6 7 ; 7 8 9 10 ; 5 6 7 8 ]
a = 1.00
2.00
3.00
4.00
4.00
5.00
6.00
7.00
7.00
8.00
9.00
10.00
5.00
6.00
7.00
8.00
>> sum(a)
ans = 17.00

21.00

25.00

29.00

>> diag(a)
ans = 1.00
5.00
9.00
8.00
>> a(2,3)
ans = 6.00
>> a(2,3)=10
a = 1.00
4.00
7.00
5.00

2.00
5.00
8.00
6.00

3.00
10.00
9.00
7.00

4.00
7.00
10.00
8.00

>> x=a
x = 1.00
4.00
7.00
5.00

2.00
5.00
8.00
6.00

3.00
10.00
9.00
7.00

4.00
7.00
10.00
8.00

2.00
5.00
8.00
6.00

3.00
10.00
9.00
7.00

4.00
7.00
10.00
8.00

>> x(5,5)=17
x = 1.00
4.00
7.00
5.00

0
0
0
0

2.2 Operasi Lain Dalam Matlab


2.2.1 Menghapus Kolom/Baris
>> a= [ 1 2 3 ; 4 5 6 ; 7 8 9 ]
a = 1.00
2.00
3.00
4.00
5.00
6.00
7.00
8.00
9.00
>> a(:,2)=[]
a = 1.00
4.00
7.00

3.00
6.00
9.00

>> a= [ 1 2 3 ; 4 5 6 ; 7 8 9 ]
a = 1.00
2.00
3.00
4.00
5.00
6.00
7.00
8.00
9.00
>> a(3,:)=[]
a = 1.00
4.00

2.00
5.00

3.00
6.00

2.2.2 Penjumlahan Matrik


>> a= [1 2 3; 4 5 6 ; 7 8 9]
a = 1.00
2.00
3.00
4.00
5.00
6.00
7.00
8.00
9.00
>> a+a'
ans = 2.00
6.00
10.00

6.00
10.00
14.00

10.00
14.00
18.00

2.2.3 Menentukan Determinasi Matrik


>> a= [ 41 2 3 ; 4 5 6 ; 7 8 9]
a = 41.00
2.00
3.00
4.00
5.00
6.00
7.00
8.00
9.00
>> det(a)
ans = -120.00

2.2.4 Invers Matrik


>> y= [1 2 3 ; 4 5 6 ; 7 5 4]
y = 1.00
2.00
3.00
4.00
5.00
6.00
7.00
5.00
4.00

17.00

>> inv(y)
ans = 3.33
-8.67
5.00

-2.33
5.67
-3.00

1.00
-2.00
1.00

2.2.5 Nilai eigen Dan Vektor eijen


>> a= [1 5 3 ; 4 5 8 ; 4 5 8]
a = 1.00
5.00
3.00
4.00
5.00
8.00
4.00
5.00
8.00
>> [V,D]=eig(a)
V = -0.93
0.37
0.26
0.66
0.26
0.66
D = -1.25
0
0

0
15.25
0

-0.85
-0.14
0.51
0
0
0

C. Polinomial
3.1 Representasi Matlab

>> p = [1 0 -2 -5];

3.2 Akar Polynomial


>> r = roots(p)
r = 2.0946
-1.0473 + 1.1359i
-1.0473 - 1.1359i
>> p2 = poly(r)
p2 = 1.0000 -0.0000 -2.0000 -5.0000

3.3 Karakteristik Polynomial

>> A = [1.2 3 -0.9; 5 1.75 6; 9 0 1];


>> poly(A)
ans = 1.0000 -3.9500 -1.8500 -163.2750

3.4 Evaluasi Polynomial


>> polyval(p,5)
ans = 110

>> X = [2 4 5; -1 0 3 ; 7 1 5];
>> Y = polyvalm(p,X)
Y = 377 179 439
111 81 136
490 253 639

3.5 Perkalian dan Pembagian

>> a = [1 2 3]; b = [4 5 6];


>> c = conv(a,b)
c = 4 13 28 27 18
>> [q,r] = deconv(c,a)
q=4
5
6
r=0
0
0
0
0
>> [q,r] = deconv (c,b)
q=1
2
3
r=0
0
0
0
0

3.6 Turunan Polynom

>> p = [1 0 -2 5];
>> q = polyder(p)
q=3
0 -2
>> a = [1 3 5];
>> b = [2 4 6];
>> c = polyder(a,b)
c = 8 30 56 38
>> [q,d] = polyder(a,b)
q = -2 -8 -2
d = 4 16 40 48 36

3.7 Pencocokan Kurva Polynomial


>> x = [1 2 3 4 5]; y = [5.5 43.1 128 290.7 498.4];
>> p = polyfit (x,y,3)
p = -0.1917 31.5821 -60.3262 35.3400
>> x2 = 1:5:5;
>> y2 = polyval(p,x2);
>> plot(x,y,'o',x2,y2), grid on

3.8 Ekspansi Fraksi Parsial

>> b = [-4 8];


>> a = [1 6 8];
>> [r,p,k] = residue(b,a)
r = -12
8
p = -4
-2
k = []
>> [b2,a2] = residue(r,p,k)
b2 = -4
8
a2 = 1
6
8
>> n = [2 5 3 6];
>> d = [1 6 11 6];
>> [r,p,k] = residue(n,d)
r = -6.0000
-4.0000
3.0000
p = -3.0000
-2.0000
-1.0000
k=2
>> [n,d] = residue(r,p,k)
n = 2.0000 5.0000 3.0000 6.0000
d = 1.0000 6.0000 11.0000 6.0000

D. Persamaan Differensial

>> y = dsolve('Dy = -a*y')


y = C2/exp(a*t)
>> y = dsolve('Dy = -a*y','y(0) = 1')
y = 1/exp(a*t)
>> y = dsolve('D2y-2*Dy-3*y=0')
y = C6*exp(3*t) + C7/exp(t)
>> y = dsolve('D2y-2*Dy-3*y=0','y(0)=0','y(1)=1')
y = 1/(exp(t)*(1/exp(1) - exp(3))) - exp(3*t)/(1/exp(1) - exp(3))
>> simple(y)
simplify: -(exp(1) - exp(4*t + 1))/(exp(t + 4) - exp(t))
radsimp: 1/(exp(t)*(1/exp(1) - exp(3))) - exp(3*t)/(1/exp(1) - exp(3))
simplify(100): (exp(1 - t)*(exp(4*t) - 1))/(exp(4) - 1)
combine(sincos): 1/(exp(t)*(1/exp(1) - exp(3))) - exp(3*t)/(1/exp(1) exp(3))
combine(sinhcosh): 1/(exp(t)*(1/exp(1) - exp(3))) - exp(3*t)/(1/exp(1) exp(3))
combine(ln): 1/(exp(t)*(1/exp(1) - exp(3))) - exp(3*t)/(1/exp(1) - exp(3))
factor: -(exp(1)*(exp(t) - 1)*(exp(t) + 1)*(exp(2*t) + 1))/(exp(t)*(1 exp(1))*(exp(1) + 1)*(exp(2) + 1))
expand: 1/(exp(t)*(1/exp(1) - exp(3))) - exp(3*t)/(1/exp(1) - exp(3))
combine: 1/(exp(t)*(1/exp(1) - exp(3))) - exp(3*t)/(1/exp(1) - exp(3))
rewrite(exp): 1/(exp(t)*(1/exp(1) - exp(3))) - exp(3*t)/(1/exp(1) - exp(3))
rewrite(sincos): - (cos(t*i) + sin(t*i)*i)/(cosh(3) - cosh(1) + sinh(1) +
sinh(3)) + (cos((-3)*t*i) + sin((-3)*t*i)*i)/(cosh(3) - cosh(1) +
sinh(1) + sinh(3))
rewrite(sinhcosh): (cosh(3*t) + sinh(3*t))/(cosh(3) - cosh(1) + sinh(1) +
sinh(3)) - (cosh(t) - sinh(t))/(cosh(3) - cosh(1) + sinh(1) +
sinh(3))
rewrite(tan): (tan(-(t*i)/2) + i)/((tan(-(t*i)/2) - i)*((tanh(1/2)*i - i)/
(tanh(1/2)*i + i) - (tanh(3/2)*i + i)/(tanh(3/2)*i - i))) (tan((3*t*i)/2) + i)/((tan((3*t*i)/2) - i)*((tanh(1/2)*i - i)/
(tanh(1/2)*i + i) - (tanh(3/2)*i + i)/(tanh(3/2)*i - i)))
mwcos2sin: - (- 2*sin((t*i)/2)^2 + sin(t*i)*i + 1)/(sinh(1) + sinh(3) 2*sinh(1/2)^2 + 2*sinh(3/2)^2) - (2*sin((3*t*i)/2)^2 +
sin(3*t*i)*i - 1)/(sinh(1) + sinh(3) - 2*sinh(1/2)^2 +
2*sinh(3/2)^2)
collect(t): 1/(exp(t)*(1/exp(1) - exp(3))) - exp(3*t)/(1/exp(1) - exp(3))
ans = (exp(1 - t)*(exp(4*t) - 1))/(exp(4) - 1)
>> pretty(y)
1
exp(3 t)
-------------------------- - --------------/ 1
\
1
exp(t) | ------ - exp(3) | ------ - exp(3)
\ exp(1)
/ exp(1)

You might also like