Advertisement

Approximating 2nd definate integral of a function

Started by April 12, 2003 04:03 AM
2 comments, last by haro 21 years, 10 months ago
Anybody know of a reasonable way to approximate the definate 2nd integral of a function f(x,y), within a program? Seems like it might be fun to create a random function, create an object representing the function within certain bounds (how I would pick them is still a question), apply a density and then create some effects with colliding the objects off other objects with effects based off of their mass.... This is just solely for fun, and I''m extremely curious if this is reasonably possible. Anyhow, any feedback would be much appreciated.
I guess you meant the Int(Int(f(x,y),y,a,b),x,a1,b1).
You can just use Simpson''s method (or Gauss quadrature or so on). All you have to do is to integrate the values of inner integrals. For each inner integral take the constant value for x and than integrate for y. Imagine it like you have Int(f(x),x,a,b) where f(x)=Int(f(y),y,a,b). That''s all.

--------
Dave
--------Dave[ Math Studio ] A Computer Algebra System
Advertisement
Thanks for the reply. I wasn''t clear. I know how to integrate by hand, but what I meant was integration within a program I am writing. I suppose I am looking for a recommendation on a mathlib...

Thanks alot.
For every 1D approximation rule, you can generate a 2D rule.

The trapezoidal rule for 1D is:
Int(f(x),x,x0,x1) ~= 1/2 * f(x0) + 1/2 * f(x1)

For 2D it''s:
Int(f(x,y),(x,y),(x0,y0),(x1,y1) ~= 1/4 * f(x0,y0) + 1/4 * f(x0,y1) + 1/4 * f(x1,y0) + 1/4 * f(x1,y1)


Simpson''s rule for 1D goes like this:
Int(f(x),x,x0,x1) ~= 1/6 * f(x0) + 4/6 * f((x0+x1)/2) + 1/6 * f(x1)

The coefficients are (1/6, 4/6, 1/6)

In 2D, the following works:
(1/36, 4/36, 1/36)
(4/36,16/36, 4/36)
(1/36, 4/36, 1/36)

Int(f(x,y),(x,y),(x0,y0),(x1,y1) ~= 1/36 * f(x0,y0) + 4/36 * f(x0,(y0+y1)/2) + ...


I''m sorry if the explanation is not great.


This topic is closed to new replies.

Advertisement