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
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 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.
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.
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...
[ 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.
IN C++ AS SIMPLE AS POSSIBLE ______ Re-write the given function, printSeriesSquareFifth,  to use a while loop...
IN C++ AS SIMPLE AS POSSIBLE ______ Re-write the given function, printSeriesSquareFifth,  to use a while loop (instead of for). • The function takes a single integer n as a parameter • The function prints a series between 1 and that parameter, and also prints its result • The result is calculated by summing the numbers between 1 and n (inclusive). If a number is divisible by 5, its square gets added to the result instead. • The function does not...
Use a recursive tree method to compute a tight asymptotic upper bound for recurrence function T(n)=...
Use a recursive tree method to compute a tight asymptotic upper bound for recurrence function T(n)= 3T(n/4)+n . then use substitution method to verify your answer.
(2nd Problem) From Chapter 15 on page 1080, do problem #5. Recursive function that computes the...
(2nd Problem) From Chapter 15 on page 1080, do problem #5. Recursive function that computes the same of values in an array. To test this function in the main, create the following array: int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; #15. Write a recursive function that finds and returns the sum of the elements of an int array. Also, write a program to test your function.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT