mathronic

Essentials · Treating Curves as Straight

Treating Curves as Straight

A fifteen-minute read: what it is for, where it is used

LIGO, an observatory in the United States, catches gravitational waves arriving from space. It has two arms, each 4 kilometres long, joined at a right angle like the letter L. Inside each arm, laser light travels back and forth through a pipe with the air pumped out; in a vacuum, light goes perfectly straight.

Imagine you are on the team that builds the floor for this pipe. You have the tool every building site uses: a spirit level, which shows you what horizontal is. You could lay the pipe by it from one end of the arm to the other, perfectly horizontal at every point.

The text below answers this question. When you have read it, come back to your guess: what held up, and what changed?

When you design something, you often run into two problems. First, evaluating the exact curve behind your answer every single time is costly; on a small processor even a sine is expensive. Second, you need to know how far off the result will be if one part is slightly off, and you cannot recompute every possibility from scratch. This topic solves both with one idea.

The Earth is a sphere, but to someone walking on it, it looks flat. An engineer building a football pitch, a building or a bridge also treats the ground as flat and draws up plans and calculations for a flat surface. That is not carelessness; it is a choice. Calculating on a sphere is hard and calculating on a plane is easy. And if you look closely enough at a sphere, the patch around you is indistinguishable from the flat surface that touches the Earth at that point. But how close is "close enough" depends on the job: in a courtyard you would never see the difference, yet for an instrument that stretches over kilometres and measures to the millimetre, you would.

The same holds for every smooth curve, that is, every curve without breaks or corners. In the derivative topic we saw that if you zoom in closely enough around a point, the curve looks just like its tangent line there, the straight line that just touches the curve at that point. Two numbers are enough to draw the tangent: the value of the curve at the point and its slope there. With these two numbers you can easily read nearby values of a hard-to-compute curve off the tangent. Using the tangent this way is what we will call treating the curve as straight. In your course and your textbook it is called linearization, and the tangent itself is the linear approximation at that point.

The slope also tells you how much the output moves when the input changes a little: if the slope is large, a small change in the input moves the output a lot. The slope can be read the other way round, too. If you measure the output and try to work back to the input, then wherever the slope is small, a small error in your measurement becomes a large error in the input. For example, if the slope is 0.1, an error of 1 unit in the measured output means an error of 10 units in the input. The engineers in the boxes below use the slope in both directions. The whole topic fits into one sentence:

Near the point you are looking at, a hard curve is indistinguishable from a straight line: treat it as straight and the calculation becomes easy, and you also know how far off you are.

The second half of the sentence matters as much as the first. The curve and the straight line meet only at that point; as you move away from it, a gap opens between them. Let us call this gap the approximation error. That gap is the price of treating the curve as straight. But the approximation error can be calculated too, and if it is large enough to matter, you take it into account.

This gives the answer to the opening question. A spirit level shows the horizontal at the point where it sits, so a pipe laid by it bends along with the Earth. Light does not bend; it goes straight. As LIGO's website explains, in such a pipe the beam would miss the mirror at the end of the arm and pass above it. Instead of laying the pipe by the spirit level, the builders worked out in advance how far off they would be if they treated the Earth as flat. According to the paper they published in 2001, a straight line that starts out level with the ground at the beginning of the arm, that is, along the surface that touches the Earth at that point, deviates from the ground by about 1.25 metres after 4 kilometres. They therefore calculated the height each section of pipe needed from the straight line of the light, not from the ground, and set the pipe's supports to that height. According to the paper, the typical deviation of the pipes from the straight line stayed below 5 millimetres.

Where it is used

The bank caught out by interest rates · in banking

You work in a bank's risk department. The bank has invested its customers' deposits in long-term bonds. A bond is a certificate for money lent at a fixed interest rate; if market interest rates rise, older bonds paying lower interest lose value.

If interest rates rise a little tomorrow, how much value will the bank's bonds lose? How do you know this each morning without recalculating every bond, and what do you do if the number looks bad?

The rough answer to this question is a number called duration. Think of the value of the bonds as a curve against the interest rate: duration gives the slope of that curve at today's rate, expressed as a percentage of the value. It is measured in years because, at heart, it is the average time until the bond's payments arrive. FINRA, the non-profit organisation, independent of the government, that supervises brokerage firms in the US, explains that when interest rates change by one percentage point, a bond's value moves in the opposite direction by roughly its duration, in percent. One percentage point is, for example, a rise in the rate from 3 percent to 4 percent. According to a 2023 review by the US Federal Reserve (the Fed), the bonds Silicon Valley Bank meant to hold to maturity had an average duration of 6.2 years at the end of 2022. A one-point rise in rates would have cut their value by roughly 6 percent, and rates rose quickly in 2022.

