Using trapezoidal method to compute integral

This is a discussion on Using trapezoidal method to compute integral within the C Programming forums, part of the General Programming Boards category; The program will compute the integral of a function f. f(x)=exp(-x^2) The program runs but i am getting wrong values. ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    4

    Question Using trapezoidal method to compute integral

    The program will compute the integral of a function f.
    f(x)=exp(-x^2)

    The program runs but i am getting wrong values. I am guessing i made mistake somewhere in the formula.

    Answer should look like the following:

    Number of subintervals: 1000000Left endpoint: 0.0Right endpoint: 100.00, answer: 0.886227

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <conio.h>
    double f(double);
    
    
    int main()
    {
        double upperBound;
        double lowerBound;
        double n;
        double h;
        printf(" Enter upper and lower bound values \n");
        scanf(" %lf %lf", &upperBound, &lowerBound);
        printf(" Enter number of N values \n");
        scanf(" %lf", &n);
        //h = ((upperBound - lowerBound)/n);
        //double x=lowerBound;
        for (int i=0; i<n; i++)
        {
        //double x = lowerBound;
        double f(double x);
    
    
        //x = x + h;
        }
        printf(" The result is %lf\n", f);
        getch();
    }
    
    
    double f(double x)
    {
       return exp(-x*x);
    }
    Thanks For your help.
    I have also attached the file. I am using Dev c++ IDE.
    Attached Files Attached Files

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    This is not a function call. It's just a function declaration.
    Code:
    double f(double x);
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trapezoidal Rule for Integration
    By lolcats22 in forum C Programming
    Replies: 2
    Last Post: 11-20-2011, 01:09 AM
  2. The trapezoidal rule question
    By paranoidgnu in forum C Programming
    Replies: 9
    Last Post: 04-24-2011, 09:00 AM
  3. Finding the integral by the summation method
    By browser in forum C Programming
    Replies: 4
    Last Post: 12-01-2009, 01:33 PM
  4. composite trapezoidal rule
    By Sam Robinson in forum C Programming
    Replies: 0
    Last Post: 05-19-2003, 10:01 AM
  5. Arrays and the trapezoidal rule
    By ChemistryStar4 in forum C++ Programming
    Replies: 1
    Last Post: 04-05-2003, 08:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21