On writing this small note, I was prompted by a recently published article on Habré article
Dynamics of vertical flight of an aircraft lighter than air . I wanted to write a comment, but it quickly grew into something more and, as it seems, more useful.
The original article gives an example of calculating the dynamics of a balloon or a balloon in the atmosphere. At the same time, air resistance and atmospheric density and temperature gradients are taken into account, so the problem is reduced to a non-trivial differential equation, which is successfully solved numerically using Python language. Everything is good in the article: the ball took off, stopped, where necessary, and we got the ultimate height and time of ascent. It was necessary to launch another balloon, say, more, load it more fundamentally, or change hydrogen to helium - not a problem - we change the parameters in the program and again we calculate everything. The program is clear, linear, works, what can be improved here, if not complicate the model?
You can make the model and calculations become universally useful not for a particular ball, but for a wide range of tasks. It is possible to ensure optimal accuracy of calculations in the numerical integration of a differential equation. You can get rid of the need to manually set the limits of integration and the step when calculating in a wide range of parameters. Finally, you can tell a lot about the dynamics of the flight of our ball and without a numerical solution. And for all this, there is one old method, true and reliable, once obligatory for any calculations on a computer and before their appearance, and now optional and often attributable to magic and art -
bringing equations to a dimensionless form and its own scales . I will use the task of aeronautics, as an example, and show how much more meaningful and graceful the analysis of the task becomes when using this technique. And then I will explain why this may be important for programmers, and why this article got into the hub “Functional programming”.
The essence of bringing equations to their own scales consists in finding and introducing such units of time, distances, masses, currents and other dimensional variables in which the problem takes the most simple and elegant form. Such units are called
characteristic or
own scale of the task. At the same time, the number of parameters affecting its solution is significantly reduced, and if you are lucky to stumble upon a self-similar solution, the parameters may disappear altogether!
Usually, this technique is introduced when studying the dynamics of a harmonic oscillator, leading the equation of motion to a canonical form. Indeed, whatever the oscillator (large or small, low or high frequency, mechanical or electromagnetic), if time is measured not in seconds, but in periods of its free oscillations, and the amplitude is not in meters, but, say, in the magnitude of the initial deviation , the equation for any linear oscillator will have the same form:
x″+2 zetax′+x=0
It suffices to study the properties of the solutions of this equation in order to know everything about all viscous friction harmonic oscillators. Without friction in the problem, the parameters completely disappear, and we get, as a solution, an exemplary sinusoid. All the other sinusoids with the accuracy of a simple linear change of coordinates are absolutely identical, so there is no point in analyzing them separately.
This is also the case when analyzing second-order curves. Having considered a parabola, hyperbola or ellipse in their canonical (most compact) form, we learned all their remarkable properties. After that, this knowledge applies to any non-trivial quadric. Moreover, the same technique is used in the analysis of the equations of second-order physics (in partial derivatives).
The reduction of the problem to a dimensionless form at its own scales in physics corresponds to the search for a canonical form or some kind of pattern in programming. And, fortunately, it can be expressed by a completely formal algorithm:
- We introduce formal scale factors for variables;
- we divide the entire equation by any quantity having the dimension of its terms;
- from the resulting dimensionless complexes, including large-scale factors, choose as many as the factors we have, and equate them to one;
- we solve the resulting equations, expressing the scale factors through the parameters of the problem, and use the remaining complexes as similarity criteria.
As a result, we obtain equations in canonical form, the eigenvalues of the problem, as well as similarity criteria for generalizing solutions to physically similar systems. The more scales one can introduce (using, for example, symmetry), the more concise the equation of motion will turn out and the less control parameters will remain in the problem. The real treasure for the researcher is the situation when it is possible to exclude in general all the parameters of the problem and all its possible solutions in a single curve. Such solutions are called self-similar solutions, and they make life much easier, turning partial differential equations into ordinary differential equations, and even into algebraic ones. The second and third steps of the above algorithm require selection and reasoning, they are the least formal, but, even if we act using the search method, at this stage a very deep system understanding of the problem can be obtained.
Let us turn to the original equation of motion given in the article on aircraft, and show by his example how to transform it to a dimensionless form at its own scales. The equation has the form:
m fracd2hdt2=−mg+gW rho0e−bh− frac12withS rho0e−bh operatornamesign left( fracdhdt right) left( fracdhdt right)2,
with initial conditions
h(0)=h′(0)=0.
Here
h - height of the ball,
m - the mass of the entire aircraft with cargo,
g - acceleration of gravity,
W - the volume of gas in the ball,
c - coefficient of drag,
S - characteristic area of resistance,
ρ0 - air density at zero height,
b - coefficient in the Boltzmann distribution.
First step. We introduce the formal scales for time and distance:
h=h0y, quadt=t0 tau qquad(1)
and rewrite the equation of motion using strokes to denote derivatives:
m frach0t20y″=−mg+gW rho0e−bh0y left[1− fraccS2Wg frach20t20 operatornamesign(y′)(y′)2 right].
The initial conditions in our case are trivial, so they can be omitted, but in general, we must rewrite them too.
The second step, in fact, the dimensioning of the equation. All terms in it have the dimension of force and we are free to divide them into any force. Usually divided by the force of inertia - factor by the second derivative of the distance. In this case, as the parameters of the problem, usually well-known dynamic similarity criteria are obtained, such as the Reynolds number or Euler number. But in our task, we will attribute all forces included in the task to gravity
mg , and that's why. We are mainly interested in the position of static equilibrium - the limiting height of the ball at a given carrying capacity and the time of transition to it. A static equilibrium does not depend on the inertial properties of the system, but it directly depends on gravity. So, divide and cut, which is possible:
frach0gt20y″=−1+ fracW rho0me−bh0y left[1− fraccS2Wg frach20t20 operatornamesign(y′)(y′)2 right].
Everything, the equation is dimensionless, now all the variables and all the terms in it are just numbers. And now we are free to choose such length and time scales in order to minimize the number of task parameters. We have two unknowns.
h0 and
t0 and four dimensionless complexes:
frach0gt20, quad fracW rho0m, quadbh0, quad fraccS2Wg frach20t20
then we can make two of them disappear just by equating them to one. Moreover, the second complex does not depend on scale factors, and we need to choose the two remaining for destruction. And again we turn to the argument about the static equilibrium that interests us. The equilibrium position is determined by the equality to zero of acceleration, that is, it will not matter what factor will be at the second derivative of the height and we can do minimization of the number of parameters on the right side of the equation. Thus, we arrive at the following solution: we will choose the scale factors so that the third and fourth of the complexes listed by us disappear from the equation. For this we assume
bh0=1, quad fraccS2Wg frach20t20=1
and we get our own scale of the task:
h0= frac1b, quadt0= frac1b sqrt fraccS2Wg. qquad(2)
The remaining parameters are denoted as follows:
frach0gt20= frac1 gamma, quad fracW rho0m=B.
This is probably the most magical stage of our transformation, which is closest to art. But experience and some reasoning help in choosing the right scales. And then this experience allows us to see similar phenomena in different areas of science and to guess the characteristic properties of complex systems.
I allow myself to slightly postpone the analysis of the physical meaning of the scales and parameters we received, although it is also very pleasant and interesting, but I will immediately move on to the most delicious - to a dimensionless equation on my own scales:
frac1 gammay′=Be−y left(1− operatornamesign(y′)(y′)2 right)−1, quady(0)=y′(0)=0. qquad(3)
Here! I am ready to solve such an equation, analyze and integrate it numerically. And when I decide, I will easily move from my own scales to meters and seconds, encoded in relations (1) and (2).
So, let's begin. Find, for a start, where our generalized balloon will stop. To do this, equate both the speed and the acceleration in equation (3) to zero:
0=Be−y∗−1,
where do we get
y∗= lnB.
Immediately we conclude: in order for the limit height to exist, the condition must be met
B>1 . Next, let us estimate how long the ball will reach this height. To do this, equate the acceleration to zero and solve the Cauchy problem of the first order:
0=Be−y left(1−(y′)2 right)−1, quady(0)=y∗.
It is solved analytically by the method of separation of variables, and is reduced to the integral:
tau∗= inty∗0 fracBdy sqrtBey=2 operatornamearth left( sqrt1− frac1B right).
See, here they are - the fruits of the correctly chosen scale! Both the maximum height and the characteristic time of its achievement are expressed only through the parameter
B . This means that we can fix some value.
B>1 , construct a series of graphs for solving equation (3) for different values
gamma and thereby immediately describe
all the solutions for
any values B !
This is a universal one-parameter family of solutions obtained by numerical integration of problem (3) for various values
gamma :

