Skip to content

Instantly share code, notes, and snippets.

@AiHiro
Last active January 8, 2016 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AiHiro/0603bed1abd04abc01cc to your computer and use it in GitHub Desktop.
Save AiHiro/0603bed1abd04abc01cc to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 4 17:24:23 2016
@author:Aihiro
"""
import numpy as np
def f(x,y):
return 2*x+2*y
aStop = 2
aStart = 0
bStop = 2
bStart = 0
n = 10000
m = 10000
dx = (aStop-aStart)/(2*n)
dy = (bStop-bStart)/(2*m)
s = 0
Narray = np.linspace(0,n,n+1)
Marray = (np.linspace(0,m,n+1))[:,np.newaxis]
x = aStart + 2*Narray*dx
x1 = x + dx
x2 = x + 2*dx
y = bStart + 2*Marray * dy
y1 = y + dy
y2 = y + 2*dy
s1 = ( ( f(x, y) + 4*f(x, y1) + f(x, y2) )/3 )*dy
s2 = ( ( f(x1, y) + 4*f(x1, y1) + f(x1, y2) )/3 )*dy
s3 = ( ( f(x2, y) + 4*f(x2, y1) + f(x2, y2) )/3 )*dy
sy1 = np.sum(s1,axis=0)
sy2 = np.sum(s2,axis=0)
sy3 = np.sum(s3,axis=0)
sx = ( (sy1 + 4*sy2 + sy3)/3 )*dx
s = np.sum(sx)
res = s
print (res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment