Reflected Gradient Formula

The inverse of a function can be found by swapping x and ys in an equation (and then rearrange back to terms of x). This has the effect of reflecting the original function in the line y = x, as you are essentially just swapping the x and y axis.

Inverse Function- Basic - Maple Help

Some mates and I sat down a few weeks ago and tried to ask the question: how do we reflect in a different line, not y = x. We set out to construct a robust description of reflection, so we could get the equation of any a reflection of any function, in any other function!


We decided that we would need to find an equation to get the gradient of a line based on two other lines: one the reflectant (which can be imagined as the incident ray) and the reflector (the mirror or boundary). I set out to find this formula and here is what I found:

Variation 1

This is the second version of the formula for the gradient of reflection (the first being a method similar to this but with an unnecessary step, making it less simplified).

The aim is to have two equations:

Reflectant: y=m1x

Reflector: y=m2x

And we want to find the gradient of the line which is formed when the reflectant is reflected in the reflector. We know from physics that the angle of incidence (the angle the reflectant makes with the normal at the point of collision with the reflector) is equal to the angle of reflection:

Angle of Reflection -- from Eric Weisstein's World of Physics
Angle of Incidence = Angle of Reflection

Now we’ve got that essential aspect out of the way, let me explain how I derived the formula:

First know that we can represent a line as a complex number, 1 + im, where m is the gradient of the line we want to convert to this complex representation. So for example the line y=x can be represented as the complex number 1 + i, and the line y = -3x can be represented like 1-3i.

This works when there is 1 on the real axis, as then the y value is equal to the gradient.

Now, consider this example:

The reflector line is x = 0 (lets ignore that this is not possible in the form I said the lines would be in earlier), and the reflectant is y = -x.

Imagining the reflector line as the complex number (1-i), to get the reflected line we must get it’s complex conjugate, and then convert it back into the equation of a line. So (1-i) goes to (1+i), which is the complex number which represent the line y = x, giving us our reflected line.

Okay, so lets add getting the complex conjugate to our list of things we need to do.

Second consider the setup: Reflector: y = x, Reflectant: x=0.

From now on, the mirror line will be coloured black and the light ray will be coloured yellow.

Imagining again the reflectant line as the complex number (0-i) and the reflector (1+i), lets call (0-i) z1 and (1+i) z2. When you multiply together two complex numbers, you can imagine it as two properties of the complex numbers interacting:

The Argument of a complex number is the angle the line between the point and origin makes with the positive part of the real axis.

The Modulus of a complex number can be described as the distance from the number to the origin.

When you multiply two complex numbers, the resulting complex number will have a modulus that is the product of the two original numbers, and a argument that is the sum of the two original numbers.

Probably a Lot of Math — Complex Numbers
A way of looking at complex multiplication

Going back to our original scenario, observe that the modulus of z2 is π/4 (45⁰) and the modulus of z1 is -π/2 (-90⁰). The line we want to get is going to be y = 0, represented by the number 1 + 0i. So to get this, we need to multiply z1 by z2 TWO TIMES, to get a number with an argument of 0 (-90 + 2 * 45 = 0).

Okay, so lets add multiplying by z2 two times as another one of the things we need to do.

This gives us the formula:

M1 and M2 are defined above.

Okay, lets expand this:

We now have this complex number, but its not useful to us yet, as the real part is not equal to 1.

So if we multiply the complex number by 1 / Re (z) we will scale the entire thing so the real part is 1 and the imaginary part is whatever it lines up with.
Also at this point we can do a special trick, removing the i. Treat the imaginary part as the “y” and the real part as the “x”. This way the equation can be generalised to the Cartesian plane.

This gives us the final form of the equation:

The first version of the gradient of reflection formula

Variation 2

There is more that can be done – a slightly different approach…

A complex number can be written in the form

Where r is the modulus of the complex number and θ is the argument of the complex number.

So if we convert our formula at the earliest step, we get this:

We can simplify this by changing the arg functions to arctan(m1 or m2) (as the real part of z1 and z2 are just 1 and the imaginary part is simply the gradient of the lines those numbers represent). We can also use indices laws to first put the power of two into the second e’s exponent, and then add the exponents of both e factors, as they have the same base. We now get this:

It has been slightly rearranged so the negative term comes second

To go further, we must figure out how to get this formula to work on the cartesian plane, and thus must convert the formula into a complex number in the form a + bi.

To do this, we can use the mod-arg form of a complex number, so:

First, factor out i:

And see that now:

So now sub theta into the mod-arg form of the complex number:

And now we can just do what we did in the prior variation of this formula. Imagine we are scaling up the real part to 1, dragging the imaginary part along so it is the gradient of the new line. Do this by multiplying the imaginary part by 1 over the real part (dividing by real). Lets drop the i now as well:

Now you will see that this can be simplified by the trig identity tan = sin over cos, and we get the final formula!

The second formula

You can play around with

Variation One: https://www.desmos.com/calculator/vtoxqqta11

and

Variation Two: https://www.desmos.com/calculator/377n9twxwl

On Desmos

Thank you for reading.

Song of the article

Big Page on Vectors

A vector is a quantity with both direction and magnitude

I go by Vector. It's a mathematical term, represented by an arrow with both  direction and magnitude. Vector! That… | Despicable me, Despicable me gif,  Minions funny
Oh yeah!!!
2d vector
3d vector

Vectors can also be denoted (xi + yj + zk) and the vector variable can be called

The way you use a vector depends on if you are treating that vector as a position vector or a direction vector.

A vector is a position vector if the vector is describing a point relative to the origin. For instance, the vector 2i + 3j on it’s own only contains information about a movement of +2 in the x dimension and +3 in the y dimension. If you go onto say this is a position vector, this number now represents an absolute position on the plane, 2 on the x and 3 on the y (and is essentially a coordinate). If it is not specified that a vector is a position vector, it is not right to link it to the corresponding coordinate on a plane.

A position vector can be denoted where O represents the origin and A is a vector.

Essential vector properties / operations

Magnitude of vector

One of the most important things to know about a vector is it’s length. Use Pythagoras.

3D Pythag!

Find unit vector

Equation for unit vector

The unit vector essentially tells you the fundamental information about spatial direction. 2D spatial directions are numerically equivalent to points on the unit circle and spatial directions in 3D are equivalent to a point on the unit sphere.

Parallel vectors

Vectors are parallel if they are scalar multiples of each other.

Parallel vectors

Vector between two vectors

To get the difference in position between two vectors, do the following:

Go back down the A and along the B!
What is the formula for finding the magnitude of vector difference? - Quora
Visual representation of B->A

Scalar Product

The scalar/dot product of two vectors is the sum of the products of their corresponding components.

a \cdot b= \sum \limits_ {i=1}^n a_i b_i
How to calculate dot product

If the dot product of two vectors equal 0, the two vectors are at 90º to each other.

The Line

Line properties

In 2D, lines are parallel or intersect. To check if lines intersect, check if they are not parallel. To check if lines are parallel, look at the direction vector for both lines, if they are linear multiples of one another, they are parallel.

In 3D, lines can be parallel, they can intersect, and can also be skew. Skew lines are when the lines do not intersect and they are not parallel. To check if lines are parallel, see if the direction vectors are linear multiples of each other. To check if lines intersect, set the lines equal to each other, and rearrange to get two equations with two unknowns. Then plug the values of λ and μ into the z row of the original equation, if this equation is true, the lines intersect. If this z equation is false (ie the LHS and RHS are different), the lines are skew.

Vector equation of a line

The straight line r in vector line notation: λ is a variable marking that the b vector is variable in magnitude, and therefore sets the direction of the line.

a is a position vector whose purpose it is to move the line away from the origin.

Straight line r
The vector OD sets the direction and point A sets the position

Cartesian equation of a line

A line in vector equation form as such:

Essentially 3 different equations

Can be rewritten as:

This uses the aspect of the vector equation of the line secretly being 3 separate equations, and rearranges them to make λ the subject.

Angle between two lines / vectors

To get the angle between two lines, use the following formula.

Make sure to only use the direction vectors in the lines, as they are what define the direction of the line, and therefore the angle between the lines.

Angle between two vectors a and b

If the is negative, the result will be the obtuse angle between the two vectors. So if you want the acute angle, do 180 – θ.

c4 vectors angles - The Student Room
Negative dot product means you are getting the blue angle

The Plane

Vector equation of a plane

The vector equation of a plane looks similar to the vector equation of a line, but has another variable and another direction vector.

Plane Π is made of one position vector and two direction vectors

b and c must not be parallel.

This creates a infinite plane of values, achieved by varying lambda and mu.

Cartesian equation of a plane

The cartesian equation of a plane harnesses the normal vector – the vector that is perpendicular to the plane.

Cartesian equation of the plane

Where

Is the normal vector to the plane.

The scalar product equation of a plane

The scalar product equation of a plane is just like the cartesian equation, but folded up a bit.

The vector with the ns is the normal vector to the plane.

Angle between line and plane

Use the direction vector of the line and the normal vector of the plane, but note that some extra stuff has to happen once you’ve got the angle:

If you have the yellow angle, do 90 – the angle to get the acute angle between the line and the plane (purple).

If you have the blue angle, do the angle – 90 to get the acute angle between the line and the plane.

Intersect line and plane

This is the super easy one. Simply get the x, y and z formulae from the line equation, and plug those expressions into the Cartesian equation of the plane to get a value of λ.

Then plug this value into the line equation to get the position vector of the point of intersection.

Song of the article

Big Page on Matrices

What is a Matrix??

A matrix is a way of showing information efficiently. It is a rectangular array of numbers.

What is the difference between a row matrix and a row vector? What about a  column matrix and column vector? - Quora

Matrices have two dimensions: the number of rows (usually denoted as as m) and the number of columns (denoted as n). The order of a matrix describes it’s size.

Matrix (mathematics) - Wikipedia
n on the columns, m on the rows

Operations on Matrices

Addition and Subtraction

Adding and subtracting matrices is really easy. Just take each element and do the required operation on the corresponding item. YES this does mean both matrices have to be of the exact same order.

Matrix addition & subtraction (article) | Khan Academy
Adding two matrices 😇

Multiplication by a scalar

Multiplying (and dividing) by a scalar is also pretty easy. Simply apply the operation to all items in the matrix and BOOM you’ve got your answer:

Multiplying matrices by scalars (article) | Khan Academy
Multiplying a matrix by a scalar 😝

Matrix Multiplication

But what if we want to multiply two MATRICES together??! The circumstance where this is possible is if the number of columns (n) in the first matrix is exactly equal to the number of ROWS (m) in the second matrix.

When this condition has been met, this is what you do:

  1. Select the first row of the first matrix
  2. Select the first column of the second matrix
  3. Multiply each number in the first list by the corresponding number in the second list, and add them up
  4. Place the sum in the first row, first column of the output matrix.
  5. Repeat the process for all combinations of rows and columns

NOTE: the position of the number outputted by the above in the output matrix is whatever row the first matrix is on (m) as the y, and whatever column the second matrix is on (n) being the x.

More efficient matrix multiplication (fastai PartII-Lesson08) | by  bigablecat | AI³ | Theory, Practice, Business | Medium
Matrix Multiplication 🤯
Matrices: Multiplication 04 - Numbas at mathcentre.ac.uk
Matrix Multiplication GIF

There is no such thing as matrix division.

Matrix multiplication is non-commutative, meaning AB ≠ BA.

Maths

What can a matrix be used for?

Linear Transformations

Matrices are best used to describe linear transformations. That means the map a point onto another point. This can be visualised by stretching and/or rotating a plane or space.

A two by two matrix represents a linear transformation which works on a 2D plane, three by three represents a transformation on 3D space etc…

NOTE: AS THESE TRANFORMATIONS ARE LINEAR, THE ORIGIN ALWAYS MAPS ONTO ITSELF

Visualizing Matrix Transformations | R-bloggers
GIF showing basis vectors being modified, transforming the plane

A vector can be mapped into the transformed version of itself by applying the matrix multiplication as shown:

Translated vector = Transformation Matrix * Original Vector

The new vector is called the image.

Solving Simultaneous Equations

Due to the way matrices are multiplied together, matrices are perfect at solving systems of equations! 😁

Take this one for example:

3 unknowns, 3 equations!

You can separate the coefficients from the variables like so:

Notice that if you do the matrix multiplication, the exact same equations are formed

Then, pre-multiply the inverse of the matrix of coefficients, to get a formula giving the values of x, y and z:

Pop that in your calculator to get the values of x, y and z. How easy was that!

Modelling

Matrices are great at modelling things in real life, such as populations.

Most questions will give you some information revolving around the total quantity of something, and how it changes from one time to another.

To solve, find 3 equations which represents this system, and solve them as simultaneous equations using the matrix method.


Identity Matrix

Matrices that are square have a value called the Identity Matrix. The Identity Matrix essentially acts as “1” in matrix multiplication.

What is an identity matrix? - Quora
Identity matrix for 2×2 and 3×3 matrices

You can recognise the identity matrix by the leading diagonal being 1’s and all other items being 0. This matrix does nothing.

Zero Matrix
Intro to zero matrices (article) | Matrices | Khan Academy
0

Figuring out a matrices’ transformation

To figure out what exactly a matrix is doing to the plane, simply imagine the first column and the second column of the matrix as the new position of the (1,0) and (0,1) basis vectors respectively.

How to figure out what a matrix is doing

Matrix rotation

There is a faster way to check if a matrix is rotating: if you see a matrix with signs in the pattern following (they could be the opposite sign):

It is rotating the plane (this might not be the only thing it’s doing). In the case of the matrix above, it applies a rotation counter clockwise to (x, y) by θ degrees.


The Determinant

The determinant is a property of a transformation vector which represents the ratio of the area (or volume) between the original plane (or space) and the transformed plane (or space). So its how much bigger the area/space gets.

For instance the matrix is an enlargement sf 2 around (0, 0), meaning both basis vectors double. This of course increases the area by 4x as the distances are doubling in two directions.

2 by 2 Determinant

You can calculate the determinant of a 2 by 2 matrix with this formula:

The determinant can also be denoted as |A|, like the modulus function
3 by 3 Determinant

To find the determinant of a 3 by 3 matrix:

  1. Multiply one of the three numbers along the first row of the matrix by the 2 by 2 matrix left when taking out the rows and columns corresponding to that number.
  2. Apply the magic signs!
Magic signs!

3. Add them up.

Determinant of 3x3 Matrix - ChiliMath
Formula to get the determinant of a 3 by 3 matrix

Determinants (article) | Khan Academy
Watch as the determinant changes as the area of the translated plane changes

The determinant of a matrix will go negative when the plane has been “flipped” (watch the gif to visualise what this means)

If a matrices’ determinant is 0, it means all of space has been squashed into a lower dimension

If det(A) = 0 the matrix is SINGULAR (no inverse)

If det(A) c 0 the matrix is NON-SINGULAR

You can’t have an inverse of a singular matrix because there is no way to extract area back out from a line with a linear transformation.

The Inverse of a Matrix

The inverse matrix applies the opposite transformation on the plane, undoing the first transformation:

AKA

A matrix times it’s inverse equals the identity matrix

This reads: apply the transformation of matrix A, then apply the transformation of inverse matrix A equals the matrix that represents no change. In this case, A and A^-1 can be swapped as they just do the opposite of on another.

Inverse of 2 by 2 matrix

Use this formula to get the inverse of a 2 by 2 matrix:

Remember to swap the numbers in the matrix in this magical way! 🧙‍♂️
Inverse of 3 by 3 matrix 🥶

First off, the transpose of a matrix is found by flipping the matrix on it’s diagonal:

Getting the transpose of a matrix

Here’s how to get the inverse of matrix A (any non singular 3 by 3 matrix) by hand

  • Find det(A)
  • Construct a matrix of minors of A, to make a 3 by 3 matrix of 2 by 2 matrices
Matrix of minors, pretty large!
  • Get the determinant of every minor matrix to get a new 3 by 3 matrix!
  • Apply the magic signs!
Magic signs!
It’s getting kinda crazy!
  • Transpose the matrix of cofactors!
  • Multiply by 1/det(A)
The final step!
  • DONE

Consistent or Inconsistent?

  • A matrix is consistent when the corresponding system of equations has at least one solution
  • A matrix is inconsistent when the system of equations has zero solutions

This is the most common case, where there is a single set of x, y and z which satisfies all equations. The determinant here is not 0.

How to figure it out:

A flow chart on how to figure out the configuration of a system of three equations

Invariant points and lines

An invariant point is a point unaffected by a transformation.

An invariant line is when each point on a line is transformed to another point on the same line.

ReflectionsRotationsEnlargement
Invariant
Lines
Mirror line and all lines perpendicular.None, unless the angle = 180°, In which case all
lines through (0, 0).
All lines through (0, 0).
Invariant
Points
All points on mirror line.(0, 0)(0, 0)

To find invariant points:

Set the point (x, y) that has the transformation applied equal to the point (x, y). (So the point is the same after the transformation).

Find the invariant points!

Then, expand to get some equations:

This will either give you the equation of a line – in which case there is an entire line of invariant points – or a single value for x and y, if there is only one invariant point.

To find invariant lines:

First, suppose y = mx + c is an invariant line.

Set the matrix up like this:

y is set in terms of x, therefore the relationship between x and y is a line.

After this expansion, keep in mind that x’ and y’ must be on the line y = mx + c.

Get these two equations
Rearrange to this

Now plug these equations into the y = mx + c formula!

Song of the article

Decision Maths 1 Revision

Sorting Algorithms

Bubble Sort

Numbers are sorted into ascending order by comparing pairs of numbers. If the number on the left is larger than the number on the right, the two numbers are swapped. If the number on the right is larger, everything is kept the same.

C# Sharp exercises: Bubble sort - w3resource

This process is repeated until the list is completely sorted. In the worst case – where the list is in descending order – there must be n (n being the number of items in the list) – 1 passes.

For the number of comparisons each pass: if the algorithm is straight forward, it will be n-1, but the algorithm could be designed to appreciate that after the first pass, the largest number must be in the correct place, so it can automatically skip this out.

Formula for number of comparisons with n being number of items in list

Either way, this means Bubble sort is in Quadratic time: O(n2)

Quick Sort

Quick sort picks a number to be a pivot. It is usually the middle number (the rightmost if there are an even number of items) but it could be any number in the list and there should theoretically be no loss in efficiency. It then iterates through the other numbers, and puts them on the left of the pivot if smaller, right if bigger (order must persist!). Once one iteration is done, a new pivots are picked out of the two sets of numbers either side of the original pivot. The same process is then repeated until all numbers have been the pivot.

The order of quciksort is O(log n) but it seems I don’t need to be able to show it or know it at all.

Graph Theory

A Graph consists of vertices (nodes) and edges (arcs).

A vertex has an order (degree, valency). This is equal to the number of edges that are connected to it.

Network

How to normalize edges weight between 0 and 1 - Mathematics Stack Exchange

A network is a graph where every edge has a weight (numbered)

Connected

A connected graph means every vertex has a path to every other vertex

3. The graph shown is an example of disconnected graph with three... |  Download Scientific Diagram
Disconnected Graph

Simple Graph

A simple graph has no loops and no multiple edges

Simple Graph -- from Wolfram MathWorld

Directed Graph

Directed graph - Wikipedia
Directed graph

A directed graph gives a direction to every edge

Complete Graph (kn)

A graph that contains n vertices where each vertex has an edge between every other vertex. There will be

edges.

Song of the article