
Concept explainers
To write:
A menu-driven program to investigate the constant
Answer to Problem 29E
Solution:
The script file is,
clc
clear all
close all
% MATLAB code to calcualte the value of pi by different options.
%script file.
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 choose one of the choices')
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 script file should be placed in the same folder.
The script file is,
% MATLAB code to calcualte the value of pi by Machinformula.
%script file.
function machinformula
pivalues = 4*(4*atan(1/5)-atan(1/239));
%define the variable pivalues.
fprintf('the value of pi using Machin''s formula is%.4f\n', pivalues)
%print the value of pi.
end
% end of function
%The script file should be placed in the same folder.
The script file is,
% MATLAB code to get the value of integer.
%script file.
function out = valuen
out = input('A positive integer for n is entered:');
%the value of positive integer is entered.
while out˜= int32(out)||out<=0
out = input('not valid! A posiytive integer for n is entered:');
end
end
% end of function
%The script file should be placed in the same folder.
The script file is,
% MATLAB code to calcualte the value of pi by leibniz's formula for the specific terms.
%script file.
function leibn
out = valuen;
numerat = -4.*cumprod(-ones(1, out));
%define the variable numerat as numerator.
denomina = 1:2:2*out;
%define the variable denomina as denominator.
pievalues = sum((numerat)./(denomina));
fprintf('the approximation of Leibniz for pi with %d terms is %.4f\n', out, pievalues);
%print the value of pi.
end
% end of function
%The script file should be placed in the same folder.
The script 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.
The main script file is,
% MATLAB code to calcualte the value of pi.
%script file.
select = -1;
while select ˜= 4
select = pivalues;
switch select
%select the different options to get the value of pi.
case 1
machinformula
case 2
leibn
case 3
leibgood
end
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 by different options.
%script 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 choose one of the choices')
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 script file should be placed in the same folder.
% MATLAB code to calcualte the value of pi by Machinformula.
%script file.
function machinformula
pivalues = 4*(4*atan(1/5)-atan(1/239));
%define the variable pivalues.
fprintf('the value of pi using Machin''s formula is%.4f\n', pivalues)
%print the value of pi.
end
% end of function
%The script file should be placed in the same folder.
% MATLAB code to get the value of integer.
%script file.
function out = valuen
out = input('A positive integer for n is entered:');
%the value of positive integer is entered.
while out˜= int32(out)||out<=0
out = input('not valid! A posiytive integer for n is entered:');
end
end
% end of function
%The script file should be placed in the same folder.
% MATLAB code to calcualte the value of pi by leibniz's formula for the specific terms.
%script file.
function leibn
out = valuen;
numerat = -4.*cumprod(-ones(1, out));
%define the variable numerat as numerator.
denomina = 1:2:2*out;
%define the variable denomina as denominator.
pievalues = sum((numerat)./(denomina));
fprintf('the approximation of Leibniz for pi with %d terms is %.4f\n', out, pievalues);
%print the value of pi.
end
% end of function
%The script 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.
% MATLAB code to calcualte the value of pi.
%script file.
select = -1;
while select ˜= 4
select = pivalues;
switch select
%select the different options to get the value of pi.
case 1
machinformula
case 2
leibn
case 3
leibgood
end
end
% end of function
%The script file should be placed in the same folder.
Save the MATLAB scripts with names, pivalues.m, machinformula.m, valuen.m, leibn.m, leibgood.m and main.m in the current folder. Execute the script by typing the script name at the command window to generate result.
Result:
The results is,


Therefore, the result and script files are stated above.
Want to see more full solutions like this?
Chapter 6 Solutions
MATLAB: A Practical Introduction to Programming and Problem Solving
- Does it take less time for seeds to germinate if they are near rock music that is continuously playing compared to being near classical music? The time (in days) to germinate was recorded for 30 seeds that were randomly exposed to rock music took and 26 seeds that were randomly exposed to classical music. a. Based on the given information, select ALL that are true about these data. There are two independent random samples of numerical data. Samples are not random. There are two paired random samples of numerical data. Each sample size is large enough. Each population has a normal distribution. At least one sample size is not large enough. Data are not numerical. Each sample data have approximately a normal distribution with no outliers. b. Are all the assumptions met for a two-sample t-test? Yes O No > Next Question to search UP T M365 F2 F3 F4 <400 2 144 64 $ DELL F5 F6 F7 F8 ►11 25 %arrow_forward4 Cor The following data show the results of two random samples that measured the average number of minutes per charge for AA Lithium-ion (Li-ion) rechargeable batteries versus Nickel-Metal Hydride (NiMH) rechargeable batteries. Click this button to reveal the data. Click again to collapse it. Li-ion NiMH 107 86 95 91 87 89 84 88 89 88 98 87 95 86 85 90 84 91 96 85 97 87 100 89 86 91 102 89 87 94 78 arch If you want to do well, please avoid using Google sheets. Perform a hypothesis test using significance level (a) = .02 to determine if the true average number of minutes per charge for NiMH batteries is different from that for Li-ion batteries. a. Perform a two-sample t test to test the claim that the true average number of minutes per charge for Li-ion batteries is different from that for NiMH batteries. Fill in the blanks for the alternative hypothesis of this test. Select an answer Select an answer Based on your work, answer the following questions. The observed difference in mean…arrow_forwardmts 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_forward
- How 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_forwardA 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_forward
- LEAVE! 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_forwardoctor 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_forward
- Question 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_forwardProctor 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_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




