Computer Programming MC Practice

0.0(0)
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/73

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

74 Terms

1
New cards

What does the following command yield?
>> clc

Clears the Command Window

2
New cards

What built-in function provides information about the data type?

whos

3
New cards

In the command window if we enter:
>> a=5
>> a=6
>> a

6

4
New cards

What does the following command yield?
> > clear

clears the workspace

5
New cards

MATLAB is a high-level language.

true

6
New cards

what is a variable?

A data container which can store a particular data.

7
New cards

The following is a series of commands entered in the Command Window:
>> pi = 2;
>> clear pi;
>> t = pi;
>> t

3.1416

8
New cards

What is the correct output for the following line of code:
-100 : 2 : -90

-100 -98 -96 -94 -92 -90

9
New cards

What is the correct output for the following line of code:

isprime(17)

1

10
New cards

What is the difference between the built-in functions sin and sind?

sin requires an argument in radians and sind requires an argument in degrees to output the expected answer

11
New cards

What is the correct output for the following line of code:
rad2deg(3.141)

180

12
New cards

What do the following lines of code output after the third line?
>> x = 'hello world'
>> x(6) = '&'
>> x

hello&world

13
New cards

Given the following lines of code, what is the index value for the third value of C (the third value in C is the number 3)?
>> x = [1 2 3;4 5 6;7 8 9];
>> y = [1,3,5,12,2,4];
>> [C index] = intersect(x,y);
>> C = 1
2
3
4
5

7

14
New cards

What would you expect the output of the variable cigarettes be after the third line of code?
>> cigarettes = [5 2 14 7 9 11];
>> cancer_prob = cigarettes 0.23 + 0.8
>> cigarettes(2) = 12;
>> cancer_prob = cigarettes 0.23 + 0.8
>> cigarettes(end+1) = 20;
>> cancer_prob = cigarettes * 0.23 + 0.8

[5 12 14 7 9 11]

15
New cards

How many data points does the following vector yield?
>> x = -pi:pi/4:pi

9

16
New cards

What goes in the dotted line to complete the code below?


load('knee_flexion.mat');
times = left_knee_flexion(:,1);
knee_angle = left_knee_flexion(:,2);
r = range(....................);
[peak, peak_index] = max(knee_angle);
peak_time = times(..........................);

(knee_angle) in line 4 and (peak_index) in line 6

17
New cards

What is the output after the second line of code is executed?
>> x = rand(10);
>> x(2:4 , :)

Outputs the values in the 2nd through 4th row all columns.

18
New cards

What would MATLAB output if you input the following command?
>> 1_x = 17

Error: The input character is not valid in MATLAB statements or expressions.

19
New cards

What are the 3 main areas covered in this introductory course?

MATLAB fundamentals, numerical techniques, programming structures

20
New cards

What does MATLAB stand for?

Matrix Laboratory

21
New cards
term image

lower triangular

22
New cards

Which type of matrix has the following definition?

This type of matrix comes with all non-diagonal elements equal to zero, that is, only the diagonal entries of this square matrix can be non-zero, (aij=0;i≠j)

Diagonal matrix

23
New cards
term image

tridiagonal

24
New cards
term image

diagonally dominant

25
New cards
term image

square, identity, diagonally dominant

26
New cards
term image

[3; 12; 21; 12]

27
New cards
term image

[1 0 0; 9 1 0; 0 0 4]

28
New cards

How many data points does the following vector yield?

>> x = -pi:pi/4:pi

9

29
New cards

What is the output after the second line of code is executed?

>> x = rand(10);

>> x(2:4 , :)

Outputs the values in the 2nd through 4th row all columns

30
New cards

%The output of the last line in the following program is

A= 10;

if (A >= 10)

B=5

else B= 6

end

B

5

31
New cards

The operator ~= stands for

Not equal to

32
New cards

Which of the following answers represents the matrix product of the following A*B?

row 1 (3 3) row 2 (5 7)

33
New cards

What is the value of y if x= 20 and the following commands are executed:

if x> 25;

y= 2;

elseif x> 21;

y=1;

else y=0;

end;

y

0

34
New cards
<p>Your boss asks you to plot the following expression using MATLAB for t values between 1790 and 2000:</p><p>Choose the missing equation from the possible choices below to complete the following code:</p><p>t = 1790:10:2000;</p><p>P= ........................;</p><p>figure(15)</p><p>plot(t,P)</p><p>title('Section I: Problem 12')</p>

Your boss asks you to plot the following expression using MATLAB for t values between 1790 and 2000:

Choose the missing equation from the possible choices below to complete the following code:

t = 1790:10:2000;

P= ........................;

figure(15)

plot(t,P)

title('Section I: Problem 12')

197273000./(1+exp(-0.0313.*(t-1913.25)))

35
New cards

What is the output after running the following program:

A = 6;

B = 3;

if A > 5 | | B < 1

A = 20;

end

A

20

36
New cards

What is the output after running the following program:

A = 6;

B = 3;

if A > 5 && B < 1

A = 20;

end

A

6

37
New cards
<p>Which of the following answers represents the inverse of matrix A?</p>

Which of the following answers represents the inverse of matrix A?

row 1 (1 -2) row 2 (1.5 -0.5)

38
New cards

How many 'end' built-in functions need to be added to the end of the following program:

if BMI <= 18

disp(['Your BMI value is ', num2str(BMI), ' Kg/m^2 indicates that you are underweight']);

elseif BMI <= 25

disp(['Your BMI value is ', num2str(BMI), ' Kg/m^2 indicates that you have a normal weight']);

elseif BMI <= 30

disp(['Your BMI value is ', num2str(BMI), ' Kg/m^2 indicates that you are Overweight']);

