Rope Equation Solver

x=\delta Is the equation for my rope equation solver???

Hey guys,

Quick question- Could anyone recommend some useful libraries for implementing the wave equation solver in python? Especially for manipulating equations and animating graphs?

I can implement the solver in Mathematica, but I am still relatively new at python and would appreciate any pointers at where to start,


1 Like

If you want to have some user-directed manipulation, you can look at the widgets functionality in jupyter/ipython:

Is that the kind of tool you were looking for? If you just want to animate some figures you can use matplotlib’s built-in animation functionality:

Click around on that site for some other examples, too, they’ve got some nice ones! (@pablo you might like this: The Bayes update — Matplotlib 3.7.1 documentation , at some point we’ll do something similar for BMEX)

1 Like

I’ve had pretty good success in the past with matplotlibs animation and normal pyplot libraries before.
Here is a small plotting script I used to plot an N-Body simulation before in 3D. It can be a little finicky depending on your device in my experience (for some reason it only wanted to make gifs even when I tried to have something else). There are certainly more interactive ways to do it as mentioned with Jupyter lab widgets, but there’s just something wrong with my installation of Jupyter to where the IPython dependency just doesn’t want to work…

#now do the 3D video plot
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

def updatePlot(frame):
    #If you want to follow sets of particles and update the scales, comment out the set_lim lines
    ax.set_xlabel('x (km)')
    ax.set_ylabel('y (km)')
    ax.set_zlabel('z (km)')
    ax.set_title(f'N-Body Simulation (N={len(mArr)})')
    # Plot the positions of each body at the current frame
    for i in range(nBodies): #this shows the particles
        ax.scatter(x[i, frame]/kmCon, y[i, frame]/kmCon, z[i, frame]/kmCon, marker='o')

    for i in range(nBodies): #this plots the line
        ax.plot(x[i, :frame+1]/kmCon, y[i, :frame+1]/kmCon, z[i, :frame+1]/kmCon)

    return ax

ani = FuncAnimation(fig, updatePlot, frames=np.size(tVals)+1, interval=10)'nbody20.gif') #writer='Pillow') here


1 Like

Hey @hmatt!

You can take a look here:

It is not the best commented code, but in the function “Movie_Maker” I lay out how to make movies:

If you download the notebook, run it locally, and uncomment the command below you should be able to make an animation and the adapt to your own rope problem.

Hope this helps!


1 Like

Awesome! I’ll take a look, thanks!


Got it! Thanks for everyone’s help!

1 Like

Very nice! Did you end up using the widgets?

AWESOME!!! Love this very nice rope :sparkling_heart:. What happens if you include more terms in the expansion (more normal modes)?

Excellent work Holly!


So I was rewriting my rope solver to be a little more general by just integrating by hand to find things like the ai’s and normalization constant, and I seem to be a little confused. When we were originally deriving the rope equation, we had a B with a tilda in the expression. Is this supposed to be our normalization constant? When we do <\phi_i | \phi_i>=1 are we finding what value B would have to be to make that true? In that case are we then just multiplying each ai (in effect the entire \phi(x, t) expression) by that value? I ask mainly because it seems the strangest thing about my solution is that the scale is completely off in weird ways right now

Never mind, I think I figured it out, or at the very least I have something!




Sorry for not answering before to your previous post, we are running with the final details for the summer school. We can chat tomorrow if something is still confusing about it, but it seems your rope is moving in a very healthy way, super congrats!! :partying_face: :partying_face: :partying_face: :partying_face:


Finally had some time to work on the problem and thankfully my python skills are still functioning properly. (I didn’t normalize the function since the movement of the rope is the same either way.)