Paul Abbott

In and Out offers readers an opportunity to ask questions of the experts. The Mathematica Journal encourages readers to submit problems in care of the editor. Answers posted to the Mathematica newsgroup, comp.soft-sys.math.mathematica, that appear here are edited for clarity and length.

Working with Intervals

A list of times of the form represents the periods when a particular system is not working. For two such lists, how can I determine the periods when both systems are not working?
Carl Woll ( answers: The function timelist simulates non-overlapping timing data of the form .

Here are two lists of timing data.

After converting each period into an Interval using Apply, IntervalIntersection returns those periods when both systems are not working.


I am interested in counting the number of paths from a node in a network back to that node, counting loops (cycles) only once. Is there any readily available code that does this?
Steve Luttrell ( answers: Use FindHamiltonianCycle. Here is an example of how this solves your problem.
Here is a random, labeled graph on 10 vertices with one more than half the number of possible edges, which is ususally sufficient to have a Hamiltonian cycle.

Using HighlightGraph, display a HamiltonianCycle of the graph g.

Listable Subvalues

I am writing functions for translating graphics primitives. The following function translates a single line object.

However, if I have a list of lines it does not work.

What is the best solution?
You can map your function over the list of lines.

Adding a rule to f for the case of list arguments makes this mapping operation automatic.

David Park ( provides an alternative solution: define as Function. The third argument to Function is a list of attributes for the purpose of evaluation.

Functions for transforming objects in 2 and 3 dimensions are defined in [1] with the packages available at [2].

How can I solve the functional equation ?
The solution to this functional equation is given at Noting that

then taking logs of both sides, one sees that , where is arbitrary, satisfies the functional equation. More generally, since

we observe that is a solution to the functional equation

for .
One way to solve the functional equation is to assume that the asymptotic behavior of the solution is .

Substitute this sum into the functional equation and expand into an asymptotic series.

Solving for the coefficients , one sees that .

Summing the asymptotic series, one obtains the same solution as earlier, .

Here we apply the same method to .

The pattern of the coefficients is clear: the coefficient is . Summing the asymptotic series, one obtains the general solution.

Absorbing the factor into the arbitrary constant, the solution can be written as . This solution results by taking the logarithm of the following identity.

Finally, we apply the same method to .

The pattern of the coefficients is clear: the even coefficients vanish, , and the odd coefficients read . Summing the asymptotic series, one obtains the general solution.

See also [3], [4], and [5].


The solution to the differential equation with is .

Solving the same equation numerically, I tried using the event function to find the extrema of .

How can I find those points where ?
Mark Sofroniou ( answers: An event is located when a change in sign in the event function is detected. For the function , the sign is practically always negative and the chance of hitting zero is infinitesimal.
You can construct an appropriate event function for extrema, where , by noting that . Then it is possible to use the Direction option to restrict the detection to points corresponding to a maximum.

Operational Solutions to Differential Equations

If is the electrostatic potential on the axis of a cylindrically symmetric system, then the potential at the point , where is the perpendicular distance from the axis, is given by the following (see, e.g., [6])

How can I implement the operator ?
The definition of is given at

Then, formally, one has

For an arbitrary potential , the operator formalism can be used to obtain the Taylor series expansion of about using NestList. For example, here are the first four terms.

For an axially symmetric potential, the Laplacian in cylindrical coordinates reads,

and the potential satisfies Laplace’s equation, . Verifying that the operator expansion produces a formal power-series solution is immediate.

Now for a concrete example. For a disk of radius , with uniform surface charge density , oriented with its normal vector along the -axis, here is the potential at .

Using the operator formalism one obtains

There is another approach to this problem: In the case of azimuthal symmetry, the general solution to Laplace’s equation is (the multipole expansion),
where and are the radial and polar spherical coordinates, respectively. Here is the truncated solution.

Now, if the potential is known on the axis, that is , then one can use equation (0) to determine and by series expansion of and term-by-term comparison. For , here is the series expansion of the axial potential.

Now, equate this to and solve.

Hence we obtain the (truncated series expansion of the) potential of the disk off the axis in spherical coordinates.

To compare this solution to that obtained earlier, we expand into a series in , valid for . See and

Check that we have the correct expansion for .

Hence the potential of the disk off the axis is given by

Changing coordinates from polar to cylindrical coordinates, and , we verify that the two expansions are consistent.

Elmar Zeitler ( submitted another example of an operator expansion. Using the integral definition (,

then the change of variables yields

Now, is a polynomial in and, since , we see that

Implementation of this operator expansion is direct.

Cluster Analysis

For an arbitrary matrix of non-negative integers, how can I obtain the sum of those matrix elements that are surrounded by zeros? As a concrete example, for the following matrix an output of is required.

The order in which the groups surrounded by zero is summed does not matter.
Carl Woll ( answers: First, use SparseArray to get the positions of non-zero elements.

Next, define a distance function yielding 0 for identical elements, 1 for adjacent elements, and a big number, say 10, for nonadjacent elements.

Then, use FindClusters with the Agglomerate method.

Finally, total the cluster values.

Here is a function to do all the steps.

Check that ClusterSums works on mat.

As a bonus, this approach can be extended to handle higher dimensional arrays.


[1] T. Wickham-Jones, Mathematica Graphics: Techniques & Applications, New York: TELOS/Springer-Verlag, 1994.
[3] E. Castillo, J. M. GutiĆ©rrez, and A. Iglesias, “Solving a Functional Equation,” The Mathematica Journal, 5(1), 1995 pp. 82-86.
[6] E. Zeitler, “Operators in Electron Optics,” Optik 3, 1995 pp. 103-134.
P. Abbott, “In and Out,” The Mathematica Journal, 2012.

About the Author

Paul Abbott
School of Physics, M013
The University of Western Australia
35 Stirling Highway
Crawley WA 6009, Australia