e_to_the_x_function

# e_to_the_x_function - delta_par double expx1 expx2,fact...

This preview shows page 1. Sign up to view the full content.

#include <iostream> #include <cmath> using namespace std; double expx( double x_par, double delta_par); //calculates the exponental function of x_par //using the tayler series to an accuracy of delta_par int main() { double x, delta, answ; char ans; cout << "enter a value for x " ; cin >> x ; cout << "now enter a value for delta " ; cin >> delta; answ = expx(x,delta); cout << "x " << x << " expx " << answ; return 0; } double expx( double x_par, double
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: delta_par) { double expx1, expx2 ,fact, error; int k; k = 2; fact = 2; expx1 =1; expx2 = expx1 + pow(x_par,1); error = (expx1-expx2)/expx1; while (fabs(error)> delta_par) { expx1 = expx2; expx2 = expx2 + pow(x_par,k)/fact; // cout << " k " << k << endl; This statement can be used to help with debugging k++; fact = fact*k; error = (expx1-expx2)/expx1; } return expx2; }...
View Full Document

## This note was uploaded on 02/05/2012 for the course CIS 210 taught by Professor Feinstein during the Fall '10 term at S. Alabama.

Ask a homework question - tutors are online