Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use Excel VBA functions to answer while following the prompt. Exam 4 - Corrosion and Chemical Engineering Computations April 2022 STLDENI NAME (PLEASE PRINT

Please use Excel VBA functions to answer while following the prompt.

image text in transcribedimage text in transcribed

Exam 4 - Corrosion and Chemical Engineering Computations April 2022 STLDENI NAME (PLEASE PRINT LEGIBLY) Problem 1. (total 50-points) As you know, Pi is an irrational number. However, it can be approximated using the GregoryLeibniz series. =k=12k1(1k+1)4 While not very efficient computationally, each added term of this series makes the approximation closer to pi. Thus, the first terms of the sequence are: =(14)(34)+(54)(74)+(94)(114)+(134)(154) Hints/Notes: 1) An entirely too long value for Pi is 3.1415926535897932384626 . You can use this value to check your work. 2) The nature of this program is such that all floating-point variables should be specified as Double precision and all integers should be specified as Long. 3) Successfully implementing this function requires the use of the "Power" function from the workbook view of Excel. To apply this function in a program, you will need to include the following two lines of VBA code Dim Power As Double and Power=Application.WorksheetFunction.Power(1,k+1) The first line creates a double precision variable "Power", while the second line computes the 1k+1 term and inserts the result into a variable "Power". Both lines of code are available for you to copy and paste into your function in the Exam's Excel Workbook. 4) When implemented this program is slow, so I recommend that you only run it for the accuracies specified in the problem during the Exam. Write a Function called PoP that calculates pi to a specified number of significant digits Part 1) (5-points) Create a new module to hold your function. In that module, create a Public Function POP with a single input variable. The input (Delta) should indicate the number of places past the decimal that you wish your value of pi to have as valid. For example, Pop(0.0001) Exam 4 - Corrosion and Chemical Engineering Computations April 2022 STUDENT NAME (PLEASE PRINT LEGIBLY) Should return pi to three places past the decimal point (3.141 c..) correctly. When I ran my function, I got 3.141642651. Comparing this value with the value of 3.1415926535897932384626 for pi indicates that numbers after the second 1 are still changing. Part 2) (4-points) Give all your variables meaningful names, appropriate precision, and a comment describing the contents of variable and a comment defining the variable, e.g., Dim DeltaPi As Double 'the current term of the summation 2k1(1k+1)4 Part 3) (3-points) Initialize the following variables: a counter (k=1) for your Do While Loop, the absolute value of the change in the value of pi for the current iteration (AbsDeltaPi =100), and the initial value for pi (Pie=0). Part 4) (10-points) Implement a Do While loop that exits the computation when the absolute value of the term being added to your summation is less than the specified value for Delta entered in the input. Part 4) (10-points) Implement the Gregory-Leibniz series within your loop. Part 5) (5-points) Return the value of PoP containing the estimate for pi with the specified number of correct digits. Part 6) (4-points) Calculate for Delta =0.001 and for Delta =0.000001 Part 7) (9-points) Fully comment your program. Your comments should contain the following - A short description of the code's function (1 to 2 sentences) - The author's name and the date. - Section headings for block of code such as: 1 Computes the Gregory-Leibniz series or - Returns results to PoP Exam 4 - Corrosion and Chemical Engineering Computations April 2022 STLDENI NAME (PLEASE PRINT LEGIBLY) Problem 1. (total 50-points) As you know, Pi is an irrational number. However, it can be approximated using the GregoryLeibniz series. =k=12k1(1k+1)4 While not very efficient computationally, each added term of this series makes the approximation closer to pi. Thus, the first terms of the sequence are: =(14)(34)+(54)(74)+(94)(114)+(134)(154) Hints/Notes: 1) An entirely too long value for Pi is 3.1415926535897932384626 . You can use this value to check your work. 2) The nature of this program is such that all floating-point variables should be specified as Double precision and all integers should be specified as Long. 3) Successfully implementing this function requires the use of the "Power" function from the workbook view of Excel. To apply this function in a program, you will need to include the following two lines of VBA code Dim Power As Double and Power=Application.WorksheetFunction.Power(1,k+1) The first line creates a double precision variable "Power", while the second line computes the 1k+1 term and inserts the result into a variable "Power". Both lines of code are available for you to copy and paste into your function in the Exam's Excel Workbook. 4) When implemented this program is slow, so I recommend that you only run it for the accuracies specified in the problem during the Exam. Write a Function called PoP that calculates pi to a specified number of significant digits Part 1) (5-points) Create a new module to hold your function. In that module, create a Public Function POP with a single input variable. The input (Delta) should indicate the number of places past the decimal that you wish your value of pi to have as valid. For example, Pop(0.0001) Exam 4 - Corrosion and Chemical Engineering Computations April 2022 STUDENT NAME (PLEASE PRINT LEGIBLY) Should return pi to three places past the decimal point (3.141 c..) correctly. When I ran my function, I got 3.141642651. Comparing this value with the value of 3.1415926535897932384626 for pi indicates that numbers after the second 1 are still changing. Part 2) (4-points) Give all your variables meaningful names, appropriate precision, and a comment describing the contents of variable and a comment defining the variable, e.g., Dim DeltaPi As Double 'the current term of the summation 2k1(1k+1)4 Part 3) (3-points) Initialize the following variables: a counter (k=1) for your Do While Loop, the absolute value of the change in the value of pi for the current iteration (AbsDeltaPi =100), and the initial value for pi (Pie=0). Part 4) (10-points) Implement a Do While loop that exits the computation when the absolute value of the term being added to your summation is less than the specified value for Delta entered in the input. Part 4) (10-points) Implement the Gregory-Leibniz series within your loop. Part 5) (5-points) Return the value of PoP containing the estimate for pi with the specified number of correct digits. Part 6) (4-points) Calculate for Delta =0.001 and for Delta =0.000001 Part 7) (9-points) Fully comment your program. Your comments should contain the following - A short description of the code's function (1 to 2 sentences) - The author's name and the date. - Section headings for block of code such as: 1 Computes the Gregory-Leibniz series or - Returns results to PoP

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Chemical Engineering Thermodynamics

Authors: J. M. Smith, H. C. Van Ness, M. M. Abbott

7th edition

71247084, 978-0071247085

More Books

Students also viewed these Chemical Engineering questions