1/73
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What does the following command yield?
>> clc
Clears the Command Window
What built-in function provides information about the data type?
whos
In the command window if we enter:
>> a=5
>> a=6
>> a
6
What does the following command yield?
> > clear
clears the workspace
MATLAB is a high-level language.
true
what is a variable?
A data container which can store a particular data.
The following is a series of commands entered in the Command Window:
>> pi = 2;
>> clear pi;
>> t = pi;
>> t
3.1416
What is the correct output for the following line of code:
-100 : 2 : -90
-100 -98 -96 -94 -92 -90
What is the correct output for the following line of code:
isprime(17)
1
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
What is the correct output for the following line of code:
rad2deg(3.141)
180
What do the following lines of code output after the third line?
>> x = 'hello world'
>> x(6) = '&'
>> x
hello&world
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
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]
How many data points does the following vector yield?
>> x = -pi:pi/4:pi
9
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
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.
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.
What are the 3 main areas covered in this introductory course?
MATLAB fundamentals, numerical techniques, programming structures
What does MATLAB stand for?
Matrix Laboratory
lower triangular
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
tridiagonal
diagonally dominant
square, identity, diagonally dominant
[3; 12; 21; 12]
[1 0 0; 9 1 0; 0 0 4]
How many data points does the following vector yield?
>> x = -pi:pi/4:pi
9
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
%The output of the last line in the following program is
A= 10;
if (A >= 10)
B=5
else B= 6
end
B
5
The operator ~= stands for
Not equal to
Which of the following answers represents the matrix product of the following A*B?
row 1 (3 3) row 2 (5 7)
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
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)))
What is the output after running the following program:
A = 6;
B = 3;
if A > 5 | | B < 1
A = 20;
end
A
20
What is the output after running the following program:
A = 6;
B = 3;
if A > 5 && B < 1
A = 20;
end
A
6
Which of the following answers represents the inverse of matrix A?
row 1 (1 -2) row 2 (1.5 -0.5)
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
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
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!'
"for loops" are the loops of choice when the programmer knows how many times a sequence of commands needs to be executed.
true
The output of the last line of this code is
for i=1:6
end
i
6
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
Every " for " statement must be accompanied by an end statement
true
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
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;
"While loops" do not need to have an end statement.
false
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
The "tic" and "toc" built-in function allows the user to
Measures the elapsed time it takes to execute the code in between
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
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
What is the output of the following code?
asum = 0;
for a=1:3
asum = asum + a^2 + a;
end
asum
20
A function can have any number of input variables, any number of output variables, no input variables, no output variables.
true
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
A variable defined within a function is a considered a global variable.
false
A function that is written within a script m-file cannot be called outside of the file.
true
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
To determine how efficient MATLAB code is, which one of the following would you use?
Use tic and toc commands
A pseudo code is
A mixture of non-specific computer language and English
Pseudo codes are written by
Humans for humans to read
flowline that connects symbols and indicates flow logic
terminal that represents the beginning or end of a task
input/output
processing for arithmetic and data manipulation operations
decision for logic of comparison operations
connector used to join different flowline
annotation that provides additional information about another flowchart symbol
used for loops/repetitions
Given the following flowchart, what would be the output?
b = 5; c = 20
Given the following flowchart, what would be the output?
a = 6, b = 5, c = 20
True error is defined as
True Value - Approximate Value
Approximate error is defined as
Present Approximation - Previous Approximation
Relative approximation error is defined as
Approximate Error/Present Approximation
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