The real danger for a bank is a mismatch: when rates rise, its bonds lose value, but the present value of what it owes its depositors does not fall by as much. The risk lies in the gap between these two responses. When the number looks bad, the job is to genuinely shrink that gap, for example by moving to shorter-term bonds or by holding contracts that protect against rising rates. According to the Fed's report, in April 2022 the bank instead changed an assumption in its model: it assumed that deposits would stay at the bank longer. Once deposits count as long-term, the model has the value of what the bank owes falling as rates rise, just like its bonds; the two sides now look alike, so the gap shrank on paper. The report also says that during the same period the bank removed such protective contracts, that it changed the assumption rather than managing the actual risk, and that no risk had been taken off the balance sheet. Duration is a good shortcut for small changes in interest rates, but a shortcut is only as sound as the assumption built into it. The bank failed on 10 March 2023.

Known: how strongly the bonds' value responds to a small change in interest rates · Found: roughly what percentage of value is lost when rates rise a little · Where the rule breaks: the slope only works for small changes in rates and is only as sound as the assumption built into it; change the assumption and the number changes, but the risk does not.

The phone's spirit level · in the phone's accelerometer

You are writing a spirit-level app for a phone. It must show the correct angle both when the phone lies on a table and when it is held upright against a wall. The phone's accelerometer measures how much of gravity it feels along one of the phone's axes. When the phone is tilted from horizontal by an angle θ (theta), the reading along this axis is 1 g · sin θ, where g is the acceleration due to gravity. The sensor can only report its reading in steps of a certain size; the manufacturer states this step in thousandths of g, that is, in mg.

At which angles will your app be accurate, and at which will it be unreliable? How can you know this in advance, rather than by trying the phone at every angle?

A 2010 application note from Analog Devices (AN-1057), written for tilt-sensing accelerometers in general, reads the answer off the slope of the sine. Because the reading follows sin θ, the slope of the sine at a given angle tells you how much the reading changes when the angle changes a little. The note puts it this way: as the angle grows, the reading responds less and less to the angle, and this response approaches zero as the angle approaches ±90°; near 90°, a large change in angle produces only a small change in the reading.

Read the other way round, a small step in the reading turns into a large uncertainty in the angle wherever the slope of the sine is small. By our own calculation, when the phone is flat a 1-degree change in angle changes the reading by about 17.5 mg; at 63°, the slope of the sine, cos 63°, has dropped to about 0.45, so the same change is only 8 mg. That is why the note says that, to tell 1-degree steps apart up to ±63°, the accelerometer must report its reading in steps of at most 8 mg. The fix also comes from the slope: a second axis of the phone responds most strongly exactly where the first one stops responding. Since one axis gains response as the other loses it, the note explains, using both axes gives roughly the same resolution at every angle; the angle is then found from the ratio of the two readings.

Known: that the reading follows sin θ, and the size of the sensor's reading step · Found: at which angle the same step turns into the largest angle error · Where the rule breaks: near 90° the slope of the sine drops to zero; there you cannot reliably find the angle from a single axis.

The battery percentage that goes astray · in battery gauges

You are programming the chip that shows how full a battery is. One way to do this is to measure the battery's voltage while it is at rest and read the percentage off the known curve linking voltage and charge. The circuit that measures the voltage has a measurement error of a few millivolts; a millivolt is a thousandth of a volt.

If your gauge always reads the percentage from the voltage, where will the number on the screen mislead? What would you do there?

A 2011 article from Texas Instruments compares two kinds of battery. In the article's graph, the voltage of lithium cobalt oxide cells falls clearly as the charge drops; for lithium iron phosphate cells, the article says the voltage curve is extremely flat. Where the curve is nearly level, its slope is close to zero, so a small error in measuring the voltage turns into a large error in the percentage. In one example in the article, a voltage range of only 13 millivolts in a lithium iron phosphate cell corresponds to the charge falling from 70 percent to 64 percent; by our own calculation, a measurement error of one millivolt moves the percentage by nearly half a point.

The engineer's fix is to decide according to the slope. The gauge in the article does not trust the voltage where the curve is most nearly level; it trusts the voltage only where the curve is somewhat steeper. Between two trusted voltage readings, it tracks the change by adding up, over time, the current flowing into and out of the battery.

Known: the curve linking voltage and charge, and the measurement error of the circuit · Found: how much the same voltage error moves the percentage, and where the voltage can be trusted · Where the rule breaks: where the curve is nearly level its slope approaches zero, and reading the percentage from the voltage becomes unreliable there.

If you change a part a little, you know how much the result will change without recalculating everything. This lets an engineer see which part's deviation does the most damage to the result, and spend care and money there.

In your own project

This idea is not just for big laboratories; each of the following can be built on a student's desk. In each one, decide first what you would do; the calculation can come later.

You are building a room thermometer with an Arduino. The resistance of a cheap temperature sensor (a thermistor) changes with temperature along a curve, and the formula that turns resistance into temperature contains a logarithm; on a small processor that has to convert many readings quickly, this can be slow. Around the temperatures you care about, you can treat the curve as straight. Around which temperature would you do that, and how would you find out how far off you are ten degrees away?

You are driving a small robot arm with a microcontroller. To find the height of the tip of the arm you need the sine of the joint angle, and the processor is slow at computing sines. The arm only ever moves through small angles. What simpler thing could you use instead of the sine, and beyond which angle would you stop trusting it?

You are writing a travel app that lists the cafés, gyms and stops near you by distance. Instead of computing the distance between two locations on a sphere, you could treat the Earth around you as a flat map. How would you set up this flat map, and up to how many kilometres would you trust it?

In all three, the job is the same: find the value and the slope where you are, treat the neighbourhood as straight, and work out in advance where treating it as straight stops being good enough.

Its limits

Before you rely on treating a curve as straight, ask three questions: can it be calculated, can it actually happen, can it be trusted?

Can it be calculated? To treat a curve as straight, it must have a single slope at the point you are looking at. At a corner, for example the sharp tip of the absolute value at 0, there is one slope from the left and another from the right; no single tangent can be drawn, and you cannot treat the curve as straight there.

Can it actually happen? The duration rule is a straight line, and it goes on straight forever. If rates rose by twenty points, the rule, with a duration of 6.2 years, would say the value falls by 124 percent, that is, below zero. A bond's value cannot fall below zero; for a big jump, the straight rule gives a number that cannot happen.

Can it be trusted? A gauge that looked only at the voltage would show a percentage in the nearly level part of the curve too; a few millivolts of error would move that percentage, yet the number on the screen would look just as precise. Every number used without knowing the slope and how the error grows is like this: when it is wrong, it looks exactly as certain as when it is right. At LIGO, by contrast, the approximation error was known: the 1.25 metres were calculated in advance, and the pipe was built accordingly.

In the language of formulas Open this if you like; let us calculate the 1.25 metres on LIGO's arm together.

Call the Earth's radius R; it is about 6,371 kilometres, or 6,371,000 metres. The arm is s = 4,000 metres long. As in the paper, assume the beam starts out level with the ground at the beginning of the arm, that is, it travels along a tangent that touches the Earth at that point. Call the beam's height above the ground at the far end of the arm h. The Earth's centre, the start of the arm and the point the beam reaches at the far end form a right triangle: the two shorter sides are R and s, and the hypotenuse is R + h. By Pythagoras:

(R + h)² = R² + s²
R² + 2 · R · h + h² = R² + s²
2 · R · h + h² = s²

h is tiny compared with R, so we can drop h² next to 2 · R · h. Dropping a small term is an approximation too; we will check in a moment how far off it puts us. Putting in the numbers:

2 · 6,371,000 · h ≈ 16,000,000
h ≈ 16,000,000 / 12,742,000 ≈ 1.26 metres

This is the paper's "about 1.25 metres"; because the Earth is not a perfect sphere, the number varies by a few millimetres with the direction of the arm and the latitude. The h² we dropped is about 1.6 square metres, while 2 · R · h is 16 million square metres. So dropping h² changes the result by only about a ten-millionth of a metre, less than a micrometre. This is a different approximation error from the one in the main text: the 1.25 metres was the error of treating the Earth as flat, while this one is the error of dropping a small term while calculating. We know the size of both; we took the first into account and dropped the second as negligible.

LIGO's official website gives the same gap as "nearly a meter" on one page and "more than a vertical meter" on another. Why can you trust the paper's 1.25 metres more? Suggest an answer.

In your own words

What problem does treating curves as straight solve? Write it in your own words, using a project or job you would like to do yourself.

Two topics together

This topic is built on the derivative; the idea the two share is this:

The derivative tells you how fast a curve is changing at a point; treating the curve as straight tells you where you will be a moment later if you keep going at that rate.

An engineer works out once how fast the result changes with respect to a part, and then finds the effect of small deviations in that part without recalculating; when the deviation grows large, the engineer works it out again.

If you want to go deeper

The long version of this topic (the book) covers the same idea in detail over three chapters: each chapter starts with an everyday situation, first asks for your guess, and then lets you try things yourself with small experiments. Each chapter opens once you have written your guess in the one before. The chapters are in Turkish for now.

Sources: LIGO: W. E. Althouse, S. D. Hand, L. K. Jones, A. Lazzarini and R. Weiss, "Precision alignment of the LIGO 4 km arms using the dual-frequency differential global positioning system", Review of Scientific Instruments 72(7), 2001, pp. 3086–3094 · LIGO Caltech, "Facts" and "Vacuum" pages. Bank: Board of Governors of the Federal Reserve System, "Review of the Federal Reserve's Supervision and Regulation of Silicon Valley Bank" (28 April 2023) · FINRA, "Brush Up on Bonds: Interest Rate Changes and Duration" (2024). Phone: C. J. Fisher, "Using an Accelerometer for Inclination Sensing", Analog Devices AN-1057 (2010). Battery: K. J. Keller, "Fine-tuning TI's Impedance Track battery fuel gauge with LiFePO4 cells in shallow-discharge applications", TI Analog Applications Journal SLYT402 (2011) · G. Zerkalov, J. Wortham and B. Damle, "Considerations for Fuel Gauging Lithium-Iron-Phosphate Batteries", Maxim Integrated Application Note 6909 · TI SLUA364, description of the Impedance Track algorithm.