我的代码K按预期运行并返回 的值,但w由于尺寸问题,图表未显示。我会很感激任何帮助。import numpy as npimport pylab as plk = np.linspace(0,0.1,1000)h = 50g = 9.81w = 0.5*(np.ones(len(k)))w = np.sqrt((g*k)*np.tanh(h*k))k = max(k[w<=0.5])print("The wave number, k = %.4f" % k)pl.figure()pl.plot(k, w)pl.show()但是,绘图会返回以下错误:x 和 y 必须具有相同的第一维,但具有形状 (1,) 和 (1000,)
1 回答
陪伴而非守候
TA贡献1757条经验 获得超8个赞
这将做:
import numpy as np
import pylab as pl
k = np.linspace(0,0.1,1000)
h = 50
g = 9.81
w = 0.5*(np.ones(len(k)))
w = np.sqrt((g*k)*np.tanh(h*k))
kmax = max(k[w<=0.5])
print("The wave number, k = %.4f" % kmax)
pl.figure()
pl.plot(k, w)
pl.show()
OP还在评论中提到他想在情节上标记点kmax。
这可以按如下方式完成:
import numpy as np
import pylab as pl
k = np.linspace(0,0.1,1000)
h = 50
g = 9.81
w = 0.5*(np.ones(len(k)))
w = np.sqrt((g*k)*np.tanh(h*k))
kmax = max(k[w<=0.5])
print("The wave number, k = %.4f" % kmax)
pl.figure()
pl.plot(k, w)
pl.plot(kmax,w[k==kmax],'.',color='r')
pl.show()
- 1 回答
- 0 关注
- 261 浏览
添加回答
举报
0/150
提交
取消