Fourier series in Mathematica

After my last post—the one about using Fourier series—I started thinking about how to use Mathematica to develop Fourier series.1 I could, of course, use the Integrate function to determine the Fourier coefficients, but Mathematica has other functions that can do the job directly once you understand how they work.

Mathematica has several Fourier functions, but I’m going to stick with the ones associated with sine series, FourierSinCoefficient and FourierSinSeries. They’re meant to be easy to use, and they are, but you need to know how they’re defined.

The coefficients used in both of these functions are defined this way:

fn=2π0πf(x)sinnxdx

This doesn’t match up exactly with the definition I used for getting the Fourier coefficients of a loading function, q(x):

qn=2L0Lq(x)sinnπxLdx

To use the Mathematica functions to get the qn, we have to do a change of variable. Let

z=πxL

so

x=Lzπanddx=Lπdz

(Here, z is just another variable name; I’m not using it to represent a complex number.)

This changes the expression for qn to

qn=2π0πq(Lzπ)sin(nz)dz

which means we can use the Mathematica functions as long as we substitute Lz/π in for x in the expression for q.

Let’s give it a try on this parabolic loading function:

q=4qmaxx(Lx)

It shouldn’t take many Fourier terms to get a good approximation of this.

Parabolic loading

Here are the Mathematica commands I used:

q = 4 qmax x (L - x)
qn = FourierSinCoefficient[q /. x -> L z/Pi, z, n]

You can see the substitution in the first argument to FourierSinCoefficient.

After simplification, the results were

