Question

In: Computer Science

Build a program to calculate the value of e ( 2.71828) raised to the power of...

Build a program to calculate the value of e ( 2.71828) raised to the power of x (the independent variable). The function is based on the series expansion shown in class. Compare your result to the predefined function exp(x) as stated in the standard file ( cmath ). Your input will be " x" and "n" where n is the number of terms in the expansion and x is an arbitrary value of your choice. Have your output display your calculated value to the cmath value.

I am using C++, show in detail.

Solutions

Expert Solution

Screenshot of the code:

Sample Output:

Code To Copy:

//Include the header file.

#include <bits/stdc++.h>

using namespace std;

//Define the function to compute the

//e power x

float exp_func(int n, float x)

{

//Define the variable sum;

float result_sum = 1.0f;

for (int i = n - 1; i > 0; --i )

{

    //Compute the sum of the exponential series.

    result_sum = 1 + x * result_sum / i;

}

//Return the summation of the series.

return result_sum;

}

//Define the main function.

int main()

{

//Declare the variables.

int n;

float x;

//Prompt the user to enter the value of x.

cout << "Enter the value of x to raise the power: ";

cin >> x;

//Prompt the user to enter the number of terms.

cout << "Enter the number of n terms: ";

cin >> n;

//Display the resultant value of the series.

cout << "e^x = " << fixed << setprecision(5)

       << exp_func(n, x) << endl;

//Return the value for the main function.

return 0;

}


Related Solutions

1. Use excel function exp( ) to calculate raising e to the power of (-2.5 +...
1. Use excel function exp( ) to calculate raising e to the power of (-2.5 + 2*X1 + 3*X2), where X1=5.6 and X2=3. 2. Denote the result from part 1 as Y, calculate the Y/(1+Y), and let us denote this ratio as prob, i.e., prob= Y/(1+Y). Demonstrate the quantity is sandwiched by this interval (0, 1) by trying different values of X1 and X2. Also realize the any quantity that is capped between 0 and 1 can lend itself to...
JAVA program: Calculate geometric area for 3 shapes(square, rectangle and circle). You need to build a...
JAVA program: Calculate geometric area for 3 shapes(square, rectangle and circle). You need to build a menu that allows users to enter options. Possible options are 'S' for square, 'R' for rectangle and 'C' for circle. HINT: you can use switch statement to switch on string input Invalid input should throw a message for the user. Example: Invalid input, please try again Each options should ask users for relevant data. HINT: use scanner object to take in length for square,...
We have to calculate the value of Power of an electric DC motor IN WATTS made...
We have to calculate the value of Power of an electric DC motor IN WATTS made from scratch. The only known values that we have are: The Voltage (V) which is 9V and the current (I) that we are using which is 3 A, also the value of "n" which is n= 90.16 m (the number of turns of the wire used in the motor) I already asked here for this problem and someone answered this: Voltage = 9 V,...
Engineer E and Owner O are engaged in contract negotiations for E to design and build...
Engineer E and Owner O are engaged in contract negotiations for E to design and build a building for O. The proposed contract is for $200,000. The estimated duration of the turnkey project is 15 months. After reaching an oral agreement of the above, O tells E that they should get together over the next few weeks to hammer out the contract language details for a formal written contract. E begins work without notifying O and completes approximately 30% of...
Calculate the bank’s assets (A), liabilities (L) and its current value, or equity (E).
Bank Balance Sheet (Note: Use this information for all three problems) Item                             Amount            Duration       Interest Rate        Cash-type Securities       $50m                1.2 year             2.25% Commercial Loans          $100m             2.4 years           4.50% Mortgages                     $350m             8.0 years           6.50% Core Deposits                $270m             1.0 year             2.00% Notes Payable                $180m             2.0 years           4.50% 1. Deposit Outflow Analysis (6 points) a. Calculate the bank’s assets (A), liabilities (L) and its current value, or equity (E). b. Calculate the bank’s Net Income (Interest Income – Interest Expense) for the current...
Governor John has decided that, rather than build a new nuclear power plant to service power...
Governor John has decided that, rather than build a new nuclear power plant to service power needs, the state should save an equivalent amount of energy. As one component of an efficiency plan, he has turned to you, his top aide, to design a policy to encourage adoption of compact fluorescent (CF) lightbulbs. Although CFs save a tremendous amount of money (and energy) over their lifetime, they are quite expensive initially ($20 or so per bulb in 1993). In addition,...
Parse string java code Write a recursive program that can calculate the value of a given...
Parse string java code Write a recursive program that can calculate the value of a given polynomial in a string, which is not more than the tenth order, for the given x. The polynomial will be given in the following format and should display the value of the polynomial for spaced-out x Using index of for -/+
The U.S. Department of Interior is planning to build a dam and construct a hydroelectric power...
The U.S. Department of Interior is planning to build a dam and construct a hydroelectric power plant. In addition to producing electric power, this project will provide flood control, irrigation, and recreational benefits. The estimated benefits and costs expected to be derived from the three alternatives under consideration are listed as follows: Design 1 - Initial invesment = $198 million - Annual recurring benefits = $37 million - Annual recurring costs = $15 million Design 2 - Initial investment =...
Explain whether the value of the original stockholders investment depends on the amount raised in the...
Explain whether the value of the original stockholders investment depends on the amount raised in the capital market to finance the investment and why
The solubility product constant for CuI(s) is 1.1 x 10^-12. Calculate the value of E knot...
The solubility product constant for CuI(s) is 1.1 x 10^-12. Calculate the value of E knot for the half-reactoin: CuI + e- ---> Cu + I-. For Cu+ + e- ---> Cu, E knot = 0.52V
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT