The function 11x2 can be approximated using a specific type

The function 1/(1-x)^2 can be approximated using a specific type of Taylor Series as follows:

1/(1-x)^2 = 1x^0+2x^1+3x^2+......nx^(n-1) for lxl<1

Write a program to calculate the series approximation using a \"for\" loop running from 1 to k. Also, calculate the correct value. Test the code for k=5, k=15, and k=25 with x=2/3.

Solution

code:

#include <iostream>
#include<math.h>
using namespace std;
float eval(int k)
{
   int i=1;
   float x =0.66;
   float sum=0;
   while(i<=k)
   {
       sum+= (i*pow(x,i-1));
       i++;
   }
   return sum;
}
int main()
{
  
   int k1=5;
   int k2=15;
   int k3 =25;
   cout<<eval(k1)<<endl;
   cout<<eval(k2)<<endl;
   cout<<eval(k3)<<endl;
   return 0;
}

Output:

5.72552

8.54688

8.64799

The function 1/(1-x)^2 can be approximated using a specific type of Taylor Series as follows: 1/(1-x)^2 = 1x^0+2x^1+3x^2+......nx^(n-1) for lxl<1 Write a pro

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site