The same point can be expressed in two different ways using two different sets of basis vectors: a point written as in the basis of is the point , and the same point written in the basis of is .
In this chapter we meet an object that does not look like a vector at all - the polynomial - and discover that it is a vector in disguise.
A polynomial of degree n is a function where are n+1 real numbers (or floating point numbers if you are writing a program). These numbers are also called coefficients.
A simple (but inefficient) way to create a polynomial function is:
def create_polynomial_function(*coefficients):
def f(x):
return sum(c * x**i for (i,c) in enumerate(coefficients))
return f
Also note that a polynomial is completely defined by its coefficients. Thus we can start denoting a polynomial with an array of numbers .
If we have
then the sum of these two functions is another polynomial:
We can use the array of coefficients to denote these polynomial functions:
This looks just like adding two vectors:
Given a polynomial function , it is easy to see that
If we denote with the array of coefficients , then we have . This looks just like scaling a vector:
We have gotten so far only by defining two simple operations: scaling a vector and adding two vectors. We could replace a vector with a polynomial and the entire line of reasoning we have used so far would still be correct. Just like vectors, adding two polynomials gives us another polynomial of the same dimension (or degree). Just like vectors, a weighted sum of polynomials is also linear.
The algebra of vector addition and scaling is the same as the algebra of polynomial addition and scaling.
So when you add two arrays [p,q] and [x,y], it doesn't matter if you view them as vectors or polynomials. They are abstractions of properties shared by both vectors and polynomials. This abstraction leads to the idea of a vector space.
In short, a polynomial is just a vector and we will treat it like one.
This is just an opinion and you can skip it if you want.
We saw earlier that a matrix maps a straight line to another straight line. A matrix is just an array of (column) vectors. Now if you imagine a (column) vector to be coefficients of a polynomial, it becomes hard to understand what's going on: we are scaling and adding multiple polynomials to get a new polynomial. But where does "a line gets mapped to another line" fit into this picture?
The idea of an n-dimensional space where each point is a vector is one geometry that we gave to the algebra of vectors. When we visualize polynomial curves (on a 2d-plane) being scaled and added, that is another geometry that we are giving to the algebra of vectors. These two geometries should not be mixed. A matrix maps a line to another line in the geometry of n-dimensional spaces, not in the geometry of polynomial curves.
A polynomial of degree n can be seen as a vector of dimensionality n+1. For example is a polynomial of degree 2, which can also be seen as a 3-dimensional vector .
Next thing to note is that we can plot any polynomial on a 2d-plane. Here are some examples of polynomials corresponding to 2-dimensional, 3-dimensional, 4-dimensional and 5-dimensional vectors, plotted on the canvas as plain functions:
Let's scale by a scalar value .
is the scaled polynomial , which starts at - exactly on top of the grey original. You can see the effect of scaling both visually and algebraically (the scaled coefficient vector is shown on the canvas):
Note what happens as you scale: every point of the curve moves vertically by the same factor, the roots (where the curve crosses the x-axis) stay put, and at the whole curve flattens into the zero polynomial.
Note that you can only add two vectors if they have the same dimensionality. In other words, you can only add two polynomials if they have the same degree.
Take , i.e. the vector ,
and , i.e. the vector .
Adding them coefficient by coefficient - just like adding two vectors - gives :
You can verify the sum visually: at any value of , the height of the gold curve is the sum of the heights of the blue and pink curves.
Next we will see how selecting a particular kind of polynomial leads to Bezier curves.