The exponential function can be defined using the following power series: ch 12 23 24 et 1+2+ + + +. k! 2 6 24 Σ k=0 Wri

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

The exponential function can be defined using the following power series: ch 12 23 24 et 1+2+ + + +. k! 2 6 24 Σ k=0 Wri

Post by answerhappygod »

 1
1 (164.11 KiB) Viewed 56 times
The exponential function can be defined using the following power series: ch 12 23 24 et 1+2+ + + +. k! 2 6 24 Σ k=0 Write a C++ program which calculates an approximation of the exponential using the series above the code is partially given for you in the next page). The program should ask the user to input x (of type double) and N (of type int). The program then calculates and prints an approximation of et using the first N +1 terms of the series, i.e., it computes Ek k! For computing powers, you can use the pow function from the <math.h> library (write pow(x,k) to compute zk). On the other hand, remember that " !" is used in C++ for negation, and so you cannot use it for calculating factori- als. Instead, we will define and use our own factorial function: copy the code snippet below and fill in the gaps. Do not change the code, just replace the comments at lines 22 and 23 with the missing part. To compute k!, just write factorial(k), where factorial is the function that is defined before main (you are not expected to understand the function implementation for now; you will learn about functions later). You can see that at the end, we are printing two values for the exponential: the approximation that you computed, and the exact value using the erp func- tion from the <math.h> library. This allows you to compare and verify the correctness of your approximation (which should converge to the exact value if N is large enough). Finally, notice that the code has a syntax error at line 27, because "approx” is not defined, and so you will need to define it and store in it the result of your approximation.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply