feat: task2.py compleated
This commit is contained in:
parent
4302e8e136
commit
47202ce7f0
@ -1,5 +1,9 @@
|
||||
#%%
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# Parameter
|
||||
N = 640
|
||||
|
||||
# Funktionen
|
||||
f_a = lambda x: np.sin(x)
|
||||
@ -10,11 +14,76 @@ f_e = lambda x: np.log2(x)
|
||||
f_f = lambda x: np.log(10)/np.log(x)
|
||||
|
||||
# Daten
|
||||
a_data = [f_a(x) for x in np.linspace(0, np.pi, 201)]
|
||||
b_data = [f_b(x) for x in np.linspace(2, 5, 20)]
|
||||
c_data = [f_c(x) for x in np.linspace(-2, 0, 20)]
|
||||
d_data = [f_d(x) for x in np.linspace(2, 100, 201)]
|
||||
e_data = [f_e(x) for x in np.linspace(1e-2, 1, 20)]
|
||||
f_data = [f_f(x) for x in np.linspace(2, 3, 20)]
|
||||
x_a_data = np.linspace(0, np.pi, N)
|
||||
x_b_data = np.linspace(2, 5, N)
|
||||
x_c_data = np.linspace(-2, 0, N)
|
||||
x_d_data = np.linspace(2, 100, N)
|
||||
x_e_data = np.linspace(1e-2, 1, N)
|
||||
x_f_data = np.linspace(2, 3, N)
|
||||
|
||||
print(b_data)
|
||||
f_a_data = f_a(x_a_data)
|
||||
f_b_data = f_b(x_b_data)
|
||||
f_c_data = f_c(x_c_data)
|
||||
f_d_data = f_d(x_d_data)
|
||||
f_e_data = f_e(x_e_data)
|
||||
f_f_data = f_f(x_f_data)
|
||||
|
||||
I_a = np.abs(np.trapezoid(f_a_data, x_a_data))
|
||||
I_b = np.abs(np.trapezoid(f_b_data, x_b_data))
|
||||
I_c = np.abs(np.trapezoid(f_c_data, x_c_data))
|
||||
I_d = np.abs(np.trapezoid(f_d_data, x_d_data))
|
||||
I_e = np.abs(np.trapezoid(f_e_data, x_e_data))
|
||||
I_f = np.abs(np.trapezoid(f_f_data, x_f_data))
|
||||
|
||||
print(f"Integral a: {I_a:.3}")
|
||||
print(f"Integral b: {I_b:.3}")
|
||||
print(f"Integral c: {I_c:.3}")
|
||||
print(f"Integral d: {I_d:.3}")
|
||||
print(f"Integral e: {I_e:.3}")
|
||||
print(f"Integral f: {I_f:.3}")
|
||||
|
||||
# Plot a
|
||||
plt.figure(1)
|
||||
plt.plot(x_a_data, f_a_data)
|
||||
plt.xlabel('x'); plt.ylabel('y')
|
||||
plt.grid('on'); plt.axis('image')
|
||||
|
||||
# Plot b
|
||||
plt.figure(2)
|
||||
plt.plot(x_b_data, f_b_data)
|
||||
plt.xlabel('x')
|
||||
plt.ylabel('y')
|
||||
plt.grid('on')
|
||||
plt.axis('image')
|
||||
|
||||
# Plot c
|
||||
plt.figure(3)
|
||||
plt.plot(x_c_data, f_c_data)
|
||||
plt.xlabel('x')
|
||||
plt.ylabel('y')
|
||||
plt.grid('on')
|
||||
plt.axis('image')
|
||||
|
||||
# Plot d
|
||||
plt.figure(4)
|
||||
plt.plot(x_d_data, f_d_data)
|
||||
plt.xlabel('x')
|
||||
plt.ylabel('y')
|
||||
plt.grid('on')
|
||||
plt.axis('image')
|
||||
|
||||
# Plot e
|
||||
plt.figure(5)
|
||||
plt.plot(x_e_data, f_e_data)
|
||||
plt.xlabel('x')
|
||||
plt.ylabel('y')
|
||||
plt.grid('on')
|
||||
plt.axis('image')
|
||||
|
||||
# Plot f
|
||||
plt.figure(6)
|
||||
plt.plot(x_f_data, f_f_data)
|
||||
plt.xlabel('x')
|
||||
plt.ylabel('y')
|
||||
plt.grid('on')
|
||||
plt.axis('image')
|
||||
Loading…
x
Reference in New Issue
Block a user