
Concept explainers
To write:
A menu-driven program to investigate the constant
Answer to Problem 28E
Solution:
The script file is,
% MATLAB code to calcualte the value of pi.
%script file.
select = pivalues;
while select ˜= 4
switch select
%select the different options to get the value of pi.
case 1
machinformula
%print the result by usin Machin's formula.
case 2
leibn
%get approximate by using Leibniz.
case 3
leibgood
%approximate pi value using Leibniz untill good approximation.
end
select = pivalues;
end
% end of
%The script file should be placed in the same folder.
The function file is,
% MATLAB code to calcualte the value of pi by different options.
%function file.
function select = pivalues
select = menu('select a option for pi', 'Machin''s formula', 'Leibniz''s formula:n-terms','Leibniz''s formula:good approximation','Exit');
%select the different options in menu.
while select == 0
disp('not valid! please select one of the options')
select = menu('select a option for pi', 'Machin''s formula', 'Leibniz''s formula:n-terms','Leibniz''s formula:good approximation','Exit');
end
end
% end of function
%The function file should be placed in the same folder.
The function file is,
% MATLAB code to calcualte the value of pi by Machinformula.
%function file.
function machinformula
formula = (4*atan(1/5)-atan(1/239));
%define the variable pivalues.
fprintf('Using the MATLAB constant, pi = %.6f\n', pi)
fprintf('the value of pi using Machin''s formula, pi = %.6f\n', 4*formula)
%print the value of pi.
end
% end of function
%The function file should be placed in the same folder.
The function file is,
% MATLAB code to calcualte the value of pi by leibniz's formula for the specific terms.
%function file.
function leibn
fprintf('Approximate value of pi by using Leibniz'' formula\n')
n = askforn;
approxvaluepi = 0;
denominator = -1;
signterm = -1;
for i = 1:n
denominator = denominator + 2;
signterm = -signterm;
approxvaluepi = approxvaluepi + signterm * (4/denominator);
end
fprintf('An approximation of pi with n = %d is %.2f\n', n, approxvaluepi)
end
function out = askforn
inputnum = input('A positive integer for n is entered: ');
num2 = int32(inputnum);
while num2 ˜= inputnum || num2 < 0
inputnum = input('Not Valid! Enter a positive integer:');
num2 = int32(inputnum);
end
out = inputnum;
end
% end of function
%The function file should be placed in the same folder.
The function file is,
% MATLAB code to calcualte the value of pi by leibniz's formula till the good apprroxiamtion is found..
%script file
function leibgood
error = 0.01;
N = 1;
S = 2;
runsum = 0;
difference = 1;
while error < difference
term = (-1)^S*4/N;
temp = runsum;
runsum = runsum + term;
difference = abs(temp-runsum);
N = N+2;
S = S+1;
end
fprintf('An approximation of pi using Leibniz ''series within %.2f is %.2f\n', error, runsum)
%print the value of pi.
end
% end of function
%The script file should be placed in the same folder.
Explanation of Solution
Machin’s formula is given as,
Leibniz’s formula is given as,
The approximation till the fourth term is given as,
MATLAB Code:
% MATLAB code to calcualte the value of pi.
%script file.
select = pivalues;
while select ˜= 4
switch select
%select the different options to get the value of pi.
case 1
machinformula
%print the result by usin Machin's formula.
case 2
leibn
%get approximate by using Leibniz.
case 3
leibgood
%approximate pi value using Leibniz untill good approximation.
end
select = pivalues;
end
% end of function
%The script file should be placed in the same folder.
% MATLAB code to calcualte the value of pi by different options.
%function file.
function select = pivalues
select = menu('select a option for pi', 'Machin''s formula', 'Leibniz''s formula:n-terms','Leibniz''s formula:good approximation','Exit');
%select the different options in menu.
while select == 0
disp('not valid! please select one of the options')
select = menu('select a option for pi', 'Machin''s formula', 'Leibniz''s formula:n-terms','Leibniz''s formula:good approximation','Exit');
end
end
% end of function
%The function file should be placed in the same folder.
% MATLAB code to calcualte the value of pi by Machinformula.
%function file.
function machinformula
formula = (4*atan(1/5)-atan(1/239));
%define the variable pivalues.
fprintf('Using the MATLAB constant, pi = %.6f\n', pi)
fprintf('the value of pi using Machin''s formula, pi = %.6f\n', 4*formula)
%print the value of pi.
end
% end of function
%The function file should be placed in the same folder.
% MATLAB code to calcualte the value of pi by leibniz's formula for the specific terms.
%function file.
function leibn
fprintf('Approximate value of pi by using Leibniz'' formula\n')
n = askforn;
approxvaluepi = 0;
denominator = -1;
signterm = -1;
for i = 1:n
denominator = denominator + 2;
signterm = -signterm;
approxvaluepi = approxvaluepi + signterm * (4/denominator);
end
fprintf('An approximation of pi with n = %d is %.2f\n', n, approxvaluepi)
end
function out = askforn
inputnum = input('A positive integer for n is entered: ');
num2 = int32(inputnum);
while num2 ˜= inputnum || num2 < 0
inputnum = input('Not Valid! Enter a positive integer:');
num2 = int32(inputnum);
end
out = inputnum;
end
% end of function
%The function file should be placed in the same folder.
% MATLAB code to calcualte the value of pi by leibniz's formula till the good apprroxiamtion is found..
%script file
function leibgood
error = 0.01;
N = 1;
S = 2;
runsum = 0;
difference = 1;
while error < difference
term = (-1)^S*4/N;
temp = runsum;
runsum = runsum + term;
difference = abs(temp-runsum);
N = N+2;
S = S+1;
end
fprintf('An approximation of pi using Leibniz ''series within %.2f is %.2f\n', error, runsum)
%print the value of pi.
end
% end of function
%The script file should be placed in the same folder.
Save the MATLAB script with name, main.m, and the function files with names machinformula.m, leibn.m, pivalues.m and leibgood.m in the current folder. Execute the program by typing the script name at the command window to generate result.
Result:
The results is,


