Question

C++ please! Write a recursive function to compute the sum of the Taylor series. use double...

C++ please! Write a recursive function to compute the sum of the Taylor series.

use double taylor(int a, int n)

Homework Answers

Answer #1

Here is your code -

#include <stdio.h>

// Recursive Function with static

// variables p and f

double taylor(int a, int n)

{

static double taylor p = 1, f = 1;

double r;

if (n == 0)

return 1;

r = taylor(a, n - 1);

p = p * a;

// Factorial

f = f * n;

return (r + p / f);
}

// Driver code
int main()
{
   int a = 4, n = 5;
   printf("%lf \n", taylor(a, n));

   return 0;
}

-----------------------------------------------------------

If you feel your purpose is not solved, go with this code. Although both are 100% working code. PLEASE DO GIVE A 'LIKE' ON MY POST. THANKS! DO COMMENT DOWN, IF YOU NEED ANY EXPLANATION OR ANY HELP REGARDING THIS QUESTION!


#include<stdio.h>
#include<math.h>

int main()
{
  
int x,i;
int fact = 1,n;
float sum=0;

cout<<"Enter the value of x in the series :";
cin>>x;

cout<<"Enter the number of terms in the series :";
cin>>n;

for(i=1;i<n;i++)
{
fact = fact*i;
sum = sum + (pow(x,i)/fact) ;

}
sum= sum +1; //Since series starts with 1

cout<<"The sum of the taylor series is :"<<sum;
return 0;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Please write a Taylor series function. C++
Please write a Taylor series function. C++
Use the definition of Taylor series to find the Taylor series (centered at c) for the...
Use the definition of Taylor series to find the Taylor series (centered at c) for the function. f (x) = e3x,   c = 0
Consider the following function: double arrayavg(int a[], int n){ int sum=0; for(int i=0; i!=n; ++i){ sum+=a[i];...
Consider the following function: double arrayavg(int a[], int n){ int sum=0; for(int i=0; i!=n; ++i){ sum+=a[i]; } return (double)sum/n; } Rewrite the function to eliminate the array subscripting (a[i]), using pointer arithmatic instead. Write a program that reads a line of input and checks if it is a palindrome (ignoring spaces) Write a program that takes the name of a file as a command line argument, and prints the contents of the file (similar to the linux 'cat' program). Write...
Please write function in Racket language. Write a recursive Racket function "sum-diff" that takes two lists...
Please write function in Racket language. Write a recursive Racket function "sum-diff" that takes two lists of integers that are the same length and evaluates to an integer. The resulting integer should be the sum of the absolute value of the differences between each pair of integers with the same index in the two lists. For example (sum-diff '(-1+2+3)'(123)) should evaluate to 12 because the absolute value of the differences between (-1 and 1), (-2 and 2) and (-3 and...
For this problem, consider the function f(x) = ln(1 + x). (a) Write the Taylor series...
For this problem, consider the function f(x) = ln(1 + x). (a) Write the Taylor series expansion for f(x) based at b = 0. Give your final answer in Σ notation using one sigma sign. (You may use 4 basic Taylor series in TN4 to find the Taylor series for f(x).) (b) Find f(2020) (0). Please answer both questions, cause it will be hard to post them separately.
Write a recursive method “int sumPos(int a[], int n)” to calculate the sum of positive integers...
Write a recursive method “int sumPos(int a[], int n)” to calculate the sum of positive integers in an array of n integers, a[]. No global variables are allowed. No other method is allowed to be called by sumPos() except itself. (Hint: The integers in an array a[] of n integers are stored in a[0], a[1], ... a[n-1].)
Please do it in c++, will up vote!! create a recursive function to perform a factorial...
Please do it in c++, will up vote!! create a recursive function to perform a factorial calculation. - int factorial(const int value) - return -1 if any negative number passed into the function - Calculate the factorial of the number entered by the use Determine value at which stack overflow occurs.
FOR C PROGRAMMING LANGUAGE Write a recursive C PROGRAMMING LANGUAGE function int sumStrlens(const char* str1, const...
FOR C PROGRAMMING LANGUAGE Write a recursive C PROGRAMMING LANGUAGE function int sumStrlens(const char* str1, const char* str2) which returns the sum of strlen(str1) and strlen(str2). You can assume that strlen(str2) is always strictly greater than strlen(str1) (strlen(str2) > strlen(str1)). You MAY NOT use any function from string.h. You MAY NOT use any square brackets([]) or any type of loops in function.
[ Write in C not C++] Define a C function int round10(double n) that returns the...
[ Write in C not C++] Define a C function int round10(double n) that returns the closest integer of n which is divisible by 10. For example, if n = 16.0, the return value is 20 and if n = 32.34, the return value is 30.
C++ Write a recursive function that reverses the given input string. No loops allowed, only use...
C++ Write a recursive function that reverses the given input string. No loops allowed, only use recursive functions. Do not add more or change the parameters to the original function. Do not change the main program. I had asked this before but the solution I was given did not work. #include #include using namespace std; void reverse(string &str) { /*Code needed*/ } int main() {    string name = "sammy";    reverse(name);    cout << name << endl; //should display...