- #1

CMJ96

- 50

- 0

## Homework Statement

I'd like to solve the following integral using the 2D trapezoidal method in fortran 95

$$I=\int^{1.40406704}_{-1.40406704} \int^{x+1.40406704}_{x-1.40406704} exp(x+y) dy dx$$

## Homework Equations

$$I= \frac{h}{2} \left(f_0+ 2 \sum_{i=1}^{n-1} f_i +f_n \right)+O(h^2) $$

## The Attempt at a Solution

So I have wrote my program below, attempting to use a nested do loop to calculate the integral over the two dimensions. However I am not sure how to use the result of my do loop to arrive at a final answer, I'm also not sure if my loop is entirely correct, here is a copy of my script

program trap2d

implicit none

real :: hy, hx, c, d, integralx, integraly, func, I_numeric,x,y,integral

integer :: nx,ny,ix,iy

c=-(1.140406704)

d=(1.140406704)

ny=1000

nx=1000

hx=(d-c)/nx

integralx=0.0

do ix=1,nx-1

x=c+ix*hx

hy=((x+1.140406704)-(x-1.140406704))/ny

integraly=0.0

do iy=1,ny-1

y=x-1.140406704+iy*hy

integraly=integraly+hy*func(x,y)

end do

integralx=integralx+hx*integraly

end do

end program

function func(x,y)

implicit none

real :: func,x,y

func=exp(x+y)

end function func