else

disp(['Your BMI value is ', num2str(BMI), ' Kg/m^2 indicates that you are Over-overweight']);

1

39
New cards

Given the list of operator precedence below, what is the answer to the following: 

a = 3; b = 4; c = 5;

2*a - c + 4 : 6

5 6

40
New cards

What will be the output of the following code?

i = 5;

while i < 6

i = 5 + 1;

end

disp('This program ended!')

The program will run once displaying 'This program ended!'

41
New cards

"for loops" are the loops of choice when the programmer knows how many times a sequence of commands needs to be executed.

true

42
New cards

The output of the last line of this code is

for i=1:6

end

i

6

43
New cards

What is the output of the last line of this code:

scores =[ 4 3 5 1 3 ];

sum=0;

for i=1:length(scores);

sum=sum+scores(i);

end;

sum

16

44
New cards

Every " for " statement must be accompanied by an end statement

true

45
New cards

When does the while loop run its course and the program executes line 10?

1 clear; clc;

2 x = input('Enter x: ');

3 val = 1;

4 t = 1;

5 Percent_Rel_Error = 100;

6 while Percent_Rel_Error > 0.01

7 val = val + (x^t)/factorial(t);

8 Percent_Rel_Error = abs(val-exp(x))*100/exp(x);

9 t = t + 1;

10 end

When the condition for the while loop Percent Rel Error is equal to or less than 0.01

46
New cards

The following code is developed for a guessing game where the user is prompted to enter a positive number as a guess. Which change needs to be made to make sure the while loop is executed and the input prompt shows in the Command Window?

i = round(rand(1) * 9) % random integer between 0 and 9

guess = i;

while (guess ~= i)

guess = input('Guess a number:');

if (guess == i)

disp('Correct!');

else

disp('Wrong, try again ...');

end

end

Change the second line to: guess = -1;

47
New cards

"While loops" do not need to have an end statement.

false

48
New cards

Which answer completes line 4 in the code to make sure it works properly?

n = input('Enter a number you would like the factorial of: ');

1 f = n;

2 while n > 1

3 n = n-1;

4 f = ...........;

5 end

6 disp(['n! = ', num2str(f)])

f*n

49
New cards

The "tic" and "toc" built-in function allows the user to

Measures the elapsed time it takes to execute the code in between

50
New cards

To which line does the program go immediately after executing line 6?

1 total = 0;

2 while (true)

3 n = input('Enter number: ');

4 if (n < 0)

5 disp('Finished!');

6 break;

7 end

8 total = total + n;

9 end

10 disp(['Total = ' num2str(total)]);

Line 10

51
New cards

To which line does the program go immediately after executing line 6?

1 total = 0;

2 for i = 1:10

3 n = input('Enter number: ');

4 if (n < 0)

5 disp('Ignoring!');

6 continue;

7 end

8 total = total + n;

9 end

10 disp(['Total = ' num2str(total)]);

Line 2

52
New cards

What is the output of the following code?

asum = 0;

for a=1:3

asum = asum + a^2 + a;

end

asum

20

53
New cards

A function can have any number of input variables, any number of output variables, no input variables, no output variables.

true

54
New cards

What does nargin ~= 1 check for in the following code?

function [l,m] = compare_to_mean(x)

% usage: [l,m] = compare_to_mean(x)

% Input:

% x - A list of numbers

% Outputs: l - Number of values in x less than mean

% m - Number of values in x greater than mean

if nargin ~= 1

error('Compare to mean: %s', 'Expecting 1 argument')

end

m = mean(x);

less_array = find(x < m);

l = length(less_array);

more_array = find(x > m);

m = length(more_array);

end

Check if the user entered a number of variables other than 1 variable as the function input

55
New cards

A variable defined within a function is a considered a global variable.

false

56
New cards

A function that is written within a script m-file cannot be called outside of the file.

true

57
New cards

What is the output of ba(5) when you consider the two function below:

function m-file: foo.m

function out = foo(n)

out = 2 * n;

end

function m-file: ba.m

function m = ba(z)

m = 10 / foo(z)

end

1

58
New cards

To determine how efficient MATLAB code is, which one of the following would you use?

Use tic and toc commands

59
New cards

A pseudo code is

A mixture of non-specific computer language and English

60
New cards

Pseudo codes are written by

Humans for humans to read

61
New cards
<p></p>

flowline that connects symbols and indicates flow logic

62
New cards
term image

terminal that represents the beginning or end of a task

63
New cards
term image

input/output

64
New cards
term image

processing for arithmetic and data manipulation operations

65
New cards
term image

decision for logic of comparison operations

66
New cards
term image

connector used to join different flowline

67
New cards
term image

annotation that provides additional information about another flowchart symbol

68
New cards
term image

used for loops/repetitions

69
New cards
<p>Given the following flowchart, what would be the output?</p>

Given the following flowchart, what would be the output?

b = 5; c = 20

70
New cards
<p>Given the following flowchart, what would be the output?</p>

Given the following flowchart, what would be the output?

a = 6, b = 5, c = 20

71
New cards

True error is defined as

True Value - Approximate Value

72
New cards

Approximate error is defined as

Present Approximation - Previous Approximation

73
New cards

Relative approximation error is defined as

Approximate Error/Present Approximation

74
New cards

The following gas stations were cited for irregular dispensation by the Department of Agriculture. Which one cheated you the most? (RELATIVE TRUE ERROR)

****************************************************************

Station Actual gas Dispensed Gas reading at pump

****************************************************************

Ser 9.90 10.00

Cit 19.90 20.00

Hus 29.80 30.00

She 29.95 30.00

***************************************************************

ser