Write a MATLAB program that will perform the following operations on a 1D array
ID: 3668568 • Letter: W
Question
Write a MATLAB program that will perform the following operations on a 1D array of data v. Make sure to preallocate space for all your resulting arrays. Create the array v = [-13.5 2.5 -32.0 45.0 -23.0 4.25 0.0 0.85 10.0 -1.5] using direct entry. Using iteration (for loop), iterate over the indices of the array v and create a new array vNew whose values are the corresponding values in v divided by two times the index of the element, for example vNew (1) = v(1)/(2*1); Using iteration (for loop), iterate over the values of the array v and create a new array vMagSqrt whose values are the square root of the magnitude (absolute value) of the corresponding values in v. Using iteration (for loop), iterate over the indices of the array v and create a new array boolvGTZ whose values are true if the corresponding value of v is positive (zero or greater) and false otherwise. MATLAB's built in false function can be used similar to the zeros function to create an array of false values (Boolean/logical 0s).Explanation / Answer
v = [-13.5 2.5 -32.0 45.0 -23.0 4.25 0.0 0.85 10.0 -1.5];
vNew = zeros(size(v));
for i=1:length(v)
vNew(i)=v(i)/(2*i);
end
vMagSqrt = zeros(size(v));
for i=1:length(v)
vMagSqrt(i)=sqrt(abs(v(i)));
end
boolvGTZ = false(size(v));
for i=1:length(v)
if v(i) >=0
boolvGTZ(i)=true;
end
end
v
vNew
vMagSqrt
boolvGTZ
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.