Move task 5 to group project

This commit is contained in:
Manuel Thalmann 2023-03-29 13:46:26 +02:00
parent 90de2d1686
commit cd0fc87561
4 changed files with 1 additions and 95 deletions

View file

@ -1,65 +0,0 @@
#%%
from numpy import array, empty, linalg, zeros
from matplotlib import pyplot
from scipy import interpolate
def Miguel_S5_Aufg2(x, y, xx):
n = len(x)
a = empty((n - 1, 1))
b = empty((n - 1, 1))
c = empty((n, 1))
d = empty((n - 1, 1))
h = empty((n - 1, 1))
for i in range(0, n - 1):
a[i] = y[i]
h[i] = x[i + 1] - x[i]
c[0] = 0
c[n - 1] = 0
A = zeros((n - 2, n - 2))
z = empty((n - 2, 1))
for i in range(0, n - 2):
if i == 0:
A[i][0] = 2 * (h[0] + h[1])
A[i][1] = h[1]
z[i] = 3 * (((y[2] - y[1]) / h[1]) - ((y[1] - y[0]) / h[0]))
else:
A[i][i - 1] = h[i]
A[i][i] = 2 * (h[i] + h[i + 1])
z[i] = 3 * (((y[i + 2] - y[i + 1]) / h[i + 1]) - ((y[i + 1] - y[i]) / h[i]))
if i < n - 3:
A[i][i + 1] = h[i + 1]
c[1:n - 1,:] = linalg.solve(A, z)
for i in range(0, n - 1):
b[i] = ((y[i + 1] - y[i]) / h[i]) - ((h[i] / 3) * (c[i + 1] + 2 * c[i]))
d[i] = (1 / (3 * h[i])) * (c[i + 1] - c[i])
yy = empty(len(xx))
for i in range(0, len(yy)):
j = 0
value = xx[i]
while x[j] < value:
j += 1
yy[i] = y[j - 1] + b[j - 1] * (value - x[j - 1]) + c[j - 1] * (value - x[j - 1]) ** 2 + d[j - 1] * (value - x[j - 1]) ** 3
pyplot.scatter(xx, yy)
return yy
# %%
x = array([4, 6, 8, 10])
y = array([6, 3, 9, 0])
xx = array([4.5, 6.5, 9.0])
Miguel_S5_Aufg2(x, y, xx)
# %%

View file

@ -1,29 +0,0 @@
# %%
from Miguel_S5_Aufg2 import Miguel_S5_Aufg2
from matplotlib import pyplot
from numpy import array, polyfit, polyval
from scipy import interpolate
x = array([1900, 1910, 1920, 1930, 1940, 1950, 1960, 1970, 1980, 1990, 2000, 2010])
y = array([75.995, 91.972, 105.711, 123.203, 131.669, 150.697, 179.323, 203.212, 226.505, 249.633, 281.422, 308.745])
xx = array([1917, 1925, 1941, 1956, 1972, 1998, 2000, 2008])
# a)
pyplot.figure()
Miguel_S5_Aufg2(x, y, xx)
# b)
pyplot.figure()
pyplot.scatter(xx, interpolate.CubicSpline(x, y)(xx))
# c) 1
pyplot.figure()
pyplot.scatter(xx, polyval(polyfit(x, y, deg = 11), xx))
# c) 2
pyplot.figure()
pyplot.scatter(xx - 1900, polyval(polyfit(x - 1900, y, deg = 11), xx - 1900))
# %%

@ -1 +1 @@
Subproject commit 842806023e486ee60013a719d0ab7961b4b07524
Subproject commit 77da7869c5537751290e177e86c55becc22b7c6b