e_to_the_x_function

e_to_the_x_function - delta_par) { double expx1, expx2...

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

View Full Document Right Arrow Icon
#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
Background image of page 1
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)&gt; delta_par) { expx1 = expx2; expx2 = expx2 + pow(x_par,k)/fact; // cout &lt;&lt; &quot; k &quot; &lt;&lt; k &lt;&lt; endl; This statement can be used to help with debugging k++; fact = fact*k; error = (expx1-expx2)/expx1; } return expx2; }...
View Full Document

Ask a homework question - tutors are online