Post Reply 
Trapezoidal Rule or Simpsons Rule?
07-07-2015, 10:15 PM (This post was last modified: 07-08-2015 10:48 AM by DrD.)
Post: #5
RE: Trapezoidal Rule or Simpsons Rule?
Well done! There's lots of good info in your approach, and I appreciate your contribution.

-Dale-

I was puttering around also, and made a request (to Tim) to enhance calling parameters to allow specifying the TYPE of input like this:

Export Trap(f[8],a[0],b[0]n[0]), etc. We'll see if that ever see's the light of day!

This way the direct entry of a function (TYPE [8]) would be possible. To keep things non-CAS this approach also works:

Code:

//  Composite Trapezoidal Rule
//  Inputs:  f=function to solve, USE ""!
//           a:=start of interval
//           b:=end of interval
//           n:= nbr of steps in interval
//
//  Returns: Trapezoidal function value in R

EXPORT trap(f,a,b,n)
BEGIN
  local h,x;
  F1:=f;
  h:=(b-a)/n;  
  x:=MAKELIST(X,X,a,b,1/n);
  R:=(h/2) * ( 2*sum(F1(x)) - F1(x(2)) - F1(x(n+1)) ) ;
 return R;
END;
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Trapezoidal Rule or Simpsons Rule? - DrD - 07-05-2015, 10:49 PM
RE: Trapezoidal Rule or Simpsons Rule? - DrD - 07-07-2015 10:15 PM



User(s) browsing this thread: 1 Guest(s)