diff --git a/numerical_analysis/5/README.md b/numerical_analysis/5/README.md index e69de29..b00aecd 100644 --- a/numerical_analysis/5/README.md +++ b/numerical_analysis/5/README.md @@ -0,0 +1,5 @@ +![image-20210117042146956](https://public.veypi.com/img/screenshot/20210117042146.png) + +![image-20210117043700038](https://public.veypi.com/img/screenshot/20210117043700.png) + +![image-20210117043750115](https://public.veypi.com/img/screenshot/20210117043750.png) diff --git a/numerical_analysis/5/main.py b/numerical_analysis/5/main.py new file mode 100644 index 0000000..2540113 --- /dev/null +++ b/numerical_analysis/5/main.py @@ -0,0 +1,60 @@ +import math +import matplotlib.pyplot as plt +import numpy as np +from matplotlib.ticker import LinearLocator + + +def f1(x): + return 2 * math.sin(x) - x ** 2 / 10 + + +def showf1(): + t = np.linspace(0, 4, 1000) + plt.plot(t, [f1(x) for x in t]) + plt.show() + + +def f2(x, y): + return (1 - x) ** 2 + 100 * (y - x ** 2) ** 2 + + +def f3(x, y): + return (1.5 - x + x * y) ** 2 + (2.25 - x + x * y ** 2) ** 2 + (2.625 - x + x * y ** 3) ** 2 + + +def showf2(): + fig = plt.figure(figsize=plt.figaspect(1.)) + ax = fig.add_subplot(1, 1, 1, projection='3d') + X = np.arange(-1, 1, 0.05) + Y = np.arange(-1, 1, 0.05) + X, Y = np.meshgrid(X, Y) + # R = np.sqrt(X ** 2 + Y ** 2) + Z = f2(X, Y) + # Z = np.sin(R) + + surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, + cmap=plt.cm.YlGnBu_r, + linewidth=0, antialiased=False) + fig.colorbar(surf, shrink=0.5, aspect=5) + plt.show() + + +def showf3(): + fig = plt.figure(figsize=plt.figaspect(1.)) + ax = fig.add_subplot(1, 1, 1, projection='3d') + X = np.arange(-5, 5, 0.25) + Y = np.arange(-5, 5, 0.25) + X, Y = np.meshgrid(X, Y) + # R = np.sqrt(X ** 2 + Y ** 2) + Z = f3(X, Y) + # Z = np.sin(R) + + surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, + cmap=plt.cm.YlGnBu_r, + linewidth=0, antialiased=False) + fig.colorbar(surf, shrink=0.5, aspect=5) + plt.show() + + +if __name__ == '__main__': + showf3()