Question

In: Mechanical Engineering

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');

Solutions

Expert Solution

clc

clear

close all

NMax = 100; % maximum number upto which difference between exact answer and partial sum is compared

partialSum = 0; % starting value of partial sum

exactAnswer = pi^2; % answer against which partial sum is compared

for k=1:NMax % k will go from 1 to Nmax with increment of 1

partialSum = partialSum + 6/k^2; % formula to calculate partial sum

percentDiff(k) = abs(partialSum - exactAnswer)/exactAnswer*100; % '% difference between partal sum and exact answer'

end

NVector = [1:NMax]; % vectror created to plot

plot(NVector,percentDiff); % plotting Nvector on x axis and difference on y axis

xlabel('{{Noob}}'); % label of x axis

ylabel('% Difference'); % label of y axis


Related Solutions

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...
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...
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 the case study below or your own health issue with goal and objective, your task...
Using the case study below or your own health issue with goal and objective, your task is to develop three outputs and one indicator for each output, considering the means of verification and assumptions for your indicators through completing the table below Goal: Decrease the complications of Hyperglycemia Objective: To maintain the blood glucose level within normal range Output Indicators (Measure to verify to what extent the goal is fulfilled – include targets and baseline data where possible) Means of...
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
Please write python code for the following. Implement the functions defined below. Include a triple-quoted comments...
Please write python code for the following. Implement the functions defined below. Include a triple-quoted comments string at the bottom displaying your output. Using sets (described in Deitel chapter 6) will simplify your work. Below is the starter template for the code: def overlap(user1, user2, interests): """ Return the number of interests that user1 and user2 have in common """ return 0    def most_similar(user, interests): """ Determine the name of user who is most similar to the input user...
Please explain in 300 words or more the task below: Your task involves an analysis of...
Please explain in 300 words or more the task below: Your task involves an analysis of general economic conditions or systematic risk, i.e., the risk that affects all industries and companies, in the U.S. macroeconomy. Your goal is to determine in percentage terms an optimal allocation of $1,000,000 among the following three asset classes: U.S. equities, U.S. Treasury bonds, and cash. Submit your analysis of U.S. Treasury bonds. Keep in mind that the purpose of your analysis is to determine...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT