Project-1/src/plot_general_alg.py
2023-09-12 20:59:34 +02:00

32 lines
811 B
Python

import matplotlib.pyplot as plt
import numpy as np
analytical_func = lambda x: 1 - (1 - np.exp(-10))*x - np.exp(-10*x)
def main():
fig, ax = plt.subplots()
for i in range(6):
x = []
y = []
x.append(0.)
y.append(0.)
with open(f"output/general/out_{10**(i+1)}.txt", "r") as f:
lines = f.readlines()
for line in lines:
x_i, y_i = line.strip().split(",")
x.append(float(x_i))
y.append(float(y_i))
x.append(1.)
y.append(0.)
ax.plot(x, y, label=f"n$_{{steps}} = 10^{i+1}$")
x = np.linspace(0, 1, 1001)
ax.plot(x, analytical_func(x), label=f"u$_{{exact}}$")
ax.legend()
fig.savefig("../latex/images/problem7.pdf")
if __name__ == "__main__":
main()