% Part 1 vec = [4 5 2 8 4 7 2 64 2 57 2 45 7 43 2 5 7 3 3 23 3 4 3 0 -65 -34] a.
ID: 1101273 • Letter: #
Question
% Part 1
vec = [4 5 2 8 4 7 2 64 2 57 2 45 7 43 2 5 7 3 3 23 3 4 3 0 -65 -34]
a. Create a new vector, vecA, that is the same as the vector vec except that all of the 3s have been deleted.
b. Create a new vector, vecR, that is the reverse of vec.
c. Create a new vector, vecS, that contains all of the elements in vec that are smaller than 45. The numbers should be in the same order as they were in vec.
d. Create a new vector, vecT, that contains true wherever vec is greater than 10 and false everywhere else.
e. Create a new vector, vec2, that contains every other element of vec starting with the second element.
f. Create a new vector, vec3R, that contains every third element of vec starting from the last element and going toward the first element in vec.
g. Create a new vector, vecF, that contains the indices of every element in vec that is equal to 2.
% Part 2: The Taylor polynomial, for e^3
n = 1:10
x = 3
Explanation / Answer
vec = [4 5 2 8 4 7 2 64 2 57 2 45 7 43 2 5 7 3 3 23 3 4 3 0 -65 -34];
vecA = vec(vec~=3)
vecR = fliplr(vec)
vecS = vec(vec<45)
vecT = vec>10
vec2 = vec(2:2:end)
vec3R = vec(end:-3:1)
vecF = find(vec==2)
% Taylor series for e^3;
x = 3;
value_of_e3 = 0;
for n=0:10
value_of_e3 = value_of_e3 + x.^n/factorial(n);
end
value_of_e3
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.