Question

In: Mechanical Engineering

Your task is to take the above code, and insert comments (using the “%” symbol) next...

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;

Solutions

Expert Solution

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.


Related Solutions

Your task is to take the below code, and insert comments (using the “%” symbol) next...
Your task is to take the below code, and insert comments (using the “%” symbol) next to each line of code to make sure that you know what every line does. clc clear close all NMax = 100; partialSum = 0; exactAnswer = pi^2; for k=1:NMax partialSum = partialSum + 6/k^2; percentDiff(k) = abs(partialSum - exactAnswer)/exactAnswer*100; end NVector = [1:NMax]; plot(NVector,percentDiff); xlabel('{{Noob}}'); ylabel('% Difference');
Understand the code and explain the code and answer the questions. Type your answers as comments....
Understand the code and explain the code and answer the questions. Type your answers as comments. #include #include using namespace std; // what is Color_Size and why it is at the end? enum Color {        Red, Yellow, Green, Color_Size }; // what is Node *next and why it is there? struct Node {        Color color;        Node *next; }; // explain the code below void addNode(Node* &first, Node* &last, const Color &c) {        if (first == NULL)...
#python. Explain code script of each part using comments for the reader. The code script must...
#python. Explain code script of each part using comments for the reader. The code script must work without any errors or bugs. Ball moves in a 2D coordinate system beginning from the original point (0,0). The ball can move upwards, downwards, left and right using x and y coordinates. Code must ask the user for the destination (x2, y2) coordinate point by using the input x2 and y2 and the known current location, code can use the euclidean distance formula...
USING MATLAB Part 2: Insert coins For this part, you are going implement the code that...
USING MATLAB Part 2: Insert coins For this part, you are going implement the code that asks the user to enter coins until they have entered enough for the NAU power juice. Open the insert_coins.m file. Initialize total to 0. We do this because initially, no coins have been entered. Using a loop, ask the user to enter a coin until the total matches or exceeds 115 cents. The input should be a char or string, so make sure that...
* Make sure you turn in your code (take a screen shot of your code in...
* Make sure you turn in your code (take a screen shot of your code in R)and answers. Conduct the hypothesis and solve questions by using R. 2) A random sample of 12 graduates of a secretarial school averaged 73.2 words per minute with a standard deviation of 7.9 words per minute on a typing test. What can we conclude, at the .05 level, regarding the claim that secretaries at this school average less than 75 words per minute on...
Explain your code with comments. Solve in C++. 1. Write a str2int() function that convers a...
Explain your code with comments. Solve in C++. 1. Write a str2int() function that convers a string to integer. The function will take the number as a string then will return it as integer. E.g. str2int(“123”) will return 123 str2int(“005”) will return 5 str2int(“102”) will return 102
Implement the recursive LU factorization algorithm in Python. Use plenty of comments to explain your code....
Implement the recursive LU factorization algorithm in Python. Use plenty of comments to explain your code. While you are coding, it is helpful to break up your code into sub-functions and test the sub-functions as you go along.
Using the income statement, calculate the vertical and horizontal analysis and insert your answers in the...
Using the income statement, calculate the vertical and horizontal analysis and insert your answers in the appropriate spaces provided VERTICAL ANALYSIS HORIZONTAL ANALYSIS Statement of Operations Income Statement 2017 Percent 2018 percent CHANGE PERCENT Sales (net) 8,100,000 10,000,000 Cost of goods sold 5,300,000 6,000,000 Gross Margin 2,800,000 4,000,000 General Expense (1,050,000.00) (1,080,000) Depreciation Expense (300,000.00) (300,000) Operating Income 1,450,000.00 2,620,000 Interest Expense (40,000.00) (50,000) Income Taxes (35%) (507,500.00) (917,000.00) Net Income 902,500.00 1,653,000
Copy and paste the below code EXACTLY as shown into your Java environment/editor. Your task is...
Copy and paste the below code EXACTLY as shown into your Java environment/editor. Your task is to fill in the code marked as "...your code here...". A detailed explanation follows the code. import java.util.*; public class OddManOut {    public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("How many random Integers to produce?"); int num = sc.nextInt();    ArrayList<Integer> randomInts = createRandomList(num); System.out.println("The random list is: "); System.out.println(randomInts);    removeOdds( randomInts ); System.out.println("The random list with only...
CODE IN PYTHON: Your task is to write a simple program that would allow a user...
CODE IN PYTHON: Your task is to write a simple program that would allow a user to compute the cost of a road trip with a car. User will enter the total distance to be traveled in miles along with the miles per gallon (MPG) information of the car he drives and the per gallon cost of gas. Using these 3 pieces of information you can compute the gas cost of the trip. User will also enter the number of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT