Sunteți pe pagina 1din 9

Pemograman Komputer 2020

Ujian Pemograman Komputer


Lecturer: Jaswar Koto

Nama : Mochamad Ridwan saleh


Nim : 170102073
Prodi. : Teknik mesin

1) Matrices

a) r = [7 8 9 10 11]; t = [2, 3, 4, 5, 6]; res = r + t; MATLAB will execute then res will be?

b) m = [1 2 3; 4 5 6; 7 8 9]; MATLAB will execute then m will be?

2) Operators
a = 10; b = 20; f = a / b; g = a \ b; z = f ^ g, MATLAB will execute the statement then f, g
and z will be?
3) Loop
a = 10;
while( a < 20 )
fprintf('value of a: %d\n', a);
a = a + 1;
end
a. When you run the file, a will be displayed?
b. Create for loop
c. Create Loop Control Statements using if

4) Vector, Matrix and Arrays


a) A = [7, 11, 15, 23, 9]; B = [2, 5, 13, 16, 20]; C = A + B; MATLAB will execute then C
will be?

b) a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8]; sa = a(2:3,2:4); MATLAB will execute


then sa will be?

c) a = [7 9 5; 6 1 9; 4 3 2]; MATLAB will execute then a(:, :, 1) will be?


Pemograman Komputer 2020

5) Plot, Graphics and Simulink


a) x = [0:0.01:10]; y = sin(x); MATLAB will execute then y will be plotted?

b) Explain function of Simulink in MATLAB

ANSWER :

1.a. r = [7 8 9 10 11];
t = [2, 3, 4, 5, 6];
res = r + t

MATLAB will execute the above statement and return the following result:

res =

Columns 1 through 4

9 11 13 15

Column 5

17

b. m = [1 2 3; 4 5 6; 7 8 9]

MATLAB will execute the above statement and return the following result:

m=

1 2 3

4 5 6

7 8 9
Pemograman Komputer 2020
Pemograman Komputer 2020

2. a = 10 ; b = 20

F = a/b

G = a\b

z=f^g

When the above code is compiled and executed, it produces the following result:

f=

0.5000

g=

z=

0.2500
Pemograman Komputer 2020

3. a. When you run the file, it displays the following result:

value of a: 10

value of a: 11

value of a: 12

value of a: 13

value of a: 14

value of a: 15

value of a: 16

value of a: 17

value of a: 18

value of a: 19

b. for index = values

<program statements>

...

end

c. a = 10;
Pemograman Komputer 2020

% check the condition using if statement

if a < 20

% if condition is true then print the following

fprintf('a is less than 20\n' );

end

fprintf('value of a is : %d\n', a);


Pemograman Komputer 2020

4. a. A = [7, 11, 15, 23, 9];

B = [2, 5, 13, 16, 20];

C = A + B;

disp(C);

When you run the file, it displays the following result:

9 16 28 39 29

5 6 2 7 -11

b. a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];

sa = a(2:3,2:4)

MATLAB will execute the above statement and return the following result:

sa =

3 4 5

4 5 6

c. a = [7 9 5; 6 1 9; 4 3 2]

MATLAB will execute the above statement and return the following result:

a=

7 9 5

6 1 9

4 3 2

The array a is a 3-by-3 array; we can add a third dimension to a, by providing the values like:
Pemograman Komputer 2020

a(:, :, 2)= [ 1 2 3; 4 5 6; 7 8 9]

MATLAB will execute the above statement and return the following result:

a(:,:,1) =

7 9 5

6 1 9

4 3 2

a(:,:,2) =

1 2 3

4 5 6

7 8 9

5. a. x = [0:0.01:10];
Pemograman Komputer 2020

y = sin(x);

plot(x, y), xlabel('x'), ylabel('Sin(x)'), title('Sin(x) Graph'),

grid on, axis equal

b. Simulink merupakan bagian tambahan dari software MATLAB .simulink berfungsi sebagai sarana
permodelan , simulasi, dan analisis dari system dinamik dengan menggunakan antar muka grafis.

Simulink terdiri dari beberapa kumpulan toolbox yang dapat digunakan untuk anasilis system linier dan
non linier.beberapa library yang sering digunakan dalam siste control antara lain match, sinks dan sources

S-ar putea să vă placă și