Documente Academic
Documente Profesional
Documente Cultură
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?
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
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
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
<program statements>
...
end
c. a = 10;
Pemograman Komputer 2020
if a < 20
end
C = A + B;
disp(C);
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);
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