A vector is given by V = [4, 17,-3, 8,-7, 12, 30,-6, 6,-6,-7, 15, 4, 7, 9]. Writ
ID: 3739334 • Letter: A
Question
A vector is given by V = [4, 17,-3, 8,-7, 12, 30,-6, 6,-6,-7, 15, 4, 7, 9]. Write an m-file which doubles the elements that are positive and are divisible by 3 or 5, and, raises to the power of 4 the elements that are negative and greater than -5. If a number does not satisfy either condition, square the value. Store the modified data into a new vector Create a 2x1 subplot (stacked vertically). In the top subplot, plot the raw unaltered data as red squares. In the bottom subplot, plot the altered data as blue circlesExplanation / Answer
V = [-4, 17, -3, 8, -7, 12, 30, -6, 6, -6, -7, 15, 4, 7, 9]
X = []
for a = 1:15
if((V(a)>=0) && (rem(V(a),3)==0 || rem(V(a),5)==0 )
X(a) = V(a)*2
elif(V(a)<0 && V(a)>-5)
X(a) = V(a)^4
else
X(a) = V(a)*V(a)
end
end
x = 0:0.1:10;
figure
subplot(2,1,1)
plot(x,V, '-s','MarkerEdgeColor','red' )
title('Original Vector')
subplot(2,1,2)
plot(x,X,'-o','MarkerEdgeColor','blue')
title('Updated Vector')
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.