@anonymous/

OrneryDismalMeasurements

Python 2.7

No description

fork
loading
Files
  • main.py

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.0015905248300778219","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"IyBweXRob24zCmltcG9ydCBudW1weSBhcyBucAoKZGVmIHRyYXBleihmLCBhLCBiICwgayApOgogIGg9MS4wLyBrCiAgaWk9cmFuZ2UoMSxrKQogIHJldHVybiAoaC8yLjApKihmKGEpK2YoYikrMipzdW0oW2YoYStpKmgpIGZvciBpIGluIGlpXSkpCiAgCgpkZWYgbWl0dGVscHVua3QoZiwgYSwgYiAsIGsgKToKICBoPTEuMC8gawogIGlpPXJhbmdlKDEsaysxKQogIHJldHVybiBoKihzdW0oW2YoYSsoaS0wLjUpKmgpIGZvciBpIGluIGlpXSkpCiAgCgpkZWYgc2ltcHNvbihmLCBhLCBiICwgayApOgogIGg9MS4wLyBrCiAgaWkxPXJhbmdlKDEsaykKICBpaTI9cmFuZ2UoMSxrKzEpCiAgcmV0dXJuIGgvNi4wKihmKGEpK2YoYikrMipzdW0oW2YoYStpKmgpIGZvciBpIGluIGlpMV0pKzQqc3VtKFtmKGErKGktMC41KSpoKSBmb3IgaSBpbiBpaTJdKSkKICAKCmRlZiByb21iZXJnKGYsYSxiLGspOgogIGRlZiBUKGYsYSxiLGwsayk6CiAgICBpZihsPT0wKToKICAgICAgcmV0dXJuIHRyYXBleihmLGEsYiwyKiprKQogICAgcmV0dXJuIDEuMC8oNCoqbC0xKSooNCoqbCpUKGYsYSxiLGwtMSxrKzEpLVQoZixhLGIsbC0xLGspKQogIHJldHVybiBUKGYsYSxiLGssMCkKICAKCmRlZiBmdW4oeCk6CiAgcmV0dXJuIDEuMC8oMSt4KioyKQogIAogIApwcmludCgiXG4gZj0xLzEreF4yLCBhPTAsIGI9MSwgaz0xIikKcHJpbnQgKCJnZW5hdWUgTMO2c3VuZzogJTIuMTJmIiAlIG5wLmFyY3RhbigxKSkKc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
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# python3
import numpy as np

def trapez(f, a, b , k ):
  h=1.0/ k
  ii=range(1,k)
  return (h/2.0)*(f(a)+f(b)+2*sum([f(a+i*h) for i in ii]))
  

def mittelpunkt(f, a, b , k ):
  h=1.0/ k
  ii=range(1,k+1)
  return h*(sum([f(a+(i-0.5)*h) for i in ii]))
  

def simpson(f, a, b , k ):
  h=1.0/ k
  ii1=range(1,k)
  ii2=range(1,k+1)
  return h/6.0*(f(a)+f(b)+2*sum([f(a+i*h) for i in ii1])+4*sum([f(a+(i-0.5)*h) for i in ii2]))
  

def romberg(f,a,b,k):
  def T(f,a,b,l,k):
    if(l==0):
      return trapez(f,a,b,2**k)
    return 1.0/(4**l-1)*(4**l*T(f,a,b,l-1,k+1)-T(f,a,b,l-1,k))
  return T(f,a,b,k,0)
  

def fun(x):
  return 1.0/(1+x**2)
  
  
print("\n f=1/1+x^2, a=0, b=1, k=1")
print ("genaue Lösung: %2.12f" % np.arctan(1))
print ("Trapezregel : %2.12f" % trapez(fun, 0, 1, 1))
print ("Mittelpunktregel: %2.12f" % mittelpunkt(fun, 0, 1, 1))
print ("Simpsonregel %2.12f" % simpson(fun, 0, 1, 1)) 
  
print("\n f=1/1+x^2, a=0, b=1, k=2")
print ("genaue Lösung: %2.12f" % np.arctan(1))
print ("Trapezregel : %2.12f" % trapez(fun, 0, 1, 2))
print ("Mittelpunktregel: %2.12f" % mittelpunkt(fun, 0, 1, 2))
print ("Simpsonregel %2.12f" % simpson(fun, 0, 1, 2))

print("\n f=1/1+x^2, a=0, b=1, k=4")
print ("genaue Lösung: %2.12f" % np.arctan(1))
print ("Trapezregel : %2.12f" % trapez(fun, 0, 1, 4))
print ("Mittelpunktregel: %2.12f" % mittelpunkt(fun, 0, 1, 4))
print ("Simpsonregel %2.12f" % simpson(fun, 0, 1, 4))

print("Rombergverfahren %2.12f" % romberg(fun, 0, 1, 4))