Documente Academic
Documente Profesional
Documente Cultură
“Introductory Progamming
in Matlab”
Group : B01
Members :
- Arya Nur Dewangga 03411640000034
- Panji Indra Wadharta 03411640000037
- Refsi Pratiwi 03411640000045
- Aceha Jazaul Aufa 03411640000057
Concept
1. What is fprintf function?
a. Function that provides additional control over the display of
information
b. Function that provides a handy way to display a value
c. Types of loops
d. Function that ends after a specified number of repetitions
e. Function that ends on the basis of a logical condition
Answer :A
Solutions : Fprintf function is function that provides additional control over
the display of information. A simple representation of its syntax is
fprintf('format', x, ...)
12. What’s the meaning of format codes (%d) that employed with the
fprintf function?
a. The decimal format
b. The integer format
c. The scientific format with lowercase e
d. The scientific format with uppercase E
e. The more compact of %e or %f
Answer :B
Solution :
13. What is the meaning of control codes (\n) that employed with the
fprintf function?
a. The decimal format
b. The integer format
c. The scientific format with lowercase e
d. Start new line
e. The more compact of %e or %f
Answer :D
Solution :
16. Suppose that the variable ‘velocity’ has a value of 5.6175. to display
the value using eight digits with four digits to the right of the decimal
point along with a amessage, the statement along with the resulting
output would be.........
a. >> fprintf(‘The velocity is “8.4f m/s/n\’, velocity)
The velocity is 50.6175 m/s
b. >> fprintf (‘The velocity is %8.4f% m/s\n’, velocity)
The velocity is 50.6175 m/s
c. >> fprintf (‘The velocity is “8.4f m/s\n”, velocity)
The velocity is 50.6175 m/s
d. >> fprintf (‘The velocity is %8.4f m/s\n’, velocity)
The velocity is 50.6175 m/s
e. >> fprintf (‘The velocity is %8.4f m/s\n, velocity)
The velocity is 50.6175 m/s
Answer :D
Solution :
17. The fprintf function can also be used to display several values per
line with different formats. What will appear in the command
window when typing the command below?
a. 100 6.283 3.14159e+000
b. 100 6.283 3.14159000
c. 100 2.283 3.14159e+000
d. 100 6.283 3.14159e^+000
e. 100 6.283 3.14159e^(+000)
Answer :A
Solution :
Answer :A
Solution :
18. Fprintf can also be used to display vectors and matrices. Which the
right set between the M-file and the result?
a. M-file:
function fprintfdemo
x = [1 2 3 4 5];
y = [20.4 12.6 17.8 88.7 120.4];
z = [x;y];
fprintf(' x y\n');
fprintf('%5d %10.3f\n',z);
The result of running this M-file:
>> fprintfdemo
x y
1 20.400
2 2 12.600
3 3 17.800
4 4 88.700
5 5 120.400
b. M-file:
function fprintfdemo
x = [1 2 3 4 5];
y = [20.4 12.6 17.8 88.7 120.4];
z = [x;y];
fprintf(' x y\n');
fprintf('%5d %10.3f\n',z);
The result:
>> fprintfdemo
x y
1 20.400
2 2 12.600
3 3 17.800
4 4 88.700
5 5 120.400
c. M-file:
function fprintfdemo
x = [1 2 3 4 5];
y = [20.4 12.6 17.8 88.7 120.4];
z = [x;y];
fprintf(' x y n');
fprintf('%5d %10.3f\n,z);
The result:
>> fprintfdemo
x y
1 20.400
2 12.600
3 17.800
4 88.700
5 120.400
d. M-file:
function fprintfdemo
x = [1 2 3 4 5];
y = [20.4 12.6 17.8 88.7 120.4];
z = [x;y];
fprintf(' x y n');
fprintf('5d , 10.3f\n,z);
The result:
>> fprintfdemo
x y
1 20.400
2 12.600
3 17.800
4 88.700
5 120.400
e. M-file:
function fprintfdemo
x = [1 2 3 4 5];
y = [20.4 12.6 17.8 88.7 120.4];
z = [x;y];
fprintf(' x y n');
fprintf('5d , 10.3f\n,z);
The result:
>> fprintfdemo
x y
6 20.400
7 12.600
8 17.800
9 88.700
10 120.400
Answer :A
19. Execute the command below, and choose the answer
for j = 1:5
disp(j)
end
a. 1, 2, 3, 4, 5
b. 5, 4, 3, 2, 1
c. 1, 3, 5
d. 2, 3, 4, 5
e. 0, 1, 2 , 3, 4, 5
Answer :A
Solution :
b. Function fout=factor(n)
%factor(n)
%computes the product of all the integers from 1 to n
X=1
For 1 =1:n
end
Fout = X
End
c. Function fout=factor(n)
%factor(n)
%computes the product of all the integers from 1 to n
X=1
For 1 =1:n
Fout = X
End
end
d. Function fout=factor(n)
%factor(n)
%computes the product of all the integers from 1 to n
X=1
For 1 =1:n
Fout = X
end
e. %factor(n)
%computes the product of all the integers from 1 to n
X=1
For 1 =1:n
Fout = X
end
Answer :B
Solution :
>> factor(5)
ans =
120
22. The statement between while and the end are repeated as long as the
condition is true. A simple example is:
x= 8
while x > 0
x = x -3
disp(x)
end
When this code is run, the result is....
a. -1, 2, 5, 8
b. -2, -1, 2, 5, 8
c. -2, -1, 0 , 1, 2, 3, 4, 5, 6, 7, 8
d. -2, 2, -1, 1, -5, 5, -8, 8
e. -1, 2, 5, 7
Answer :A
Solution :
23. Sum of sequence of random numbers until the next random number is
greater than an upper limit. Then, exit the loop using a break statement.
Which code is correct?
while 1 while 1
tmp = rand; if tmp > limit
if tmp > limit break
break end
end s = s + tmp;
s = s + tmp; end
end
c. limit = 0.8; d. limit = 0.8;
s = 0; s = 0;
while s = s + tmp;
if tmp > limit
break
end
tmp = rand;
end
Answer :A
Solution :