Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For problems 2 and 3, sketch out an algorithm for solving the problem using iter

ID: 3668944 • Letter: F

Question

For problems 2 and 3, sketch out an algorithm for solving the problem using iteration before writing any MATLAB code. 1. Write a MATLAB program that will perform the following operations on a ID 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(l)/(2*l); Using iteration (for loop), iterate over the values of the array v and create a new array vMag squareroot whose values are the squareroot 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 fuction can be used similar to the zeros function to create an array of false values (Boolean/logical 0s). 2. In previous labs, element by element operations were used to evaluate formulas for an array of data values. Formulas can also be evaluated for arrays of data using iteration. Write a MATLAB program to evaluate and plot the formula h(t) = 1.5 + 2.5e~Degree'2' +0.5/e~Degree2' over the time range 0.0

Explanation / Answer

1 )

v=[-13.5 2.5 -32.0 45.0 -23.0 4.25 0.0 0.85 10.0 -1.5];
newv=[];
for i = 1:length(v)
   newv(i) = v(i)/(2*i)
end
vMaSqrt = [];
for i=1:length(v)
   vMaSqrt(i) = sqrt(v(i))
end
boolvGTZ = [];
for i=1:length(v)
   if (v(i)<0)
       boolvGTZ(i)=logical(0)
   else
       boolvGTZ(i)=logical(1)
end

2)

for t=0.0:0.1:25.0
   y=1.5+2.5*exp(-0.2*t)+0.5*t*exp(-0.2*t)
   plot(t,y)
end