Taylor series exponential

Represent an exponential function as Taylor series. Iterate the function 10 times.

Hint:

Find the approximated Solution of x = 0.5

float x = 0.5f;

float Sum = 0f;

float pot = x;

int n = 1;

int counter = 1;

while(counter != 10) {

n *= counter; 
// compute faculty number 1 = 1; 2 = 1*2;3=1*2*3
if(counter == 1) {  // first Condition x = 1

 Sum = 1+((x)/n); // first term + 1

                    }

 else {                  
// other conditions start with x*x/2!

pot = pot*x;

Sum += pot/n;

}

 counter++; 

}

System.out.println(Sum);

Solution: 1.6487213

Leave a Reply

Your email address will not be published. Required fields are marked *