You are on page 1of 22

y = sin(x)

{#Undefined function or variable 'x'.


}#
%Tidak dapat dikerjakan karena x belum didefinisikan
x = sym('x')

x =

Y = sin(x)

Y =

sin(x)

y =(2*x^3)^-1

y =

1/(2*x^3)

syms a b c x
f =a*x^2+b*x^2

f =

a*x^2 + b*x^2

g = diff(f)

g =

2*a*x + 2*b*x

g_prime = diff(sqrt(3*x^2+2*x^5))

g_prime =

(10*x^4 + 6*x)/(2*(2*x^5 + 3*x^2)^(1/2))

w = sym('w')

w =

z = 3*cos(w)/sin(2*w/(w+1))

z =

(3*cos(w))/sin((2*w)/(w + 1))

t = sym('t')

t =

t
A = [3*sin(t) -cos(t^2); cos(2*t) -sin(t)]

A =

[ 3*sin(t), -cos(t^2)]
[ cos(2*t), -sin(t)]

ff = 2 x2 + 3 x - 5
ff = 2 x2 + 3 x - 5
|
{#Error: Unexpected MATLAB expression.
}#
ff = 2*x^2 + 3*x - 5

ff =

2*x^2 + 3*x - 5

gg = x^2 - x + 7

gg =

x^2 - x + 7

a = 1

a =

b = 3/2

b =

1.5000

fg = ff + gg

fg =

3*x^2 + 2*x + 2

gf = ff - gg

gf =

x^2 + 4*x - 12

ffg = ff .* gg

ffg =

(x^2 - x + 7)*(2*x^2 + 3*x - 5)

ffg = ff * gg

ffg =
(x^2 - x + 7)*(2*x^2 + 3*x - 5)

fgg = ff / gg

fgg =

(2*x^2 + 3*x - 5)/(x^2 - x + 7)

ffx = ff^(3*x)

ffx =

(2*x^2 + 3*x - 5)^(3*x)

f = sin (a - x)

f =

-sin(x - 1)

g = sin (b x^2)
g = sin (b x^2)
|
{#Error: Unexpected MATLAB expression.
}#
g = sin (b*x^2)

g =

sin((3*x^2)/2)

% Kesimpulan : Suatu fungsi dapat dikerjakan jika fungsi tersebut didefinisikan


terlebih dahulu. Penggunaan sym berfungsi untuk memperkenalkan variabel jika masih
belum terbentuk angka. diff digunakan untuk mendifferensialkan dan differensial
bisa dilakukan dua kali.

clear all

syms a b c d x s
f = a*x^3 + x^2 + b*x - c

f =

a*x^3 + x^2 + b*x - c

df = diff(f)

df =

3*a*x^2 + 2*x + b

dfa = diff(f,a)

dfa =

x^3

df2 = diff(f,2)
df2 =

6*a*x + 2

dfa2 = diff (f,a,2)

dfa2 =

t=sym('t')

t =

F=[3*sin(t)-cos(t^2); cos(2*t)-sin(t)]

F =

3*sin(t) - cos(t^2)
cos(2*t) - sin(t)

dF = diff(F)

dF =

3*cos(t) + 2*t*sin(t^2)
- 2*sin(2*t) - cos(t)

dF2 = diff(F,2)

dF2 =

2*sin(t^2) - 3*sin(t) + 4*t^2*cos(t^2)


sin(t) - 4*cos(2*t)

Iff = int(f)

Iff =

(a*x^4)/4 + x^3/3 + (b*x^2)/2 - c*x

Ifab = int(f , pi/2 , pi)

Ifab =

(pi*(72*pi*b - 96*c + 45*pi^3*a + 56*pi^2))/192

IF = int(F)

IF =

- 3*cos(t) - (2^(1/2)*pi^(1/2)*fresnelC((2^(1/2)*t)/pi^(1/2)))/2
(2*(tan(t/2) + tan(t/2)^2 - tan(t/2)^3 + 1))/(tan(t/2)^2 + 1)^2

IFab = int (F, pi/2 , pi)

IFab =
3 - (2^(1/2)*pi^(1/2)*(fresnelC(2^(1/2)*pi^(1/2)) -
fresnelC((2^(1/2)*pi^(1/2))/2)))/2

-1

% Kesimpulan : Int digunakan untuk mengintegralkan suatu fungsi. Cara cepat


