Question

Must be written in basic C language. I keep getting stuck with my code.Step 1: You are to write an algorithm to compute e1 using the Taylor Series Expansion n! o Use the highest precision possible Step 2: Calculate the error between your algorithm and the value computed using the function exp(x) found in the <math.h> library. .Step 3: Calculate how many digits of precision is your algorithm.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the code for you:

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

long int fact(int n)
{
    if(n == 0)
        return 1;
    return n * fact(n-1);  
}
long double expCalc(int x)
{
    long double sum = 0, previousSum = 0;
    int i = 0;
    while(1)
    {
       sum += pow(x, i) /fact(i);
       if(sum < 0)
           return previousSum;
       //printf("%Lf\t%Lf\n", sum, previousSum);  
       previousSum = sum;
       i++;  
    }
}
int main()
{
    long double calculatedValue = expCalc(11);
    long double actualValue = exp(11);
    long double error = fabsl(calculatedValue - actualValue);
    printf("The calculated value is: %Lf\n", calculatedValue);
    printf("The actual value is: %Lf\n", actualValue);
    printf("The error in between is: %Lf\n", error);
}

And the output screenshot is:

Add a comment
Know the answer?
Add Answer to:
Must be written in basic C language. I keep getting stuck with my code. Step 1:...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • There are also approximations of higher order derivatives that can be computed using only values ...

    Number 9 requires number 8 so please can you answer both? Thanks. Here's more context: There are also approximations of higher order derivatives that can be computed using only values of the original function. Consider the approximation: u(a + 2h)-2u(a + h) + u (a) h2 8. Using your knowledge of Taylor series, what derivative is approximated by Equa Many different combinations of terms can be used to create approximations to deriva- tion??? What is the order of the approximation?...

  • * This is for CS 101 Java class. I can only use "while" loops. I cannot...

    * This is for CS 101 Java class. I can only use "while" loops. I cannot use "for", "do-while" or any other repetition method.* d. Create a new project Lab04d. In this part, you are going to compute arctan(x) in radians The following formula approximates the value of arctan(x) using Taylor series expansion: 2k +1 tan-1 (x) = > (-1)" 2k 1 k=0 Depending on the number of terms included in the summation the approximation becomes more accurate Your program...

  • This is an assignment for my algorithm class which I have written the code partially and...

    This is an assignment for my algorithm class which I have written the code partially and only need to complete it by adding a time function that calculates the average running time. We could use any programming language we want so I am using C++. I am including the instruction and my partial code below. Thank you! Implement linearSearch(a,key) and binarySearch( a,key)functions. Part A.In this part we will calculate theaverage-case running time of each function.1.Request the user to enter a...

  • Hello, I am having trouble with part c of this question. Here is my work so far: The solution for part c states that a...

    Hello, I am having trouble with part c of this question. Here is my work so far: The solution for part c states that a possible solution is (e^16 * 4^3) / 3! I am having trouble understanding how they got e^16 or why they decided to use e^(4^2) for M in the equation |f(x) - Tn(x)| <= (M / (n + 1)!) * |x - 0|^(n + 1). From my understanding, I have to maximize H^3(x) (i.e. 3rd derivative...

  • I just want to clarify what I need help on (as I do not need help...

    I just want to clarify what I need help on (as I do not need help on the full question). Specifically what I want is to be able to set the equations given to me so that I can solve for n using a root finding algorithm (which I already have). As I understand, I need something of the form | Tn(x) - e^x | = epsilon machine = (x^(n+1) / (n+1)!) and all I need from there is to...

  • Please use C programming to write the code to solve the following problem. Also, please use the i...

    Please use C programming to write the code to solve the following problem. Also, please use the instructions, functions, syntax and any other required part of the problem. Thanks in advance. Use these functions below especially: void inputStringFromUser(char *prompt, char *s, int arraySize); void songNameDuplicate(char *songName); void songNameFound(char *songName); void songNameNotFound(char *songName); void songNameDeleted(char *songName); void artistFound(char *artist); void artistNotFound(char *artist); void printMusicLibraryEmpty(void); void printMusicLibraryTitle(void); const int MAX_LENGTH = 1024; You will write a program that maintains information about your...

  • I keep getting an error code in my C++ program. It says "[Error] 'strlen' was not...

    I keep getting an error code in my C++ program. It says "[Error] 'strlen' was not declared in this scope" in my main.cpp. Here are my codes. main.cpp #include <iostream> #include <string> #include "functions.h" using namespace std; //definition of the main function. //takes arguments from the command-line. int main(int argc, char *argv[]) { //Determine if you have enough arguments. //If not, output a usage message and exit program if (argc<2 || (argc == 2 && argv[1][0] == '-')) { //call...

  • Please help me, my professor wants us to explain step by step each problem but I...

    Please help me, my professor wants us to explain step by step each problem but I cant! This is worth many points so please help me! Thank you! Writing Assignment 4 The following application and statements a., b., d., e., and f. can be found Sullivan's PreCalculus 9t www wennnnm edition pages 336-337. "A strain of E-coli SC18del-recA718 is placed into a nutrient broth at 30° Celsius and allowed to grow. The data given below are collected where x is...

  • Write the code in C language. Computer communication networks sometimes have noise on them, which can...

    Write the code in C language. Computer communication networks sometimes have noise on them, which can corrupt data being transmitted. It is the responsibility of the computers communicating to confirm data is transmitted accurately. One method to do this is to calculate a checksum of the data and transmit the checksum along with the data to ensure accuracy. In C, we can compute a checksum simply by summing the integer ASCII codes in the message and finding the remainder of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT