Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In python 3, write function computeE(n) to compute e to n1 significant digits, using Bernoullis formula e= limk(1 +1/k)^k and a while loop. In this

In python 3, write function

computeE(n) to compute e to n1 significant digits, using Bernoullis formula e= limk(1 +1/k)^k and a while loop. In this question, we will define the answer to be correct to n significant digits when two consecutive approximations agree to n significant digits. When two consecutive approximations agree to n significant digits, return the later approximation (which will be more accurate). For example, if (1 +1/4)^4 and (1 +1/5)^5 agree to ndigits, then you would return (1 +1/5)^5. I recommend using the helper function "sig(a,b) to solve this problem, which takes a float (a) and number of significant digits (b) to calculate a expressed to b. Start with k= 1, the smallest relevant k for Bernoullis formula.

Recall that, since e is an irrational number like 2, the decimal representation of e requires an infinite number of digits, so we can only approximate e. In the context of our recent discussion of logarithms, the natural log (ln x = loge (x)) is the log with base e. Just as computations simplify in computer science when you start counting at 0, computations become more elegant in mathematics and physics when you use the natural logarithm.

This is the helper function that is given:image text in transcribedEX: input=1,

DO NOT ANSWER IF ALL THE OUTPUTS DONT MATCH PLEASE!!!!

input =1 output=2.25

input=2, output=2.44140625

input=3,output=2.6328787177279187

# helper function: please do not change import decimal def significant (d, n): """Given a desired precision, express a float to this level of precision. >>> significant (12.345678, 4) 12.35 Params: d (float): # of interest n (int): precision (# significant digits) Returns: (float) d rounded to this precision 191 decimal.getcontext).precn return float (decimal.Decimal(d) / decimal.Decimal (1)) # helper function: please do not change import decimal def significant (d, n): """Given a desired precision, express a float to this level of precision. >>> significant (12.345678, 4) 12.35 Params: d (float): # of interest n (int): precision (# significant digits) Returns: (float) d rounded to this precision 191 decimal.getcontext).precn return float (decimal.Decimal(d) / decimal.Decimal (1))

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

Visual C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

More Books

Students also viewed these Databases questions