*/
Stuck? Need help? Ask questions on our forums.
*/

View \xinum.h

Calculus (Derivative:Tangent). v04

Submitted By: xhunga
Rating: (Not rated) (Rate It)


/* f.h                    freeware                          [[Email Removed]] */


/* ------------------------------------- FUNCTION --------------------------  */
/* Do    :                                                                    */
/*                                                                            */
/* -------------------------------------------------------------------------- */
double trapezoid(
double (*P_f)(double x),
double a,
double b,
   int n
)
{
   int i = 0;
double m = 0.;
double M = 0.;

 for(i = 0; i <= n; i++)
 {
    if(i ==0 || i== n){m = 1.;}
  else                {m = 2.;}

  M += m * (*P_f)(a + i*(b-a)/n);
 }

  return( ((b -a)*M) / (2*n) );
}


/* ------------------------------------- FUNCTION --------------------------  */
/* Do    :                                                                    */
/*                                                                            */
/* -------------------------------------------------------------------------- */
double simpson(
double (*P_f)(double x),
double a,
double b,
   int n
)
{
   int i = 0;
double m = 0.;
double M = 0.;

 for(i = 0; i <= n; i++)
 {
       if(i ==0 || i== n){m = 1.;}
  else if(fmod(i,2) == 0){m = 2.;}
  else                   {m = 4.;}

  M += m * (*P_f)(a + i*(b-a)/n);
 }

  return( ((b -a)*M) / (3*n) );
}

corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.