Member-only story

Modeling a Wave on a String With the Finite Difference Method in Python

Rhett Allain
11 min readMar 16, 2022

--

Photo: Rhett Allain. A plucked guitar string is a perfect example of a wave on a string.

There’s a very good chance that you have at least plucked a guitar string. When you do that, you deform the string under tension with some initial state. After that, the “plucked” parts of the string interact with the other parts of the string — and you get a wave.

But how do you model this in python? Assume that you have the initial shape of a string that is fixed at the two ends with some constant tension — how do you model the motion for future times? Yes, this is what we are going to do. Don’t worry, I’m going to start from the very basics.

A String as Finite Elements

Let’s pretend that the string consists of a bunch of individual masses connected by massless strings. It would look something like this.

Each mass is labeled with an index and they are separated by a distance of Δx and they all have the same mass. Note: this is a very small displacement such that we can keep each mass a constant distance Δx from each other. Oh, two more things. First, each mass can ONLY move in the vertical (y) direction and second the tension in the string has a constant magnitude. I guess I should also say that the gravitational force on each mass is negligible compared to the tension (so we will ignore that). I know this seems like a lot to ask of a simple string, but I’m going to keep asking for stuff until it breaks.

Let’s look at mass 3 above. There are two forces on it. There’s a tension pulling towards mass 2 and there’s another one in the direction of mass 4.

Since the mass can only move in the y-direction, I only need the y-component of these two tension forces. Let’s look at the one pulling towards mass 4. Since it’s in the same direction as the string, the ratio of Δy/L must be the same as T_y/T (where L is the length between masses). But wait! Remember I said that the horizontal distance between masses was constant? That must…

--

--

Rhett Allain
Rhett Allain

Written by Rhett Allain

Physics faculty, science blogger of all things geek. Technical Consultant for CBS MacGyver and MythBusters. WIRED blogger.

Responses (1)

Write a response