In: Mechanical Engineering
Your task is to take the above code, and insert comments (using the “%” symbol) next to each line of code to make sure that you know what every line does. close all; clear all; clc;
thetaAB = 0; angleIncrement = 0.1; numOfLoops = 360/angleIncrement; thetaABVector = [angleIncrement:angleIncrement:360]; rAB = 5; rBC = 8;
for i=1:numOfLoops bothResults = SliderCrankPosn(rAB,rBC,thetaAB); rAC(i) = bothResults(1); thetaBC(i) = bothResults(2); thetaAB = thetaAB+angleIncrement;
end
subplot(2,1,1) plot(thetaABVector,thetaBC,'Linewidth',3); xlabel('\theta_{AB} [degrees]'); ylabel('\theta_{BC} [degrees]'); xlim([0 360]); ylim([300 400]); grid on;
subplot(2,1,2) plot(thetaABVector,rAC,'r'); xlabel('\theta_{AB} [degrees]'); ylabel('r_{AC} [inches]'); xlim([0 360]); grid on;
close all; %closes all figures
clear all; %clears workspace
clc; %clear command window
thetaAB = 0; %initialize variable thetaAB = 0
angleIncrement = 0.1; %The data will be taken for each increment
angle of 0.1
numOfLoops = 360/angleIncrement; %The number of times the 'for'
loop will be executed 360/0.1 = 3600
thetaABVector = [angleIncrement:angleIncrement:360]; %Creates an
array named 'thetaABVector' that contains values of theta
rAB = 5; %Length of link AB
rBC = 8; %Length of link BC
for i=1:numOfLoops %Beginning of 'for' loop
bothResults = SliderCrankPosn(rAB,rBC,thetaAB); %It calls the
function 'SliderCrankPosn' and stores the value returned by the
function in the array 'bothResults'
rAC(i) = bothResults(1); %Creates an array 'rAC' that stores the
data of the '1'st column of array 'bothResults'
thetaBC(i) = bothResults(2); %Creates an array 'thetaBC' that
stores the data of the '2'nd column of array 'bothResults'
thetaAB = thetaAB+angleIncrement; %the angle is incremented by 0.1
to continue the loop
end %end of loop
subplot(2,1,1) %divides the current
figure into a 2x1 grid
plot(thetaABVector,thetaBC,'Linewidth',3); %plots the two vectors
using a 'linewidth' (the width of line in plot)
xlabel('\theta_{AB} [degrees]'); %this gives the label to x-axis to
show what x-axis represents
ylabel('\theta_{BC} [degrees]'); %this gives the label to y-axis to
show what y-axis represents
xlim([0 360]); %the x-axis starts from 0 to 360
ylim([300 400]); %the y-axis starts from 300 to 400
grid on; %displays the grid
subplot(2,1,2) %divides the current figure into a 2x1 grid
plot(thetaABVector,rAC,'r'); %plots the two vectors using a red
line('r')
xlabel('\theta_{AB} [degrees]'); %this gives the label to x-axis to
show what x-axis represents
ylabel('r_{AC} [inches]'); %this gives the label to y-axis to show
what y-axis represents
xlim([0 360]); %the x-axis starts from 0 to 360
grid on; %displays the grid
NOTE : Make sure you copy the above text to MATLAB to see the comments properly.