qn={32L2qmaxn3π3for odd n0for even n

We could also get the series (through n=7) directly with FourierSinSeries:

qapprox2 = FourierSinSeries[q /. x -> L z/Pi, z, 7] /. z -> Pi x /L

where the inverse substitution comes at the end to put the expression back in the form we want. Here’s a screenshot from the Mathematica notebook:

Mathematica notebook screenshot of Fourier series

You can see that the coefficients match what we got earlier.

A quick plot of the difference between this truncated Fourier series and the original parabolic function shows that, as expected, the series does a good job of replicating the original:

Error of Fourier series estimate

In this plot, the horizontal axis is the fraction of L and the vertical axis is the fraction of qmax.

If you’re interested, here’s the entire Mathematica notebook:

Now that I understand the way these functions work, I can do more complicated Fourier analysis in Mathematica without questioning myself on whether I’m using them correctly.


  1. Something I couldn’t do in any of the posts in that series, as that would be breaking the rules I had set up for myself. 


Simply supported beam—Fourier series solution of the ODE

We’re finally here, at the end of all things. In this post, we’ll use a Fourier series to get the formula for the center deflection of a simply supported beam with a uniformly distributed load. We’ll see some of the same math that we saw in the previous Fourier series solution, but the fundamental approach will be different.

Let’s start with the fourth-order ordinary differential equation for a beam with a general loading function, q(x):

EIyiv=q

The simple supports at both ends give us these boundary conditions:

y(0)=y(L)=y(0)=y(L)=0

Let’s work out the solution for a loading condition we haven’t considered before, a distributed load in the form of a sine wave:

q(x)=qmsinmπxL

where m is a positive integer and qm is some constant amplitude. Given the form of the governing ODE and the boundary conditions, it seems likely that the solution will look like this:

y(x)=ymsinmπxL

It satisfies the boundary conditions, and if we plug it and the expression for q into the governing ODE, we get

EI(mπL)4ymsinmπL=qmsinmπL

which is a solution for all values of x if

ym=1EI(Lmπ)4qm

This will work for any value of m that’s a positive integer.

Since the governing ODE is linear, if q is the sum of several sine terms, the solution will be the sum of several sine terms. Returning to our favorite problem,

Simply supported beam with uniform load

we now have a path for expressing the solution as a sum of sines, as long as we can express the constant function, q(x)=w, as a sum of sines.

And of course we can. The Fourier sine series expression that fits a constant is

q(x)=m=1qmsinmπxL=w

where

qm=2L0LwsinmπxLdx={4wmπfor odd m0for even m

This result comes from the orthogonality of the sine function. The Fourier coefficients are the same as those for a square wave.

Plugging this result into the expression for ym, we get

ym=1EI(Lmπ)4(4wmπ)=4wL4m5π5EI

for odd m. Therefore,

y(L2)=4wL4π5EIm=1,3,5,1m5sinmπ2

You may recall from our earlier post that there’s a closed-form solution for this sum:

Simitses Table A-2

The last entry in this table with x=π/2 gives us

m=1,3,5,1m5sinmπ2=(π496)(π2)(π248)(π2)3+(π96)(π2)4=5π51536

Substituting the closed-form solution in for the sum yields our old friend:

y(L2)=(4wL4π5EI)(5π51536)=5wL4384EI


The purpose of this series of posts—apart from a bit of showing off—was to demonstrate why I love structural analysis. It has, even in the simplest of problems, a depth that rewards those who study it. And when you’re confronted with problems that aren’t so simple, you can draw on that depth to understand and solve them.


Simply supported beam—Newmark’s method

This would have been the last post in the series if I hadn’t realized recently that another method deserved a post. So this is the penultimate. It was described in this 1943 paper by Nathan Newmark and is known—or was known—as Newmark’s method.

I say was because this method is dead. How dead? Forty-five years ago, when I was an undergraduate taking structural analysis courses, Newmark’s method wasn’t being taught in the department that he had been the head of for decades and whose main building is named after him. That’s dead.

Which isn’t to say it wasn’t a good method. Some of my professors talked about using it when they were young, and it was a practical technique when engineers used slide rules and desk calculators, but it was clear by the 80s that its time had passed. Still, it’s desncribed in the textbook I used as an undergrad, and I did eventually learn it well after I was out of school, so here it is.

Newmark’s method is basically a way of doing double integration, so you can use it to go from loading to bending moments or from bending moments to deflection. As Newmark says in the introduction to his paper,

The numerical procedure is approximate, but leads to exact moments (or deflections) when the loading diagram (or diagram of “angle changes”) is made up of segments that are bounded by straight lines or by arcs of parabolas.

For our simply supported, uniformly loaded beam, the “angle change” diagram—which we’ve been calling a curvature diagram—is a parabola, so we can get an exact solution.

Let’s say we have a beam with any kind of support conditions and some general distributed loading:

Beam with generic loading

The fundamental trick of Newmark’s method is to imagine a set of simply supported beams inserted between the load and the real beam.

Insertion of simply supported beams

The small imaginary beam segments are all of the same length, λ, and the analysis proceeds by calculating the reaction forces at the ends of these beams and then building a table of loads, shears, and moments based on these reactions (reversed in direction) acting on the large original beam.

Here’s a figure from the paper that explains how to calculate the reaction forces for parabolically distributed loading:

Equivalent concentrated loads for parabolas

There are simpler formulas if the loading is distributed linearly.

You may have noticed the double curvature in the right drawing, which means that the load shown there is not parabolic. Newmark suggests using the formulas in this figure even if the loading curve is of higher order—the parabolic formulas are close enough if you divide the beam into several segments.

I’ve focused here on the process of going from loads to bending moments because I think the mechanics of that is easier to understand. But the same process applies to going from curvature to deflection. We went through that in the conjugate beam post.

In fact, Newmark does our problem in the paper. He uses the constant q as the intensity of the load and splits the beam into four segments:

Newmark four-segment solution

This may look impenetrable, but we can simplify it by using only two segments and explaining each step. Here’s the table, starting with the moment diagram:

Newmark two-segment solution

The row labeled Moment is the value of the bending moment at each point. The Curvature row is just the moment at each point divided by EI and with the sign reversed. Those are the easy ones.

The Angle change row is based on the curvature values and the formulas in Figure 5 above. The value at the left end is

L/224[70+6(wL28EI)0]=wL364EI

where we’ve used λ=L/2. This is also the value at the right end.

The value at the center is

L/212[0+10(wL28EI)+0]=5wL396EI

We start the Average slope row with the knowledge that the slope at the center of the beam is zero, so if the angle change across the center is

5wL396EI

then the average slope must go from

5wL3192EIto5wL3192EI

as we move from the left half of the beam to the right half.

(If you’re having trouble with this, remember that angle change is analogous to shear and think of a beam with an antisymmetric shear diagram. If the change in shear across the centerline is F, then the shear must be F/2 in the left half of the beam and F/2 in the right half.)

For the Deflection row, we know that the deflection is zero at the left and right ends. Since the average slope in the left half of the beam is

5wL2192EI

the deflection at the center must be

(5wL3192EI)(L2)=5wL4384EI

an answer we’ve now seen twelve times.


Simply supported beam—dummy unit load method

We’re in the home stretch of this series, so ANIAT will soon go back to complaining about Apple’s UI choices.1 Next week’s WWDC keynote should provide some inspiration.

But today’s post covers our eleventh method for deriving the center deflection of a uniformly loaded simply supported beam: the dummy unit load method. When I was an undergraduate, this was the method we used to determine the deflections of truss structures, but it’s more general than that. My favorite explanation of why it works is in Nicholas J. Hoff’s The Analysis of Structures. I have the original Wiley hardcover of this book, but you can apparently get both paperback and hardcover reprints.

Hoff uses the principle of virtual work in his explanation, and I’d like to quote him here, but unfortunately his explanation is split between one section on the analysis of trusses and another on the analysis of beams. I couldn’t figure out a nice way to put them together coherently, so you’re just going to have to trust me.

For a beam, you can get the deflection at a particular point by following these steps:

  1. Work out an equation for the bending moment, M, in the beam for the given set of applied loads.
  2. Imagine that same beam with those loads removed (this is the dummy structure) and a concentrated unit load placed at the point at which we want the deflection. By definition, the magnitude of a unit load is one. The unit load points in the direction of the deflection we want to calculate.
  3. Work out an equation for the bending moment, m, in the dummy beam with the unit load.
  4. The desired deflection is

    δ=0LmMEIdx

Let’s apply this simple principle to our problem:

Simply supported beam with uniform load

The bending moment is

M=w2(Lxx2)

where the x coordinate starts at the left end of the beam and increases to the right, as usual.

This same structure with just a unit load at the center is

Beam with dummy unit load

Its bending moment is

m=12xfor 0xL2

and m is symmetric about the center of the beam.

Therefore,

δ=y(L2)=0LmMEIdx

and we can take advantage of symmetry to say

y(L2)=2w4EI0L/2(Lx2x3)dx=w2EI[13Lx314x4]0L/2=w2EI[L424L464]=5wL4384EI

You can pretty much do this problem in your head if you’re good at figuring out least common multiples. I’m not, but after writing things out, I did realize that the LCM of 24 and 64 is 192.


  1. Heads up, though. I recently thought of a thirteenth method that’s different enough from the others to merit another post. Sorry about that.