Thread: Simpson's rule and Trapezoidal rule from fixed array

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    1

    Simpson's rule and Trapezoidal rule from fixed array

    Hi!
    I am trying to write a program that uses Simpson's rule and Trapezoidal rule from a fixed array. But I am having trouble integrating the array into the rules.

    Here is the code
    Code:
     #include <stdio.h>
    #include <stdlib.h>
    #include <strings.h>
    #include <math.h>
    //Function prototypes
    double f_value (double x);
    
    int main (void){
    
            int k;
            double f[21], xx[21], del_x, x, s_value, t_value;
            del_x=0.05;
            for (k=0, x=0.; k<=20; k++){
                    xx[k]=x;
                    f[k]=f_value(x);
                    x+= del_x;
            }
            printf ("    x         f(x)\n");
            for(k=0; k<21; k++) printf ("%8.2f %15.4e\n", xx[k], f[k]);
            /*trapezoidal rule*/
            t_value=
            /*Simpson's rule*/
            s_value=
            return;
            }
    
            double f_value (double x)
            {
            double fx;
            fx=sin(x)* exp(-0.5 *x*x);
            return fx;
            }
    thank you!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. composite trapezoidal rule
    By Sam Robinson in forum C Programming
    Replies: 0
    Last Post: 05-19-2003, 10:01 AM
  2. Arrays and the trapezoidal rule
    By ChemistryStar4 in forum C++ Programming
    Replies: 1
    Last Post: 04-05-2003, 09:16 PM