Let $f(x) = |\log_2(x)|$ for $x$ belonging to the domain $(0,1]$. I would like to know if there is an algorithm to fit $f(x)$ using a piecewise linear function g(x) in an optimal way?. That is, on input $n$, the algorithm needs to output the better linear approximation using $n$ pieces. Also $g(x)<=f(x)$. Maybe there is a function/procedure in Python or other programming language?
2026-03-26 04:32:55.1774499575
Best piecewise with $n$ points for a portion of a log function.
115 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
1
There are 1 best solutions below
Related Questions in PIECEWISE-CONTINUITY
- Continuity of composite functions.
- Multivariable piecewise function optimization
- Find $k$ so that the following function is constant on any interval
- Piecewise functions in MATLAB. Help!
- Piecewise functions "overlap"
- To check whether the function is piecewise continuous or not
- Is function $f(x) = \frac{x^{2}-2}{x-\sqrt{2}}$ continuous for all $x$?
- How does Raph Levien's Spiro choose angles for the ends of a path?
- Let $x_1,x_2,...,x_n$ be n points in $\mathbb{R}^m$. Is the function $F(w)=max(w^Tx_1,w^Tx_2,...,w^Tx_n)$ differentiable for all $w$?
- Find all $x\in\mathbb R$ that satisfy the equation $|x| − |x − 1| = 1/2$ . Sketch the graph of the equation $y = |x| − |x − 1|$
Related Questions in LINEAR-APPROXIMATION
- Product and Quotient Rule proof using linearisation
- Find a vector $x \in \mathbb{R}^n$ such that $x \neq 0$, $x_1w_1 + \dots + x_nw_n \approx 0$ and $x \approx z$
- Linear approximation for an implicit function
- Linear approximation for an implicit function 2
- Differentials: to the nearest milimetre question
- Explanation for the Continuity of the Jacobi Matrix
- Linear Approximation and Volume of Cylinder
- What is the linear approximation of $f(x) = \frac1x$ when $x \approx 0$?
- Placing $n$ linear functions so that it is best fit to another function in integral norm sense?
- Intuition of error in Taylor appoximation and finding error in approximation of a function by a constant function
Trending Questions
- Induction on the number of equations
- How to convince a math teacher of this simple and obvious fact?
- Find $E[XY|Y+Z=1 ]$
- Refuting the Anti-Cantor Cranks
- What are imaginary numbers?
- Determine the adjoint of $\tilde Q(x)$ for $\tilde Q(x)u:=(Qu)(x)$ where $Q:U→L^2(Ω,ℝ^d$ is a Hilbert-Schmidt operator and $U$ is a Hilbert space
- Why does this innovative method of subtraction from a third grader always work?
- How do we know that the number $1$ is not equal to the number $-1$?
- What are the Implications of having VΩ as a model for a theory?
- Defining a Galois Field based on primitive element versus polynomial?
- Can't find the relationship between two columns of numbers. Please Help
- Is computer science a branch of mathematics?
- Is there a bijection of $\mathbb{R}^n$ with itself such that the forward map is connected but the inverse is not?
- Identification of a quadrilateral as a trapezoid, rectangle, or square
- Generator of inertia group in function field extension
Popular # Hahtags
second-order-logic
numerical-methods
puzzle
logic
probability
number-theory
winding-number
real-analysis
integration
calculus
complex-analysis
sequences-and-series
proof-writing
set-theory
functions
homotopy-theory
elementary-number-theory
ordinary-differential-equations
circles
derivatives
game-theory
definite-integrals
elementary-set-theory
limits
multivariable-calculus
geometry
algebraic-number-theory
proof-verification
partial-derivative
algebra-precalculus
Popular Questions
- What is the integral of 1/x?
- How many squares actually ARE in this picture? Is this a trick question with no right answer?
- Is a matrix multiplied with its transpose something special?
- What is the difference between independent and mutually exclusive events?
- Visually stunning math concepts which are easy to explain
- taylor series of $\ln(1+x)$?
- How to tell if a set of vectors spans a space?
- Calculus question taking derivative to find horizontal tangent line
- How to determine if a function is one-to-one?
- Determine if vectors are linearly independent
- What does it mean to have a determinant equal to zero?
- Is this Batman equation for real?
- How to find perpendicular vector to another vector?
- How to find mean and median from histogram
- How many sides does a circle have?
You can always consider the norm $$\Phi(\alpha ,\beta)=\int_a^b \Bigg[\frac{\log (x)}{\log (2)}-(\alpha +\beta x)\Bigg]^2$$ and minimize it with respect to $(\alpha ,\beta)$. This is equivalent to the sum of squares of a linear regression for an infinite number of points for $x \in (\alpha ,\beta)$.
The antiderivative is quite simple and writing $$\frac{\partial \Phi(\alpha ,\beta)}{\partial \alpha}=\frac{\partial \Phi(\alpha ,\beta)}{\partial \beta}=0$$ gives two linear equations in $(\alpha ,\beta)$.
Skipping the intermediate calculations, you should get $$ \beta=\frac{3}{(a-b)^3\log (2) }\Bigg[(a^2-b^2) +2 a b \log \left(\frac{b}{a}\right)\Bigg]$$ $$\alpha=\frac{(b-a) (\beta \log (2) (a+b)+2)+2 a \log (a)-2 b \log (b)}{2 (a-b) \log (2) }$$
Try for $a=\frac 12$ and $b=\frac 12+\frac 1{10}=\frac 35$ which give $$\alpha=\frac{-365-1992 \log \left(\frac{5}{3}\right)+1990 \log (2)}{2 \log (2)}\qquad\qquad \beta=\frac{330-3600 \coth ^{-1}(11)}{\log (2)}$$ gives a maximum absolute error of $0.004$ at the bounds.
But, making $a=\frac 12$ and $b=\frac 12+\frac 1{100}=\frac {51}{100}$, the maximum absolute error is $0.00005$ at the bounds.
But, because of the curvatur of the logarithmic function, I do not see how your constraint $g(x) \leq f(x)$ could (at least easily) could be satisfied.
Edit
Making $b=a+\epsilon$ and using series expansions with $t=\frac \epsilon a$ $$\alpha=\frac 1{2\log(2)}\Bigg[2 \log \left(\frac{a}{e}\right)+\sum_{n=1}^\infty (-1)^{n-1}\, c_n\,t^n\Bigg]$$ where the $c_n$ form the sequence $$\left\{1,\frac{13}{30},\frac{4}{15},\frac{13}{70},\frac{29}{210},\frac{3}{28},\frac{3}{35},\frac{139}{1980},\cdots\right\}$$ $$\beta=\frac{1}{a \log (2)}\sum_{n=0}^\infty (-1)^{n}\, d_n\,t^n\Bigg]$$where the $d_n$ form the sequence $$\left\{1,\frac{1}{2},\frac{3}{10},\frac{1}{5},\frac{1}{7},\frac{3}{28},\frac{1}{12},\frac{1}{15},\frac{3}{55},\cdots\right\}$$ and $$\Phi_{\text{min}}\sim\frac{\epsilon ^5}{720\, a^4 \log ^2(2)}$$