Linearization

 

To linearize the expression a + bx, you can use a linear regression approach to fit a line to the data points. Here’s an example code using the scikit-learn library in Python:

python
from sklearn.linear_model import LinearRegression
 
# Define your data points
x = [1, 2, 3, 4, 5]
y = [3, 5, 7, 9, 11]
 
# Reshape the x data to a 2D array
X = [[xi] for xi in x]
 
# Create a linear regression model and fit it to the data
model = LinearRegression().fit(X, y)
 
# Print the intercept and slope of the line
print(“Intercept: “, model.intercept_)
print(“Slope: “, model.coef_[0])

In this example, we have defined two lists, x and y, representing the input and output values of the a + bx expression. We then reshape x to a 2D array using list comprehension, which is required by the LinearRegression class. Next, we create a LinearRegression object and fit it to the data using the fit method. Finally, we print the intercept and slope of the line, which represent the values of a and b in the original expression.

Alternatively, if you only have a single point and want to linearize it with respect to its tangent line, you can use the sympy library in Python:

python
import sympy
 
# Define your point and slope
x0 = 2
y0 = 5
m = 3
 
# Define the independent variable and the function
x = sympy.Symbol(‘x’)
f = y0 + m*(x-x0)
 
# Print the linearized expression
print(f)

In this example, we have defined a single point (x0, y0) and a slope m. We then define the independent variable x and the function f using the sympy library. Finally, we print the linearized expression, which is 3*x - 1 in this case.

Linearization is a common technique used in optimization to convert a nonlinear objective function or constraint into a linear form. The advantage of linearizing a nonlinear function is that linear optimization algorithms can be used to solve the problem, which are often more efficient and have better convergence properties than nonlinear optimization algorithms.

There are different methods to linearize a nonlinear function, and the choice of method depends on the nature of the function and the problem at hand. Here are some common techniques:

  1. Taylor approximation: The Taylor series can be used to approximate a nonlinear function by a linear function around a point. The first-order Taylor approximation is a linearization of the function using the tangent line at a point, while higher-order approximations use higher-order derivatives. This method is commonly used for convex functions and can be applied to both objective functions and constraints.

  2. McCormick envelopes: The McCormick envelope is a technique used to linearize a product of two variables that are bounded within a certain range. The idea is to approximate the product by a set of linear inequalities that form a tight envelope around the product function. This method is commonly used in mixed-integer nonlinear programming (MINLP) problems.

  3. Big-M method: The Big-M method is a technique used to linearize constraints involving binary or integer variables. The idea is to introduce a large constant M and use binary or integer variables to enforce the constraint when a certain condition is met. This method is often used in mixed-integer linear programming (MILP) problems.

  4. Piecewise linearization: The piecewise linearization method involves approximating a nonlinear function by a piecewise linear function that consists of linear segments. The segments are chosen to closely approximate the nonlinear function over a certain interval. This method is commonly used in global optimization problems.

Linearization is a powerful tool in optimization, and it can significantly improve the efficiency and accuracy of the optimization process. However, it is important to note that linearization can introduce approximation errors, and the quality of the linearization depends on the choice of method and the accuracy of the approximation.

Taylor approximation

 

The Taylor approximation is a method to approximate a nonlinear function by a linear function around a point. In the case of the linear equation a + bx, the first-order Taylor approximation involves approximating the function using the tangent line at a point.

Let’s say we want to approximate the function f(x) = a + bx around the point x0 = 2. We can use the first-order Taylor approximation to obtain the following linear approximation:

scss
f(x) ≈ f(x0) + f'(x0)*(x – x0)
= f(x0) + b*(x – x0)
= a + b*x0 + b*(x – x0)
= a + b*2 + b*(x – 2)
= 2b + ax

where f'(x0) is the first derivative of f(x) evaluated at x0, and x is the independent variable. The resulting linear function is 2b + ax, which is a valid approximation of a + bx near x0 = 2.

For example, let’s say we have the linear equation f(x) = 3 + 2x, and we want to approximate it around the point x0 = 2. Using the first-order Taylor approximation, we get:

scss
f(x) ≈ f(x0) + f'(x0)*(x – x0)
= f(x0) + 2*(x – 2)
= 3 + 2*2 + 2*(x – 2)
= 4 + 2x

So the linear approximation of f(x) around x0 = 2 is 4 + 2x, which is a valid approximation of f(x) = 3 + 2x near x0 = 2. We can plot the original function and its linear approximation to visualize how close they are:

python
import numpy as np
import matplotlib.pyplot as plt
 
# Define the original function
def f(x):
return 3 + 2*x
 
# Define the linear approximation
def g(x):
return 4 + 2*x
 
# Define the point of approximation
x0 = 2
 
# Define the range of x values to plot
x = np.linspace(0, 4, 100)
 
# Plot the functions
plt.plot(x, f(x), label=‘Original function’)
plt.plot(x, g(x), label=‘Linear approximation’)
plt.plot([x0, x0], [-2, 10], ‘k–‘, label=‘Approximation point’)
plt.legend()
plt.show()

The resulting plot shows that the linear approximation closely follows the original function near x0 = 2.

McCormick envelopes

 

The McCormick envelope is a technique used to linearize a product of two variables that are bounded within a certain range. In the case of the linear equation a + bx, we can use the McCormick envelope to linearize the product ax + bx^2.

To use the McCormick envelope method, we need to first bound the two variables a and x. Let’s assume that a is bounded between a_min and a_max, and x is bounded between x_min and x_max. We can then define two auxiliary variables y and z as follows:

