Question

In: Mechanical Engineering

Another less efficient way to estimate pi is the Gregory-Leibniz series: pi = 4/1 -4/3 +...

Another less efficient way to estimate pi is the Gregory-Leibniz series: pi = 4/1 -4/3 + 4/5 -4/7 + 4/9... . Use a while loop to approximate pi using this technique (5 points). Continue the calculations until the absolute value of the difference between the value of pi stored in MATLAB and the approximation is less than 0.001. Report the final approximation and the number of iterations required (5 points). Hint: to alternate the sign on each term use (-1) raised to a power.

Solutions

Expert Solution

The code is below:

---------------------------------------------------------------------------------------

clc;
p=0;
count=0;
i=0;
%fprintf('value of abs diff %1.16f \n',abs(pi-p));
while abs(pi-p) > 0.001
%fprintf('value of abs diff %1.16f \n',abs(pi-p));
p = p + (4*((-1)^i))/(2*i + 1);
count=count+1;
i=i+1;
end
fprintf('Number of iterations is %d \n',count);
fprintf('Value of Pi is %1.16f...\n',p);

------------------------------------------------------------------------------------------------------------------------

Also the m file can be downloaded from the following link:

https://drive.google.com/file/d/1stNHZ8cbiIMjkoX8nTQwmf_Eb1KCr53z

To run the m file , go to the specific folder and type leibniz

The output is shown below:


Related Solutions

Another less efficient way to estimate pi is the Gregory-Leibniz series: pi = 4/1 -4/3 +...
Another less efficient way to estimate pi is the Gregory-Leibniz series: pi = 4/1 -4/3 + 4/5 -4/7 + 4/9... . Use a while loop to approximate pi using this technique (5 points). Continue the calculations until the absolute value of the difference between the value of pi stored in MATLAB and the approximation is less than 0.001. Report the final approximation and the number of iterations required (5 points). Hint: to alternate the sign on each term use (-1)...
1. is sin(pi/4) causal? 2. is sin(pi/4) stable? 3. is delta(n+1) causal? 4.  = ? 5. If...
1. is sin(pi/4) causal? 2. is sin(pi/4) stable? 3. is delta(n+1) causal? 4.  = ? 5. If function w [ n ] is convolved with , what will the result be? 6. if a system with signal length 4 is convolved with its own system response, what will the length of that signal be? 7. In an LTI system, x[n] * h[n]= y[n]. What is x[n-3] * h[n-2] =?
The most efficient way to send a spacecraft from the earth to another planet is by...
The most efficient way to send a spacecraft from the earth to another planet is by using a Hohmann transfer orbit (the figure (Figure 1)). If the orbits of the departure and destination planets are circular, the Hohmann transfer orbit is an elliptical orbit whose perihelion and aphelion are tangent to the orbits of the two planets. The rockets are fired briefly at the departure planet to put the spacecraft into the transfer orbit; the spacecraft then coasts until it...
The profitability index (PI)is a capital budgeting tool that provides another way to compare a project’s...
The profitability index (PI)is a capital budgeting tool that provides another way to compare a project’s benefits and costs. It is computed as a ratio of the discounted value of the net cash flows expected to be generated by a project over its life (the project’s expected benefits) to its net cost (NINV). A project’s PI value can be interpreted to indicate a project’s discounted return generated by each dollar of net investment required to generate those returns. Consider the...
A series of vertical curves connect a 3% upgrade, a 2% downgrade, and another 3% upgrade...
A series of vertical curves connect a 3% upgrade, a 2% downgrade, and another 3% upgrade moving west to east. These curves are designed such that they connect directly to one another (i.e., the PVT of the first curve is the PVC of the second curve). If the design speed of the alignment is 60 mi/h, what is the elevation difference between the two road segments (i.e., the vertical difference between the PVC of the first curve and the PVT...
Find the real Fourier series of the piece-wise continuous periodic function f(x)=1+x+x^2 -pi<x<pi
Find the real Fourier series of the piece-wise continuous periodic function f(x)=1+x+x^2 -pi<x<pi
1. Starting with a sample of a fine pearlitic steel, describe the most efficient way to...
1. Starting with a sample of a fine pearlitic steel, describe the most efficient way to form a coarse pearlitic steel. Answer: ….. 2.Now, with this sample of a coarse pearlitic steel, describe the most efficient way to form a tempered martensitic steel. Answer:….. 3.Now with this sample of a tempered martensitic steel, describe the most efficient way to form a spheroiditic steel. Answer….. 4.Now with this sample of a spheroiditic steel, describe the most efficient way to return to...
1) Estimate the isoelectric point (pI) for the dipeptide Ser-Ile. Round the answer to one decimal...
1) Estimate the isoelectric point (pI) for the dipeptide Ser-Ile. Round the answer to one decimal place. 2) Estimate the isoelectric point (pI) for the tripeptide Gly-Lys-Val. Round the answer to one decimal place. 3)A mixture of Cys, Glu, Tyr, Lys and Ser was applied to a cation exchange column at pH 6. Which of these amino acids eluted from the column first?    Which of these amino acids eluted from the column last?    Tyr Glu Lys Ser Cys
1. triple integral... first form 0 to pi, second from 0 to pi/3, third to sec(phi)...
1. triple integral... first form 0 to pi, second from 0 to pi/3, third to sec(phi) to 2 of p^2*sin(phi) dp d(phi) d(theta) 2. triple integral... first form 0 to pi, second from -sqrt(3) to sqrt(3), third to 1 to sqrt(4-r^2) of r dz dr d(theta) 3. triple integral... first form 0 to pi/2, second from 0 to sqrt(3), third to 1 to sqrt(4-r^2) of r dz dr d(theta) 4. triple integral... first form 0 to pi, second from 0...
Calculate a geometric series 1.For v greater than 0 and less than 1, what is the...
Calculate a geometric series 1.For v greater than 0 and less than 1, what is the Sum(v^i) for i = 1 to 100? 2.For v greater than 0 and less than 1, what is the Sum(v^i) for i = 1 to infinity? 3.Let v = 1/(1+r). State the answer to question 2 in terms of r.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT