added old projects

This commit is contained in:
Austin Bennett
2026-02-03 08:18:39 -06:00
parent 43acf989bf
commit 2451448b8a
623 changed files with 28117 additions and 0 deletions
@@ -0,0 +1,13 @@
from tabulate import tabulate
from trap import trap as t
from midpoint import midpoint as m
from simpson import simpson as s
l = [[10, t(0, 4, 10), m(0, 4, 10), s(0, 4, 10)],
[20, t(0, 4, 20), m(0, 4, 20), s(0, 4, 20)],
[40, t(0, 4, 40), m(0, 4, 40), s(0, 4, 40)],
[80, t(0, 4, 80), m(0, 4, 80), s(0, 4, 80)],
[100, t(0, 4, 100), m(0, 4, 100), s(0, 4, 100)],
]
print(tabulate(l, headers=['n', 'trapezoidal', 'midpoint', 'simpsons'], tablefmt='orgtbl'))
@@ -0,0 +1,20 @@
#midpoint.py
from numpy import sin
def function(x):
return sin(x*x)
def midpoint(a, b, n):
deltaX = (b - a) / n
deltaXValues = []
integral = 0
for i in range (n+1):
xSubscriptI = round((a + i * deltaX),5)
deltaXValues.append(xSubscriptI)
for i in range (n):
input = (deltaXValues[i] + deltaXValues[i + 1]) / 2
integral += function(input)
return integral * deltaX
@@ -0,0 +1,29 @@
#simpson.py
from numpy import sin
def function(x):
return sin(x*x)
def multiple(m, n):
return True if m % n == 0 else False
def simpson(a, b, n):
deltaX = (b - a) / n
deltaXValues = []
integral = 0
for i in range (n+1):
xSubscriptI = round((a + i * deltaX),5)
deltaXValues.append(xSubscriptI)
i = 0
for i in range (n+1):
if i == 0 or i == n:
integral += function(deltaXValues[i])
elif multiple(i, 2) == True:
integral = integral + (2 * function(deltaXValues[i]))
else:
integral = integral + (4 * function(deltaXValues[i]))
integral = (deltaX/3) * integral
return integral
@@ -0,0 +1,23 @@
#trap.py
from numpy import sin
def function(x):
return sin(x*x)
def trap(a, b, n):
deltaX = (b -a) / n
deltaXValues = []
integral = 0
for i in range (n+1):
xSubscriptI = round((a + i * deltaX),5)
deltaXValues.append(xSubscriptI)
for i in range(n+1):
if i == 0 or i == n:
integral += function(deltaXValues[i])
else:
integral += 2 * function(deltaXValues[i])
integral = round((deltaX/2) * integral, 7)
return integral