css
y = a*x_min 
z = a*x_max

Using these auxiliary variables, we can linearize the product ax + bx^2 as follows:

scss
ax + bx^2 = a*(x_min + (x_max – x_min)*(x – x_min)/(x_max – x_min)) + b*(x_min + (x_max – x_min)*(x – x_min)/(x_max – x_min))^2
= a*x_min + (a*x_max – a*x_min)*(x – x_min)/(x_max – x_min) + b*x_min^2 + 2*b*x_min*(x_max – x_min)*(x – x_min)/(x_max – x_min) + b*(x_max – x_min)^2*(x – x_min)^2/(x_max – x_min)^2
= y + (z – y)*(x – x_min)/(x_max – x_min) + b*x_min^2 + 2*b*x_min*(x_max – x_min)*(x – x_min)/(x_max – x_min) + b*(x_max – x_min)^2*(x – x_min)^2/(x_max – x_min)^2

The resulting expression is a linear function of x, y, and z, which can be used in linear optimization problems. The variables y and z represent the lower and upper bounds of the product ax, respectively, and they are linearly related to x.

For example, let’s say we have the linear equation f(x) = 3 + 2x, and we want to linearize the product ax + bx^2 using the McCormick envelope method. Let’s assume that a is bounded between 1 and 3, and x is bounded between 0 and 2. Using the auxiliary variables y and z, we get:

css
y = a*x_min = 1*0 = 0
z = a*x_max = 3*2 = 6

Substituting these values into the McCormick envelope expression, we get:

scss
ax + bx^2 = y + (z – y)*(x – x_min)/(x_max – x_min) + b*x_min^2 + 2*b*x_min*(x_max – x_min)*(x – x_min)/(x_max – x_min) + b*(x_max – x_min)^2*(x – x_min)^2/(x_max – x_min)^2
= 0 + (60)*(x – 0)/(20) + 0 + 2*0*(20)*(x – 0)/(20) + 2*(20)^2*(x – 0)^2/(20)^2
= 3x^2 + 6x

So the linearized expression for ax + bx^2 is `3x^2 + 6

Big-M method

 

The Big-M method is another technique used to linearize nonlinear expressions in linear programming problems. In the case of the linear equation a + bx, we can use the Big-M method to linearize the product ax.

The basic idea of the Big-M method is to introduce a binary variable z that takes on the values of either 0 or 1 depending on the value of x. Specifically, we can write x as a linear combination of z and a constant value M, where M is a large positive constant that is larger than the maximum value of x in the feasible region of the problem. We can then use this expression to linearize the product ax.

The linearized expression using the Big-M method can be written as:

css
ax = Mz + (a-M)*x

where z is a binary variable that takes on the value of 1 if x is in the feasible region, and 0 otherwise. The value of M needs to be chosen such that it is larger than the maximum value of x in the feasible region.

For example, let’s say we have the linear equation f(x) = 3 + 2x, and we want to linearize the product ax using the Big-M method. Let’s assume that a is bounded between 1 and 3, and x is bounded between 0 and 2. We can choose M to be a large constant value such as 10. Using the binary variable z, we get:

makefile
x = z*M + (1-z)*x_max

where x_max is the maximum value of x in the feasible region, which is 2 in this case. Substituting this expression into the product ax, we get:

css
ax = a*x
= a*(z*M + (1-z)*x_max)
= a*z*M + a*(1-z)*x_max

We can then linearize this expression using the Big-M method as follows:

css
ax = a*z*M + a*(1-z)*x_max
= Mz*a + x_max*(a-M) + x*(M-a)

We can then add constraints to ensure that z takes on the values of either 0 or 1, such as:

0 <= z <= 1

With this linearized expression and the binary constraint on z, we can solve the linear programming problem using standard optimization techniques.

Piecewise linearization

Piecewise linearization is another technique that can be used to linearize nonlinear expressions in linear programming problems, including the linear equation a + bx.

The basic idea of piecewise linearization is to break the nonlinear expression into smaller linear segments that approximate the nonlinear function over specific ranges of the independent variable. In the case of a + bx, we can break the function into two segments based on the sign of bx. Specifically, we can define a new variable y such that:

makefile
y = bx

We can then break the function a + bx into two linear segments based on the sign of y:

less
if y >= 0: a + bx = a + y
if y < 0: a + bx = a - y

We can then linearize each segment separately using standard linear programming techniques.

For example, let’s say we have the linear equation f(x) = 3 + 2x, and we want to linearize the expression using piecewise linearization. We can define the variable y as:

makefile
y = bx

We can then break the function a + bx into two linear segments based on the sign of y:

less
if y >= 0: a + bx = a + y
if y < 0: a + bx = a y

For the first segment where y >= 0, we can define a new variable u such that:

makefile
u = y

We can then rewrite the expression a + y as:

css
a + y = a + u

We can add a constraint to ensure that u >= 0, such as:

u >= 0

For the second segment where y < 0, we can define a new variable v such that:

makefile
v = -y

We can then rewrite the expression a - y as:

css
a - y = a + v

We can add a constraint to ensure that v >= 0, such as:

v >= 0

With these linearized expressions and constraints, we can solve the linear programming problem using standard optimization techniques.

Piecewise linearization can be an effective technique for linearizing nonlinear expressions, especially when the nonlinear function has a simple structure that can be broken into smaller linear segments. However, it can also result in a larger number of variables and constraints compared to other linearization techniques.

Leave a Reply

Your email address will not be published. Required fields are marked *