Takuya Miyashita
This site
Web
Start:
*Python演習問題:最大値・最小値の検出 [#if086f7f]
***前提条件 [#fa1ccd8d]
-その1:import~
import とエイリアスの設定は以下の通り.
#codeprettify(lang-python){{
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
}}
-その2:peaks(MATLAB)~
MATLAB の [[peaks>https://jp.mathworks.com/help/matlab/re...
#codeprettify(lang-python){{
def peaks(N=49):
x = np.linspace(-3., 3., N)
y = np.linspace(-3., 3., N)
X, Y = np.meshgrid(x, y)
Z = 3.*(1.-X)**2.*np.exp(-(X**2.)-(Y+1.)**2.) \
-10.*(X/5.-X**3.-Y**5.)*np.exp(-X**2.-Y**2.) \
-1./3.*np.exp(-(X+1.)**2.-Y**2.)
return X, Y, Z
}}
***問題 [#t29756f3]
+上記の peaks を用い,2次元行列データ Z を作成しなさい.
#codeprettify(lang-python){{
X, Y, Z = peaks(XX)
}}
+Z の最大値と最小値,及びそれらのインデックス(行番号,列...
-最大値・最小値,インデックス
#codeprettify(lang-python){{
np.max, np.min
np.argmin, np.argmax
}}
-2次元の図~
自分の使いやすい方法で書く.
#codeprettify(lang-python){{
# オブジェクト指向に沿った書き方
fig = plt.figure() # Figureインスタンス生成
ax = fig.add_subplot(111) # Axesインスタンス生成
ax.contour(X,Y,Z)
ax.plot(x,y,z)
# MATLABに類似した書き方
plt.contour(X,Y,Z)
plt.plot(x,y,z)
}}
-3次元の図~
#codeprettify(lang-python){{
fig = plt.figure()
ax = fig.add_subplot(111,projection='3d') # または
ax = Axes3D(fig)
ax.plot_surface(X,Y,Z)
ax.plot(x,y,z)
}}
***解答例(参考) [#u2b64008]
メッシュサイズを 25×25 として解答例の図を作成してみた.~
MATLAB と似たような見かけにしている.~
&ref(https://main-t-miyashita.ssl-lolipop.jp/hydrocoast/i...
&ref(https://main-t-miyashita.ssl-lolipop.jp/hydrocoast/i...
End:
*Python演習問題:最大値・最小値の検出 [#if086f7f]
***前提条件 [#fa1ccd8d]
-その1:import~
import とエイリアスの設定は以下の通り.
#codeprettify(lang-python){{
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
}}
-その2:peaks(MATLAB)~
MATLAB の [[peaks>https://jp.mathworks.com/help/matlab/re...
#codeprettify(lang-python){{
def peaks(N=49):
x = np.linspace(-3., 3., N)
y = np.linspace(-3., 3., N)
X, Y = np.meshgrid(x, y)
Z = 3.*(1.-X)**2.*np.exp(-(X**2.)-(Y+1.)**2.) \
-10.*(X/5.-X**3.-Y**5.)*np.exp(-X**2.-Y**2.) \
-1./3.*np.exp(-(X+1.)**2.-Y**2.)
return X, Y, Z
}}
***問題 [#t29756f3]
+上記の peaks を用い,2次元行列データ Z を作成しなさい.
#codeprettify(lang-python){{
X, Y, Z = peaks(XX)
}}
+Z の最大値と最小値,及びそれらのインデックス(行番号,列...
-最大値・最小値,インデックス
#codeprettify(lang-python){{
np.max, np.min
np.argmin, np.argmax
}}
-2次元の図~
自分の使いやすい方法で書く.
#codeprettify(lang-python){{
# オブジェクト指向に沿った書き方
fig = plt.figure() # Figureインスタンス生成
ax = fig.add_subplot(111) # Axesインスタンス生成
ax.contour(X,Y,Z)
ax.plot(x,y,z)
# MATLABに類似した書き方
plt.contour(X,Y,Z)
plt.plot(x,y,z)
}}
-3次元の図~
#codeprettify(lang-python){{
fig = plt.figure()
ax = fig.add_subplot(111,projection='3d') # または
ax = Axes3D(fig)
ax.plot_surface(X,Y,Z)
ax.plot(x,y,z)
}}
***解答例(参考) [#u2b64008]
メッシュサイズを 25×25 として解答例の図を作成してみた.~
MATLAB と似たような見かけにしている.~
&ref(https://main-t-miyashita.ssl-lolipop.jp/hydrocoast/i...
&ref(https://main-t-miyashita.ssl-lolipop.jp/hydrocoast/i...
Page:
Edit with a page name which already exists