#160 Max and min using argmax and argmax in python
import numpy as np
import matplotlib.pyplot as plt
import os
os.chdir(r'D:\projects\wordpress\ex160')
os.getcwd()
def main():
N = 100
L = 1
def f(i, n):
x = i * L / N
lam = 2 * L / (n+1)
return x * (L-x) * np.sin(2*np.pi*x/lam)
a = np.fromfunction(f, (N+1, 5))
min_i = a.argmin(axis=0)
max_i = a.argmax(axis=0)
plt.plot(a, c='k')
plt.plot(min_i, a[min_i, np.arange(5)], 'v', c='b', markersize=8)
plt.plot(max_i, a[max_i, np.arange(5)], '^', c='r', markersize=8)
plt.xlabel(r'$x$')
plt.ylabel(r'$f_n(x)$')
plt.savefig("example160.png", dpi=100)
plt.show()
if __name__ == '__main__':
main()
Last Updated on 2021-02-14 by gantovnik

Recent Comments