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');
Explain the following code using comments next to the code: void foo() { uint8_t a=2; uint8_t...
Explain the following code using comments next to the code: void foo() { uint8_t a=2; uint8_t b[]={b0, b1, b2}; // They are the last three digits of your A# uint8_t* c=b; uint8_t* d=&a;
Your task is to create a book ordering form using VISUAL STUDIOS, with the code and...
Your task is to create a book ordering form using VISUAL STUDIOS, with the code and screenshots 1. Boxes for first name, last name, address. 2. Radio buttons to select: hard cover, soft cover, ebook. 3. Drop down list to select the book (make up three or four book names). 4. Radio buttons to select credit card (at least Visa, Master Card, American Express). 5. Box to enter credit card numbers. 6. The credit card box MUST verify that numbers...
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...
Source code with comments explaining your code in C# Program 2: Buh-RING IT! For this assignment,...
Source code with comments explaining your code in C# Program 2: Buh-RING IT! For this assignment, you’re going to simulate a text-based Role-Playing Game (RPG). Design (pseudocode) and implement (source) for a program that reads in 1) the hero’s Hit Points (HP – or health), 2) the maximum damage the hero does per attack, 3) the monster’s HP and 4) the maximum monster’s damage per attack. When the player attacks, it will pick a random number between 0 and the...
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...
Please complete the following code in C using the comments as instructions. Further instructions are below...
Please complete the following code in C using the comments as instructions. Further instructions are below the code. challenge.c // goal: print the environment variables to the file "env.txt", one per line // (If envp is NULL, the file should be empty, opening in write mode will do that.) // example: // inputs: // envp/environ = {"E1=2","E2=7",NULL} // outputs: // env.txt as a string would be "E1=2\nE2=7\n" // example: // inputs: // envp/environ = {NULL} or NULL // outputs: //...
Create a Hangman game using C++ by QT creator. please separate each code that will insert...
Create a Hangman game using C++ by QT creator. please separate each code that will insert in hider files and cpp files and use an accurate screeshoots if needed. Thanks in advance.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT