Wikipedia:Reference desk/Archives/Mathematics/2022 December 15

= December 15 =

Approximating y = e^x
I want to approximate y = e^x in the range x = a to x = c with two line segments (a, e^a) (b, e^b) and (b, e^b) (c, e^c) such that the error defined as the area between the original y = e^x and the two segments is minimised. All I really care about is the ratio (b - a) / (c - a).

I'm pretty sure I could do this by finding an expression for the area, taking the derivative, setting it to zero and solving for x to find b, but it feels like the solution shouldn't depend on a or b or even e, so all of that seems like it might be overkill.

Is there an obvious answer that I'm missing?

2A01:E34:EF5E:4640:4210:3448:E6A9:8778 (talk) 22:03, 15 December 2022 (UTC)


 * If you increase a and c together while keeping (c-a) fixed, say a -> a+d and c -> c+d, that just scales the areas up by a multiplicative factor of e^d. Therefore, the quantities (b-a) and (c-b) only depend on (c-a). We can say b = a + f(c-a) where f is some function. Perhaps that's the "shouldn't depend" that you're intuiting? Given that observation, you can simplify the calculation by setting a=0, then work out the answer just as you suggested. --Amble (talk) 00:13, 16 December 2022 (UTC)


 * Hi! The only direct thing comes to my mind is Taylor series expansion. However, I am not sure regarding the ratio part of the question. Are you trying to say ration between area under curve in both line segments (?). If so, I would highly recommend to work out on paper and see if this is something you want. I hope this helps! :) Cheers, Nanosci (talk) 00:17, 16 December 2022 (UTC)


 * The Leibniz integral rule is simple here because the integrands are zero at $$x = b$$. I get:


 * $$\begin{align}0 & = \frac{\partial}{\partial b} \left( \int _{a}^{b}\left( \frac{(b - x) e^{a} + (x - a) e^{b}}{b - a} - e^{x}\right) \partial x + \int _{b}^{c}\left( \frac{(c - x) e^{b} + (x - b) e^{c}}{c - b} - e^{x}\right) \partial x\right) \\

& = \int _{a}^{b}\left( \frac{\partial}{\partial b} \left( \frac{(b - x) e^{a} + (x - a) e^{b}}{b - a} - e^{x}\right)\right) \partial x + \int _{b}^{c}\left( \frac{\partial}{\partial b} \left( \frac{(c - x) e^{b} + (x - b) e^{c}}{c - b} - e^{x}\right)\right) \partial x \\ & = \frac{e^{a} + e^{b} (c - a) - e^{c}}{2} \end{align}$$


 * so


 * $$b = \ln\left( \frac{e^{c} - e^{a}}{c - a}\right)$$


 * catslash (talk) 01:10, 16 December 2022 (UTC)


 * Try $$a = 0$$, $$c = 1$$, then $$b = \ln(e - 1) \simeq 0.541325$$ which seems plausible. catslash (talk) 01:30, 16 December 2022 (UTC)


 * On further consideration, for any function $$f(x)$$, the area is stationary when


 * $$f'(b) = \frac{f(c) - f(a)}{c - a}$$


 * that is, the point at which the slope of the function is the average slope over the interval. catslash (talk) 02:32, 16 December 2022 (UTC)
 * I think this is correct. Here is another way of obtaining the result. By scaling we can choose $$a=0,c=1.$$ The piecewise linear function $$f_b$$ on the interval $$[0,1]$$ fixed by the three points $$(0,1),(b,e^b),(1,e)$$ never assumes values exceeding those of $$y=e^x,$$ so to minimize the difference in areas we can simply seek to maximize the area between $$f_b$$ and the x-axis, formed by two trapezoids glued back-to-back:
 * $$I_b=\int_0^1 f_b(x)dx=\frac{1}{2}b(1+e^b)+\frac{1}{2}(1-b)(e^b+e).$$
 * Solving $$\frac{d}{db}I_b=0$$ results in $$b=\log(e-1).$$ --Lambiam 07:21, 16 December 2022 (UTC)


 * Thankyou all. So as I suspected a and b are not relevant, but e actually is. I had the feeling that the base would end up canceling out and the ratio would end up being a common constant such as 0.5 or the golden ratio or something. 08:34, 16 December 2022 (UTC) — Preceding unsigned comment added by 2A01:E34:EF5E:4640:6743:DBBA:BC3:542 (talk)


 * Knowing the answer from having ground through the integrals, hindsight makes it obvious geometrically:
 * The area between the line segments and the curve is the area under the line segments minus the area under the curve.
 * The area under the curve is fixed, so the problem reduces to minimizing the area under the line segments (subject to the middle point being on the curve)
 * That is equivalent to maximizing the area of a triangle whose (upward facing) 'base' is a single straight line between the end points and whose 'apex' is the middle point (b, f(b)) of the line segment pair.
 * The area of a triangle is half the base times the height, so the area is stationary (and possibly maximal) when the apex is moving parallel to the base.
 * So the solution lies at a point where the slope of the curve is equal to the average slope over the interval.
 * catslash (talk) 19:23, 16 December 2022 (UTC)