Therefore, the result is stated above.
Want to see more full solutions like this?
Chapter 6 Solutions
Matlab, Fourth Edition: A Practical Introduction to Programming and Problem Solving
- mts ces urces A group of economists wants to compare the mean annual leave among the US and EU workers. Two samples of US and EU workers were obtained independently and analyzed. The sample of 45 US workers had the mean annual leave of 18.8 days and the standard deviation 9.05 days. The sample of 31 EU workers had the mean annual leave of 25.6 days and the standard deviation 5.38 days. Use 4% level of significance to decide whether there is sufficient evidence that mean annual leave of US workers is less than mean annual leave of EU workers. Procedure: Two means T Hypothesis Test Assumptions: (select everything that applies) Normal populations The number of positive and negative responses are both greater than 10 for both samples Population standard deviations are known Simple random samples Population standard deviation are unknown and not assumed equal Sample sizes are both greater than 30 Independent samples Paired samples Population standard deviation are unknown but assumed equal…arrow_forwardHow do the assumptions and characteristics of the linear regression model influence the reliability and robustness of inference drawn from its results in diverse research scenarios?arrow_forwardA group of economists wants to compare the mean annual leave among the US and EU workers. Two samples of US and EU workers were obtained independently and analyzed. The sample of 45 US workers had the mean annual leave of 18.8 days and the standard dediation 9.05 days. The sample of 31 EU workers had the mean annual leave of 25.6 days and the standard deviation 5.38 days. Use 4% level of significance to decide whether there is sufficient evidence that mean annual leave of US workers is less than mean annual leave of EU workers. Procedure: Select an answer Assumptions: (select everything that applies) Normal populations The number of positive and negative responses are both greater than 10 for both samples Population standard deviations are known Simple random samples Population standard deviation are unknown and not assumed equal Sample sizes are both greater than 30 Independent samples Paired samples Population standard deviation are unknown but assumed equal Part 1: Hypothesis Test..…arrow_forward
- A group of economists wants to compare the average annual leave among the US and EU workers. Two samples of US and EU workers were obtained independently and analyzed. The sample of 37 US workers had the average annual leave of 18 days and the standard deviation 9.07 days. The sample of 40 EU workers had the average annual leave of 26.8 days and the standard deviation 5.11 days. Use 10% level of significance to decide whether there is sufficient evidence that average annual leave of US workers is less than average annual leave of EU workers. Procedure: Two means T Hypothesis Test Assumptions: (select everything that applies) Population standard deviations are known Population standard deviation are unknown but assumed equal Independent samples Paired samples The number of positive and negative responses are both greater than 10 for both samples Sample sizes are both greater than 30 Population standard deviation are unknown and not assumed equal Normal populations Simple random samples…arrow_forwardLEAVE! A group of economists wants to compare the average annual leave among the US and EU workers. Two samples of US and EU workers were obtained independently and analyzed. The sample of 37 US workers had the average annual leave of 18 days and the standard deviation 9.07 days. The sample of 40 EU workers had the average annual leave of 26.8 days and the standard deviation 5.11 days. Use 10% level of significance to decide whether there is sufficient evidence that average annual leave of US workers is less than average annual leave of EU workers. Procedure: Two means T Hypothesis Test Assumptions: (select everything that applies) Population standard deviations are known Population standard deviation are unknown but assumed equal Independent samples Paired samples D The number of positive and negative responses are both greater than 10 for both samples Sample sizes are both greater than 30 Population standard deviation are unknown and not assumed equal Normal populations Simple random…arrow_forwardFall 2025 Home C Canvas - Homework 6 Secure Exam Proctor Proctorio) Announcements Modules A group of economists wants to compare the mean annual leave among the US and EU workers. Two samples of US and EU workers were obtained independently and analyzed. The sample of 34 US workers had the mean annual leave of 14.7 days and the standard deviation 7.95 days. The sample of 32 EU workers had the mean annual leave of 23.5 days and the standard deviation 3.86 days. Use 10% level of significance to decide whether there is sufficient evidence that mean annual leave of US workers is less than mean annual leave of EU workers. Procedure: Two means T Hypothesis Test くくる Discussions eople Grades enji brary Resources ampus Resources Assumptions: (select everything that applies) Independent samples simple random samples Population standard deviations are known Normal populations The number of positive and negative responses are both greater than 10 for both samples Population standard deviation are…arrow_forward
- octor es ces A group of economists wants to compare the mean annual leave among the US and EU workers. Two samples of US and EU workers were obtained independently and analyzed. The sample of 34 US workers had the mean annual leave of 14.7 days and the standard deviation 7.95 days. The sample of 32 EU workers had the mean annual leave of 23.5 days and the standard deviation 3.86 days. Use 10% level of significance to decide whether there is sufficient evidence that mean annual leave of US workers is less than mean annual leave of EU workers. Procedure: Two means T Hypothesis Test Assumptions: (select everything that applies) Independent samples Simple random samples Population standard deviations are known Normal populations The number of positive and negative responses are both greater than 10 for both samples Population standard deviation are unknown but assumed equal Paired samples Sample sizes are both greater than 30 Population standard deviation are unknown and not assumed equal…arrow_forwardQuestion 4 ANNUAL LEAVE 2.19/3 pts 29 Part 1 of 6 A group of economists wants to compare the mean annual leave among the US and EU workers. Two samples of US and EU workers were obtained independently and analyzed. The sample of 34 US workers had the mean annual leave of 14.7 days and the standard deviation 7.95 days. The sample of 32 EU workers had the mean annual leave of 23.5 days and the standard deviation 3.86 days. Use 10% level of significance to decide whether there is sufficient evidence that mean annual leave of US workers is less than mean annual leave of EU workers. Procedure: Select an answer Assumptions: (select everything that applies) Independent samples Simple random samples Population standard deviations are known Normal populations The number of positive and negative responses are both greater than 10 for both samples Population standard deviation are unknown but assumed equal Paired samples Sample sizes are both greater than 30 Population standard deviation are…arrow_forwardYou may want to use the Excel Two Means Calculator found in the Course to complete this problem. You want to estimate the difference between the mean GPA of day students (Group 1) and the mean GPA of night students (Group 2) with a 94% confidence. A random sample of 13 day students and 14 night students and their GPA's are recorded below. It is reasonable to assume samples represent populations with normal distributions. Click this button to reveal the data. Click again to collapse it. GPA-Day GPA-Night 3.22 3.19 3.36 3.19 3.6 3.1 2.97 3.09 3.11 3.36 2.57 3.18 3.46 3.43 3.01 3.13 3.06 3.15 3.31 3.12 3.22 3.4 3.06 3.27 2.97 3.18 3.38 Click Download CSV to download csv file of data or copy/paste the data into Excel. After downloading the file, you may want to save it as an Excel Workbook. All conditions are met for inference using Two-Sample T-Confidence Interval because there are two independent random samples and populations have normal distributions. Round answers properly to 2…arrow_forward
- Proctor ents An economist wants to compare average hourly rate charged by automobile mechanics in two suburbs. She randomly selects auto repair facilities from both suburbs and records their hourly rates (in dollars). The data are as follows: Click this button to reveal the data. Click again to collapse it. Suburb1 Suburb2 39.5 44.6 33.3 39.5 43.9 29.6 37.7 31.2 42 44.3 32.9 46.3 33.5 46.4 46 47.3 41.6 20.1 43.4 33.9 ources 34.1 45.6 44.3 44.1 esources 43.1 35.8 36.5 36.6 42.1 32.5 Note: If using Excel, after copying the given data, use Paste Special and select "Unicode Text" to paste the data properly. After pasting, double check the number of data in each column to make sure those are pasted properly. If using Ti calculator, check sum of the data before analyzing: 593.9 for Suburb 1 and 577.8 for Suburb 2 Use 3% level of significance to decide whether there is sufficient evidence that the average hourly rate charged by automobile mechanics in suburb 1 is greater than the average…arrow_forward3:51 myopenmath.com Get a similar question You can retry this question below 89 סוי A school administrator wants to see if there is a difference in the number of students per class for the Portland Public School district (Group 1) compared to the Beaverton School district (Group 2). Let μ₁ be the average number of students per class for the Portland Public School district. Let u₂ be the average number of students per class for the Beaverton School district. Assume the populations are normally distributed. A random sample of 28 Portland classes found a mean of 33 students per class with a standard deviation of 6. A random sample of 27 Beaverton classes found a mean of 38 students per class with a standard deviation of 4. a. Find a 98% confidence interval for the difference of the means. Use Excel Two Means Calculator found in the Course and round answers to 2 decimal places. <11-12 < b. Select the correct conclusion based on the < above confidence interval. Since the above dencente…arrow_forwardDon't use AI please for this statistics question.arrow_forward
- Algebra & Trigonometry with Analytic GeometryAlgebraISBN:9781133382119Author:SwokowskiPublisher:Cengage
Mathematics For Machine TechnologyAdvanced MathISBN:9781337798310Author:Peterson, John.Publisher:Cengage Learning,
Elementary AlgebraAlgebraISBN:9780998625713Author:Lynn Marecek, MaryAnne Anthony-SmithPublisher:OpenStax - Rice University
Algebra: Structure And Method, Book 1AlgebraISBN:9780395977224Author:Richard G. Brown, Mary P. Dolciani, Robert H. Sorgenfrey, William L. ColePublisher:McDougal Littell
Trigonometry (MindTap Course List)TrigonometryISBN:9781305652224Author:Charles P. McKeague, Mark D. TurnerPublisher:Cengage Learning
Glencoe Algebra 1, Student Edition, 9780079039897...AlgebraISBN:9780079039897Author:CarterPublisher:McGraw Hill




