MATLAB PROGRAMMING FOR ENGINEERS
FINAL PAPER FULL QUESTIONS AND
CORRECT ANSWERS PREMIUM STUDY
SHEET
●● Suppose you want to automatically generate a vector of with 2
entries; the 1st entry starting at 0 and ends at 1. How would you create
this vector in MATLAB?
Answer: x = linspace(0,1,2)
●● Whats another way to do this?
Answer: 0:1:2
●● Now Suppose you want to automatically generate a vector of 11
entries; the 1st entry starting at 0 and ends at 1. How would you create
this vector in MATLAB?
Answer: x = linspace(0,1,11)
●● Whats another way to do this?
Answer: 0:1:11
,●● Now Suppose you want to automatically generate a vector with 8
entries; the 1st entry starting at 0 and ends at 3. How would you create
this vector in MATLAB?
Answer: x = linspace(0,3,8) or x = 0:3:8
●● How would you access the first twelve elements for y?
Answer: y = (1:12);
x(1:12)
OR
y = (1:12);
x(1:12)
●● How would you access the 1st four multiples of 3 specified in a
vector?
Answer: y([3 6 9 12])
●● Write a statement transposing x
Answer: x'
●● Write two statements that notes the difference in tranpose of z
Answer: z' and z.'
,●● Elementary functions in MATLAB
Use the following few commands (a script) to make a plot. The
evaluation of v=cos(u) creates a vector whose elements are:
v(k) = cos(u(k)) where k = 1, 2, ...n
Answer: n = anu number;
u = linspace(0, 2*pi*n);
v = cos(u);
plot(u,v)
●● How would you clean up this plot?
Answer: By plotting axis label and a title; the text inside the single
quotes is a string which we intend to be the labels.
xlabel('u');
ylabel('v');
title('v = cos(u)');
command "help plot" would be very helpful
●● Write a statement that would transpose a 3x4 matrix
Answer: x = [1 2 3 4; 5 6 7 8; 9 10 11 12];
, x'
x=
1234
5678
9 10 11 12
ans =
159
2 6 10
3 7 11
4 8 12
●● If the previously-entered statement was "num1 = 5", what value will
be stored in num2 after the statements "num1 = num1 + num1" followed
by "num2 = num1 + 3".
Answer: 13;;
The interpreter computes 5 + 5, which is 10, then stores 10 in num1. The
interpreter then computes num1 + 3, which is 10 + 3 or 13, and stores 13
in num2.
FINAL PAPER FULL QUESTIONS AND
CORRECT ANSWERS PREMIUM STUDY
SHEET
●● Suppose you want to automatically generate a vector of with 2
entries; the 1st entry starting at 0 and ends at 1. How would you create
this vector in MATLAB?
Answer: x = linspace(0,1,2)
●● Whats another way to do this?
Answer: 0:1:2
●● Now Suppose you want to automatically generate a vector of 11
entries; the 1st entry starting at 0 and ends at 1. How would you create
this vector in MATLAB?
Answer: x = linspace(0,1,11)
●● Whats another way to do this?
Answer: 0:1:11
,●● Now Suppose you want to automatically generate a vector with 8
entries; the 1st entry starting at 0 and ends at 3. How would you create
this vector in MATLAB?
Answer: x = linspace(0,3,8) or x = 0:3:8
●● How would you access the first twelve elements for y?
Answer: y = (1:12);
x(1:12)
OR
y = (1:12);
x(1:12)
●● How would you access the 1st four multiples of 3 specified in a
vector?
Answer: y([3 6 9 12])
●● Write a statement transposing x
Answer: x'
●● Write two statements that notes the difference in tranpose of z
Answer: z' and z.'
,●● Elementary functions in MATLAB
Use the following few commands (a script) to make a plot. The
evaluation of v=cos(u) creates a vector whose elements are:
v(k) = cos(u(k)) where k = 1, 2, ...n
Answer: n = anu number;
u = linspace(0, 2*pi*n);
v = cos(u);
plot(u,v)
●● How would you clean up this plot?
Answer: By plotting axis label and a title; the text inside the single
quotes is a string which we intend to be the labels.
xlabel('u');
ylabel('v');
title('v = cos(u)');
command "help plot" would be very helpful
●● Write a statement that would transpose a 3x4 matrix
Answer: x = [1 2 3 4; 5 6 7 8; 9 10 11 12];
, x'
x=
1234
5678
9 10 11 12
ans =
159
2 6 10
3 7 11
4 8 12
●● If the previously-entered statement was "num1 = 5", what value will
be stored in num2 after the statements "num1 = num1 + num1" followed
by "num2 = num1 + 3".
Answer: 13;;
The interpreter computes 5 + 5, which is 10, then stores 10 in num1. The
interpreter then computes num1 + 3, which is 10 + 3 or 13, and stores 13
in num2.