Matlab
Solid
'-'
Dashed
'--'
Dash-dot
'-.'
Dotted
':'
x=linspace(1,5,10), how many elements will the resulting vector x contain?
10
Given a vector defined as Z = linspace(3,12,4), the element in position 4 of vector z is
12
If the following matrix is in the command window M = [5 6 18; 2 4 12; 90 3 2] what number is the command M(1,3) referring to?
18
If the following loop is repeated 6 times, for a=6:X:21 disp(a) end the value of X must be
3
Given the following code segment, what is the resulting value of x. a=0; b=1; if a x=1; elseif b x=2; if a==b x=3; end if a<b x=4; end if a>b x=5; end else x=6; end
4
given the matrix G = 3 1 4 7 1 5 the output from the command G(2,1) is
4
Total number of elements in vector P P=linspace(2,10,5)
5
Given the following vectors: x=[ 2 4 0 8 10 12] y=[ 2 -4 7 10 10 -10] If z = find (x==max(x)) what is the value of z?
6
Using the following code, determine the value of the variable "Total" at the end of the code. >>q=3;Total=0;x=0:5;y=3*x-5; >>if q==1 for t=1:3 Total=Total+y(t); end elseif q==2 for s=1:3 Total=Total-y(s); end else Total=Total+y(5); end
7
Given the following Matlab code: v=4; while v<8; y=v+2; v=v+2; end; disp(y) What is the output from the disp(y) command?
8
how many elements in the vector v=[3:2:17]
8
What is not a relational operator
=
If you wanted to ask the person running your MATLAB program to provide a value for the stopping time of a calculation of projectile motion, you would use the command...
>>time_end=input('Please enter the stop time of the calculation in seconds: ');
If the variable A has been defined as a 3 by 4 matrix, the 2nd row can be removed using which of the following commands.
A(2,:)=[]
If A and B are relational operations, and the result of the command "A & B" is 1, then:
Both A and B are true
In a for-loop where "k = f:s:t", which of the following values can be correctly substituted for s (the increment value)?
Can be blank, a negative number or a positive number
Figure Window
Contains the outputs from graphics commands
Editor Window
Creates and debugs script and function files
A loop can be ended by pressing:
Ctrl+C
Function definition line _____
Defines the file as a function Defines the name of the function Defines the number and order of the input and output arguments
who
Display's a list of known variables in MATLAB'S memory
whos
Displays a list of known variables and their size and classifivation
OR |
Either one or both are true
The last command for every loop should be
End
Relational operations, i.e. x>0, will provide a "binary" 0 or 1 indicating false/true as the output, as a scalar independent of the size of the variable x (matrix/vector/scalar).
False
Command History
Logs all commands entered in the command window
~
NOT neither are true so produces a 1 if the operand is false
Assume the following commands have been entered in Matlab: >>t=0:0.1:3; >>x=t.*sin(t); >>y=cos(t)+2*sin(t); if you wanted to plot both x and y on the vertical axis of the same graph which command(s) would you enter
Plot(t,x,t,y,'r')
Workspace Window
Provides information about the variables that are stored in memory
Help Window
Provides the help information about the various functions within Matlab
clear
Removes all variables from MATLAB's memory
clear x
Removes only the indicated variable(s) from memory
Current Folder Window
Shows the files in the current/working folder
When defining a vector with the linspace function, you can set the beginning value, ending value, and ______ .
The number of intervals
which of the relational operators has the highest precedence?
They have equal precedence
The command hold on can be used to prevent the figure from being over written by another plot command
True
The script file and command window share the workspace
True
What code structure repeats commands, but requires the code to update a variable to be compared, to determine when to stop running the code?
While loop
Given the following vectors: x=[ 2 4 0 8 10 12] y=[ 2 -4 7 10 10 -10] If z = x>=x+y what is the value of z
[0 1 0 0 0 1]
Given the following vectors: x=[ 2 4 0 8 10 12] y=[ 2 -4 7 10 10 -10] If z = [ x >= y] what is the value of z?
[1 1 0 0 1 1]
Given the following vectors: x=[ 2 4 0 8 10 12] y=[ 2 -4 7 10 10 -10] If z = ~~x what is the value of z?
[1 1 0 1 1 1]
Given the following matrix K=[1,2,5,6;3,4,2,0;2,1,8,9] the output after evaluating the command K(2:3,1)' is
[3;2]
Given the following Matlab code: M=[1 5 4 1; 8 1 0 5; 3 6 7 2]; for r=1:3; for c=1:4; if M(r,c)<5; M(r,c)=8; end end end disp(M(2,:)) Indicate the output from the disp(M(2,:)) command
[8 8 8 5]
When using the plot command with no line specifiers, the resulting plot has the appearance of
a blue solid line connects the points with no markers
semicolon is typed before
a new line is entered
The output from the following Matlab commands is: a=5; b=1; c=6; if a>6 & b>c disp(a) else disp('b') end
b
format long g
best of 15 digit fixed or floating point
format short g
best of 5-digit fixed or floating point
&
both have to be true
What Matlab command will remove variables from memory?
clear
clc
clears the text from the command window
Which is a valid input command a. x = input('Enter a number: '); b. input('Enter a number: ') c. n = input('Enter your name: ','s'); d. both a and c e. a, b, and c
e. a, b, and c
Which of Matlab's windows is used to create script and function files?
editor window
format compact
eliminates empty lines to allow more lines with information displayed on the screen
A variable name may contain punctuation
false
function[outputarg]=functionname(inputarg)
file name = functionname.m
Which code structure will repeat calculations while controlling one variable automatically?
for loop
Differences between fprintf and disp
fprintf can show both variable and text from one command disp can only display a variable OR a text but not both fprintf can be used to write information to a file
What code structure will run command only if a specific condition has been met?
if statement
A function file must be saved before ______
it can be used
The output of the following MatLab commands is: k=3; c=2; m=8; if k>m | c<k disp('k') else disp(c) end
k
In the command >>fprintf('The answer is %4.1 \n',ans) the value 4 indicates...
keep at least 4 places for numbers in the statement
Variables in a function file are
local
What calculates the natural log of x
log(x)
Command Window
main window where you can enter variables and run programs
First executable line in a function file
must be the function definition, otherwise it is considered a script file
function[A]=RectArea(a,b)
one output two input arguments also can be written as function A (without brackets)
Order of operations
parentheses exponential multiplication and division addition and subtraction
order of precedence
parentheses exponentiation logical NOT multiplication, division addition, subtraction relational operators logical AND logical OR
The variables in a script file are
recognized in the Command Window
sum(A)
returns the added values of the elements in vector A
mean(A)
returns the average value of vector A
inv(A)
returns the inverse of the matrix A
max(A)
returns the max value of the vector A
dot(A,B)`
returns the scalar product of vectors A and B
format short e
scientific notation with 4 decimal places
In the command >>fprintf('The answer is %4.1 \n',ans) the value 1 indicates...
show 1 decimal place
In order to use the units of degrees in MATLAB's trig functions, you can use which of the following commands. tan(x*180/pi) tand(x)
tand(x)
A user defined function can be used in ________ (like a built in function)
the command window, a script file, or in another function
The functions xlsread() and xlswrite() can be used to read and write Excel files provided
the full file structure ('C:/folder/filename.xlsx') is given the file ('filename.xlsx') is in the active MATLAB folder
The functions xlsread() and xlswrite() can be used to read and write Excel files provided
the full file structure ('C:/folder/filename.xlsx') is given the file ('filename.xlsx') is in the active MATLAB folder
function trajectory(v,h,g)
the inputs and no outputs
V=linspace(1,12,7) the number 7 indicates -
the number of elements
When a function file is saved, the name of the file should be ________
the same as the name of the function
A variable name must begin w a letter
true
No spaces are allowed between characters in variable names
true
function[mpay,tpay]=loan(amount,rate,year)
two output arguments and three input arguments
function[V,S]=spherevolarea(r)
two output one input variables
When the total number of iterations required is not known, the best type of loop to use is
while-loop
if a=0:1:5 and b=1:1:6 then, x=[a,b] is
x = 1 3 5 7 9 11
x=eye(3)
x= 1 0 0 0 1 0 0 0 1
linspace(x,y,z)
x=first element y=last element z=number of elements
v=[x,y,z]
x=first element y=spacing z=last element