如何制作李沙育曲线的动画 [英] How to make an animation of a Lissajous curve
本文介绍了如何制作李沙育曲线的动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用参数化制作一个曲线动画(在其中递增绘制):x(t)= sin(3t)和y(y)= sin(4t),其中t [0,2pi]。
I want to make an animation of the curve (where you incrementally draw it) with parametrization: x(t) = sin(3t) and y(y) = sin(4t) where t[0, 2pi].
尝试:
%matplotlib notebook
import matplotlib.pyplot as plt
import math
import numpy as np
# set the minimum potential
rm = math.pow(2, 1 / 6)
t = np.linspace(-10, 10, 1000, endpoint = False)
x = []
y = []
for i in len(t): #TypeError 'int' object is not iterable
x_i = np.sin( 3 * t[i] )
y_i = np.sin( 4 * t[i] )
x.append(x_i)
y.append(y_i)
# plot the graph
plt.plot(x,y)
# set the title
plt.title('Plot sin(4t) Vs sin(3t)')
# set the labels of the graph
plt.xlabel('sin(3t)')
plt.ylabel('sin(4t)')
# display the graph
plt.show()
但是TypeError'int'对象不是可迭代的...我该如何解决?
But TypeError 'int' object is not iterable springs up... How can I fix it?
谢谢
推荐答案
您要遍历一个完整的整数er(len(t)中的 i
)
You're trying to iterate over an integer (i in len(t)
)
相反,您需要遍历数组:
Instead, you need to be iterating over the array:
for i in t:
x_i = np.sin( 3 * i )
y_i = np.sin( 4 * i )
x.append(x_i)
y.append(y_i)
这篇关于如何制作李沙育曲线的动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文