Linear Functions
Learn about linear functions using different examples.
Linear algebra uses linear functions to realistically approximate real-world functions. Furthermore, linear functions also reduce the complexity of a system.
Linear function definition
If and are any two
Additivity:
Homogeneity:
We can combine these two properties in a single statement and say that a linear function must fulfill the following:
Furthermore, we can extend these properties to more than two objects and scalars.
The additivity property above says that whether we apply a linear function to a sum of objects or apply that linear function to the objects individually, subsequently adding them gives us the same result. Meanwhile, the homogeneity property says that we may first multiply an object with a scalar, then apply a linear function, or otherwise apply that linear function to an object and then multiply it with the scalar. Either way, our result is the same.
Simulation for verifying linearity
The code below tries to test the linearity of the two functions, f1
and f2
. Although the code that implements f1
and f2
is available, the test works even if we only have access to f1
and f2
but not their implementation. The code randomly generates two inputs, x1
and x2
, and then tests the additivity and homogeneity properties on 10000
randomly generated values of alpha
and beta
.
import numpy as npdef f1(x):return 2*xdef f2(x):return x**2#Initializing variablesx1, x2, isf1Linear, isf2Linear = np.random.randn(), np.random.randn(), True, Truefor i in range(10000):#Generating random scalars for linearity testalpha, beta = np.random.randn(), np.random.randn()#Verifying additivity and homogeneity for f1if f1(alpha*x1+beta*x2) != alpha*f1(x1)+beta*f1(x2):isf1Linear = False#Verifying additivity and homogeneity for f2if f2(alpha*x1+beta*x2) != alpha*f2(x1)+beta*f2(x2):isf2Linear = Falseprint('In 10000 random tries: f1 is ', ['Non Linear', 'Linear'][isf1Linear],' and f2 is ', ['Non Linear', 'Linear'][isf2Linear])
Although the code above seems to work well for the f1 and f2 functions, this approach is generally slow and occasionally impossible (when we can’t loop over all real scalars, for example). Luckily, we have analytical ways to do this as well when the definition of a function is available. Let’s go through some examples to learn how to verify a function’s linearity.
Examples
In this section, we present multiple examples to clarify the concept of a linear function. Although the linear function may be applied to any object, we use vectors in our examples. A vector is an ordered array of numbers, which is usually expressed as We may also express the same vector as
Linearity verification
Let’s solve a problem. You’re given the function ...