mengintegralkan atau mendifferensialkan dua kali yaitu dengan memberi perintah
(fungsi,2). Suatu perintah integral dapat dibuat dalam bentuk rentang dengan
bertuliskan (fungsi, rentang 1, rentang2)
clear all

for n=1 : 10
x(n)=sin(n*pi/10)
end

x =

0.3090

x =

0.3090 0.5878

x =

0.3090 0.5878 0.8090

x =

Columns 1 through 3

0.3090 0.5878 0.8090

Column 4

0.9511

x =

Columns 1 through 3

0.3090 0.5878 0.8090

Columns 4 through 5

0.9511 1.0000

x =

Columns 1 through 3

0.3090 0.5878 0.8090


Columns 4 through 6

0.9511 1.0000 0.9511

x =

Columns 1 through 3

0.3090 0.5878 0.8090

Columns 4 through 6

0.9511 1.0000 0.9511

Column 7

0.8090

x =

Columns 1 through 3

0.3090 0.5878 0.8090

Columns 4 through 6

0.9511 1.0000 0.9511

Columns 7 through 8

0.8090 0.5878

x =

Columns 1 through 3

0.3090 0.5878 0.8090

Columns 4 through 6

0.9511 1.0000 0.9511

Columns 7 through 9

0.8090 0.5878 0.3090

x =

Columns 1 through 3

0.3090 0.5878 0.8090

Columns 4 through 6

0.9511 1.0000 0.9511


Columns 7 through 9

0.8090 0.5878 0.3090

Column 10

0.0000

data=[3 9 45 6; 7 16 -1 5]

data =

3 9 45 6
7 16 -1 5

for n=data
x=n(1)-n(2)
end

x =

-4

x =

-7

x =

46

x =

for n=1 : 5
for m=5:-1 : 1
A(n,m)=n^2+m^2;
end
disp(n)
end
1

zeros(1, 10);
for n=1 : 10
x(n)=sin(n*pi/10);
end
zeros(1, 10)

ans =

Columns 1 through 6

0 0 0 0 0 0

Columns 7 through 10

0 0 0 0

for n=1 : 10
x(n)=sin(n*pi/10);
end
for n=1 : 10
x(n)=sin(n*pi/10)
end

x =

Columns 1 through 3

0.3090 0.5878 0.8090

Columns 4 through 6

0.9511 1.0000 0.9511

Columns 7 through 9

0.8090 0.5878 0.3090

Column 10

0.0000

x =

Columns 1 through 3

0.3090 0.5878 0.8090

Columns 4 through 6

0.9511 1.0000 0.9511

Columns 7 through 9

0.8090 0.5878 0.3090

Column 10

0.0000

x =
Columns 1 through 3

0.3090 0.5878 0.8090

Columns 4 through 6

0.9511 1.0000 0.9511

Columns 7 through 9

0.8090 0.5878 0.3090

Column 10

0.0000

x =

Columns 1 through 3

0.3090 0.5878 0.8090

Columns 4 through 6

0.9511 1.0000 0.9511

Columns 7 through 9

0.8090 0.5878 0.3090

Column 10

0.0000

x =

Columns 1 through 3

0.3090 0.5878 0.8090

Columns 4 through 6

0.9511 1.0000 0.9511

Columns 7 through 9

0.8090 0.5878 0.3090

Column 10

0.0000

x =

Columns 1 through 3
0.3090 0.5878 0.8090

Columns 4 through 6

0.9511 1.0000 0.9511

Columns 7 through 9

0.8090 0.5878 0.3090

Column 10

0.0000

x =

Columns 1 through 3

0.3090 0.5878 0.8090

Columns 4 through 6

0.9511 1.0000 0.9511

Columns 7 through 9

0.8090 0.5878 0.3090

Column 10

0.0000

x =

Columns 1 through 3

0.3090 0.5878 0.8090

Columns 4 through 6

0.9511 1.0000 0.9511

Columns 7 through 9

0.8090 0.5878 0.3090

Column 10

0.0000

x =

Columns 1 through 3

0.3090 0.5878 0.8090


Columns 4 through 6

0.9511 1.0000 0.9511

Columns 7 through 9

0.8090 0.5878 0.3090

Column 10

0.0000

x =

Columns 1 through 3

0.3090 0.5878 0.8090

Columns 4 through 6

0.9511 1.0000 0.9511

Columns 7 through 9

