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

By using MATLAB: 1. Create a vector x-sin(.1\'pi*t+9) for 10,000 evenly spaced p

ID: 3738395 • Letter: B

Question

By using MATLAB: 1. Create a vector x-sin(.1'pi*t+9) for 10,000 evenly spaced points between 0 and 100. Write a for loop that does the following: a. b. Displays the value of the iterator within each iteration using the fprintf command. Check to see if the jth entry of x is bigger than.5 i. If it is, add 1 to a counter. c. Otherwise, check if the ith entry of the counter is smaller than -2 i. Ifit is, add 1 to a different counter Finally, think of a way to achieve the same counts without writing a for loop. We learned how to do this last week using logicals. Use the timing functions tic and toc to see the difference in timing.

Explanation / Answer

SAVE THE FOLLOWING COD EIN MATLAB AND GET THE RESULTS ACCORDINGLY AS ASKED IN YOUR QUESTION-

clc
clear
close all;
%% Part(a)
%% Generating evenly spaced points between 0 to 200
t=linspace(0,100,10000);
%% Starting the for loop
counter=0;
counter1=0;
for i=1:length(t)
x(i)=sin(0.1*pi.*t(i)+9);% calculating the value of x
% Using fprintf command to display the values after each iteration
fprintf('The value of the %.2f iteration is %d',i,x(i))
end
%% Part(b)
if x(i)>0.5
counter=counter+1;
elseif x(i)<0.2
counter1=counter1+1;
end
disp('The values of the x > 0.5 is')
disp(counter)
disp('The values of the x < 0.2 is')
disp(counter1)