Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 41
# def subdiv(i1,i2,n): return [i1+i*(i2-i1)/n for i in range(n+1)] print subdiv(0,10,10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
def masomme(Lcoord,Iinit,Ifin): Fs=0 lenLcoord = len(Lcoord) if Iinit < 0 : return Fs if Ifin > lenLcoord : Ifin = lenLcoord for Ii in range(Iinit,Ifin): Fs = Fs + Lcoord[Ii][1] return Fs L=[(-1, 1), (0, 2), (1, 3), (2, 4)] print(masomme(L,0,4))
10
def mamethodesimpson(f,xa,xb,n): Fs=0 Lcoord = subdiv(xa,xb,n) Iinit=0 Ifin = n Fs = Fs + f(Lcoord[Iinit]) Fs = Fs + f(Lcoord[Ifin]) for Ii in range(Iinit+1,Ifin): Fs = Fs + 4* f((Lcoord[Ii-1]+Lcoord[Ii])/2) for Ii in range(Iinit+1,Ifin-1): Fs = Fs + 2* f(Lcoord[Ii]) return Fs*(xb-xa)/(6*n) L=[(0,1),(1,0),(2,0),(3,0)] def g(x): return 1 print(mamethodesimpson(g,0.,3.,3)