0.8090 0.5878 0.3090

Column 10

0.0000

% Kesimpulan : For loops digunakan untuk mengulang perintah yang sama untuk seluruh
rentang yang diperlukan. Perintah For harus diakhir end agar memperoleh hasil dan
tidak menggantung

num=0; EPS=1;
while (1+EPS)>1
EPS=EPS/2
num=num+1
end

EPS =

0.5000

num =

EPS =

0.2500

num =

2
EPS =

0.1250

num =

EPS =

0.0625

num =

EPS =

0.0313

num =

EPS =

0.0156

num =

EPS =

0.0078

num =

EPS =

0.0039

num =
8

EPS =

0.0020

num =

EPS =

9.7656e-04

num =

10

EPS =

4.8828e-04

num =

11

EPS =

2.4414e-04

num =

12

EPS =

1.2207e-04

num =

13

EPS =

6.1035e-05

num =
14

EPS =

3.0518e-05

num =

15

EPS =

1.5259e-05

num =

16

EPS =

7.6294e-06

num =

17

EPS =

3.8147e-06

num =

18

EPS =

1.9073e-06

num =

19

EPS =

9.5367e-07
num =

20

EPS =

4.7684e-07

num =

21

EPS =

2.3842e-07

num =

22

EPS =

1.1921e-07

num =

23

EPS =

5.9605e-08

num =

24

EPS =

2.9802e-08

num =

25

EPS =

1.4901e-08
num =

26

EPS =

7.4506e-09

num =

27

EPS =

3.7253e-09

num =

28

EPS =

1.8626e-09

num =

29

EPS =

9.3132e-10

num =

30

EPS =

4.6566e-10

num =

31

EPS =

2.3283e-10
num =

32

EPS =

1.1642e-10

num =

33

EPS =

5.8208e-11

num =

34

EPS =

2.9104e-11

num =

35

EPS =

1.4552e-11

num =

36

EPS =

7.2760e-12

num =

37

EPS =
3.6380e-12

num =

38

EPS =

1.8190e-12

num =

39

EPS =

9.0949e-13

num =

40

EPS =

4.5475e-13

num =

41

EPS =

2.2737e-13

num =

42

EPS =

1.1369e-13

num =

43

EPS =
5.6843e-14

num =

44

EPS =

2.8422e-14

num =

45

EPS =

1.4211e-14

num =

46

EPS =

7.1054e-15

num =

47

EPS =

3.5527e-15

num =

48

EPS =

1.7764e-15

num =

49
EPS =

8.8818e-16

num =

50

EPS =

4.4409e-16

num =

51

EPS =

2.2204e-16

num =

52

EPS =

1.1102e-16

num =

53

EPS=2*EPS

EPS =

2.2204e-16

% Kesimpulan : While Loops digunakan ketika ada persyaratan dalam suatu soal atau
perintah untuk memenuhi suatu kriteria seperti kurang dari (<) atau lebih dari (>)
dan persyaratan lainnya.

apples=10

apples =

10

cost=apples*25

cost =
250

if apples>5
cost=(1-20/100)*cost
end

cost =

200

cost

cost =

200

% Kesimpulan : Perintah if digunakan jika hanya terdapat 1 variabel dicari contoh


apel. Sedangkan perintah if-end digunakan jika ada kriteria tertentu dalam soal
mengenai diskon atau lainnya dalam satu pembelian.

EPS=1

EPS =

for num=1:1000
EPS=EPS/2;
if (1+EPS)<=1
EPS=EPS*2
break
end
end

EPS =

2.2204e-16

% Kesimpulan : Break digunakan untuk mengakhiri perintah terakhir namun tidak


memberikan hasil. Oleh karena itu ditambahi end agar memperoleh hasil.

x=2.7

x =

2.7000

units= 'cm';
switch units
case {'inch' , 'in'}
y=x*2.54;
case {'feet' , 'ft'}
y=x*2.54*12;
case {'meter' , 'm'}
y=x/100;
case {'millimeter' , 'mm'}
y=x*10;
case {'centimeter' , 'cm'}
y=x;
otherwise
disp(['Unknown Units: ' units])
y=nan;
end

% Kesimpulan : Switch digunakan untuk merubah atau mengganti satuan. Namun saya
belum paham untuk penggunaannya Bapak. Mengapa tanda panahnya hilang sendiri dan
eror kebawahnya.

You might also like