开发者

Guidance for Python logic programming

I am having difficulty figuring out how to go about coding a simple logic program to calculate pendulum movement. See this doc, I am stuck on task two.

What I have so far is:

Unfortunately I'm not sure how to go on since I have very limited experience with Python.


Since this is homework, I won't give you a complete answer - I'll just give some hints.

The question asks you to reduce the timestep. To do this change this line:

dt = 0.1 # Use a smaller value.

It then asks you to verify that the period and amplitude of the oscillation are correct. The simplest way to do this is to print the results out to the screen or a file and verify them manually. This requires little-to-no programming ability and can be done in just a few minutes.

Alternatively you can calculate the period and amplitude programatically by finding the local maximum of the angle. To do this search for every occurrence of three values such that the middle one is greater than the two on either side. I would suggest writing this is a separate function - possibly as a generator (using yield). The time between two local maximums is the period.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