Question: Please Code in C The exponential function exp(2) = eappears in many physical, biological and financial phenomena: Radioactive substances decay at exponential rate. Pandemic viruses

Please Code in C

Please Code in C The exponential function exp(2) = eappears in many

physical, biological and financial phenomena: Radioactive substances decay at exponential rate. Pandemic

The exponential function exp(2) = eappears in many physical, biological and financial phenomena: Radioactive substances decay at exponential rate. Pandemic viruses may have exponential growth (or exponential decay when contained). Interest-on-interest provokes exponential growth of monetary wealth. The exponential function is mathematically interesting as its derivative (the slope of its curve when drawn) is the function itself: d e". dc In order to enable simulation of the physical, biological or financial phenomena discussed above, computers must be able to compute the values of the exponential function, given a value for its argument x. This computation runs in software, as computer hardware does not contain circuits to compute the exponential. Fast and accurate algorithms to compute the exponential functions are hard to develop. Their design requires precise knowledge of the internal workings of floating-point hardware. There is an easy way to compute the exponential for a value x between -1 and 1. This way of computing the exponential is based on a Taylor expansion of the exponential at 0: 1 1 e* = -z = 1+1.2+==+ 23 + i! 2.3 1 r* +... 2.3.4 i=0 This Taylor expansion converges, so an approximation to the exponential can be obtained by computing 72 1 z = 1+1.7+= 1 + 2.3 .23 + 1 r4+ 2.3.4 1 + 2" n! Write a program exponential.c that does the following: Asks the user to enter a real number r that is between - 1 and 1 (both included). If the user enters a number that does not satisfy this condition, the program prompts the user again, until a number 2 s.t. -1 0 is entered. See below for examples. The program then computes an approximation y to the exponential e" by summing up, on y, which is initialized to the different terms of the sum 42. The program uses a loop on i from 0 to n (both included) to do so. In the loop, the values (i = 1 and Pi = ri are maintained. = 2 Observe that: - As i moves from 2 to 3 for example, the value c; moves from c2 = 1, to c3 = 1.2.3. This means c3 . - As i moves from 2 to 3 for example, the value P; moves from p2 = 22 to P3 73 = 22.1. This means P3 = P2.2. - The values C; and pi are all real numbers, so they must be maintained on double variables. After the loop, the program displays the approximation to em it computed, as well as the math library's result obtained with a call to exp(x). See below for examples. Caution: your program must not use any other function out of the math library, such as pow (x,y). These are examples of input and output for this program: Please enter a real number between -1.0 and 1.0: 0.0 Please enter a non-negative integer number: 17 Our approximation of exp(0.000000) 1.000000. The math library says: exp(0.000000) = 1.000000. Please enter a real number between -1.0 and 1.0: 1.0 Please enter a non-negative integer number: 17 Our approximation of exp (1.000000) 2.718282. The math library says: exp(1.000000) = 2.718282. Please enter a real number between -1.0 and 1.0: 0.69 Please enter a non-negative integer number: 17 Our approximation of exp (0.690000) 1.993716. The math library says: exp(0.690000) = 1.993716. Please enter a real number between -1.0 and 1.0: 2 Sorry. Your input, 2.000000, is out of bounds. Try again. Please enter a real number between -1.0 and 1.0: -1 Please enter a non-negative integer number: -1 Sorry. Your input, -1, is incorrect. Try again. Please enter a non-negative integer number: 17 Our approximation of exp(-1.000000) 0.367879. The math library says: exp(-1.000000) = 0.367879

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!