After reaching the equilibrium height, the balloon makes damped oscillations for some time, but the characteristic time to reach this height is correctly estimated. From criterion
gamma only the oscillation period and the time of their attenuation depend. The more this parameter is, the more “rigid” our system is.
It remains to translate this family of graphs into a dimensional view, simply by multiplying the values along the axes by the corresponding scale factors. And now the numerical experiment is over and its results have gained universal meaning. You can substitute the actual dimensional parameters of the task, and instantly get the numbers along the axes, already in meters and seconds! Such a result can already be published in a serious reference for severe aeronautics or in a scientific article describing the whole phenomenon on a single graph.
Now let's see what we got in the form of parameters and variables. Replace the mass of the ball
m for the sum of the mass of gas
W rhog and payload mass
M :
m=W rhog+M=W rhog(1+ alpha),
Where
alpha= fracMW rhog - relative load capacity of the aircraft. In addition, we will accept a spherical ball and express its area and volume through a radius
R . In this view, we get the parameters of the problem:
B= frac rho0 rhog(1+ alpha), gamma= frac3cB8Rb.
The first is the buoyancy factor, depending on the gas used and the load being lifted, a very important parameter, it has absorbed all mass quantities. The second shows how the size and shape of the ball correlates with the density gradient in the atmosphere, that is, how large the atmospheric heterogeneities are in relation to the size of the ball.
Scales are expressed as:
h0=1/b tau0= frac12b sqrt frac3c2gR= sqrt frac gammagb
The distance scale is determined only by the density gradient. What is absolutely true, because it is precisely because of this gradient that the lifting of the ball, in general, stops somewhere. The characteristic time included dynamic values - acceleration of free fall, mass ratios and air resistance.
Characteristic height and time of the ball
h∗=y∗h0= frac1b lnB,t∗= tau∗t0=2 sqrt frac gammagb operatornamearth left( sqrt1− frac1B right)
also expressed through the basic parameters and scope of the task.
For example, let's see what happens for the physical parameters given in the original article:
B=4.57 gamma=686h0=8000 m tau0=12.47 minh∗=12166.6 mt∗=13.72 min
Summarize. Having worked a little on paper before feeding the task to the machine, we were able to get a more intelligible, universal result and noticed the most important properties of the solution. At the same time, we have not lost the “modularity” of the solution. That's what I mean. We formulated the task in the most general terms, and then, having already received the solution, we began to add new “features”, for example, we divided the concept of payload and the mass of the gas that lifts it. This complication affected the scale values, but did not change the nature of the decision.
If later it is necessary to add an account of the temperature gradient, the expression in the exponent becomes more complicated, but its essence and, most importantly, the scale will not change:
exp left( frac−bhT0T0−ah right)
after dimensioning it will look like this:
exp left( frac−y1− psiy right),
where is the new parameter
psi= fracabT0 It shows how the density and temperature gradients correlate. Since these are atmospheric parameters that are beyond our control,
psi Is a constant equal to
0.17 . The value of the constant, by the way, shows the significance of the effect of the temperature gradient, it is not great, but not negligible. The family of graphs will change a little, but, most importantly, it will remain one-parameter.
The use of the inherent scale of the problem in the calculations has one more significant advantage: the variables in this case usually take “moderate” values, that is, close to unity. This is very useful for floating-point calculations: accuracy is not lost in operations on values that differ greatly in order of magnitude. In addition, it is possible to correctly compare the roles of individual effects in a problem by comparing the values of the similarity criteria corresponding to them or the values of variables. For example, the value
B=4.5 says how many times the force of interaction with the atmosphere is greater than the force of gravity. And the square of the characteristic dimensionless lifting speed
(y∗/ tau∗)2 sim0.3 shows the degree of importance of air resistance in the vertical movement of the aircraft compared with buoyancy, which is expressed in units in brackets.
Finally, calculations in dimensionless variables and parameters have a certain internal consistency with the fact that solutions of differential equations are almost always transcendental functions, and only dimensionless quantities can be their arguments and results. The computer also operates solely on numbers, in dimensionless quantities. Static typing, in principle, allows you to enter the dimensions of physical quantities at the type level and check the program for correctness when compiling, but at the numerical stage we still work only with the values themselves. Any errors associated with units of measurement and dimensions are lost in such calculations. It is reasonable to prepare the task for the calculations, eliminating unnecessary, and leaving only the most essential and natural for the solver.
And what would happen if we chose other complexes, or referred all forces not to gravity, but, say, to inertia? There would be two parameters left in the equation, but the family of curves would become two-parameter, and it could not be shown on the same diagram. I admit, at first it happened to me exactly that, as a scale of length, I got the radius of the ball. But having played with these curves, I saw their geometric similarity (you see one in all parabolas), and a further cursory analysis of the resulting criteria and equations he himself pushed me to a hidden symmetry and suggested what the "canonical form" of our equations should be. This, however, a beautiful occupation! The task itself begins to talk about itself. I feel this kind of pleasure when building a system of types and data structures in a program on Haskell or in C #: when the program architecture corresponds to the internal structure of the task, everything becomes surprisingly natural, elegant, special cases are worked out automatically and the number of layers of abstraction decreases.
Dimensions of physical quantities in themselves are very interesting. They form a linear space, and the search for similarity criteria can be reduced to the problem of searching for a kernel in a space of dimensions, thereby formalizing this process. They, to some extent, play the role of types in physical calculations. Just as the compiler uses static typing to verify the correctness of a program, so a physicist uses dimensions to verify his calculations and results. As in a strictly typed pure functional language (for example, in Haskell), the function code can be derived from its type, in the same way, based on the dimension of physical quantities, one can construct dimensionless complexes, characteristic values in physical systems and obtain extremely useful and universal results. There are many examples in mechanics, gas and thermodynamics, quantum mechanics, etc. I recommend to get acquainted with the
remarkable work , which provides a bunch of beautiful examples of the application of dimensional analysis to problems from the Pythagorean theorem, to the oscillations of stars and Rayleigh scattering in the sky. This paper cites the words of John Wheeler, the teacher of Richard Feynman, who received the name “Wheeler's Rule”:
“Never start a calculation until you know the answer. Predetermining the calculation for each calculation: attract simple physical considerations (symmetry! Invariance! Preservation!) Before starting a detailed conclusion; consider possible answers to each riddle. Be bolder: after all, no one cares what you suggested. Therefore, make assumptions quickly, intuitively. Successful assumptions strengthen this intuition. Erroneous assumptions give a useful shake. "
This advice for programmers sounds very familiar: do not start writing the function code without having decided on its signature (type) and its behavior (tests); Before writing code, you should consider the types, data structures and their relationships. It is with this that OOP and functional programming are strong - there these principles do not just work, they, with skillful use, suggest the most natural and elegant solutions themselves, and in the case of the FP, they do it on a deep mathematical level, making it possible to prove the properties of programs and charge some work on the output properties of the program to the compiler.
Learn math, program beautifully and have fun!