MA124 Maths by Computer Week 8 Assignment: Solution 8A:Root Finding
MA124 Maths by Computer Week 8 Assignment: Solution 8A:Root Finding
Week 8 Assignment
Thomas Dove 1403349
Kyle Byrne 1407493
March 2, 2015
f (xn )
f 0 (xn )
(1)
log(10M (b a)
log(2)
Where log(x) is the natural logarithm of x. So from this we can see it will
M
(ba)
take at least log(10
iterations to have an approximation of a root to 10M
log(2)
accuracy. When carrying out these computations it is much more favourable to
use a method with fewer iterations necessary , for example the Newton-Raphson
method. Taking the error at the nt h iteration to be en = xn + r in the NewtonRaphson scheme, where r is the actual value of the root. We can clearly see
that the errors satisfy the difference equation ;
f (xn )
f 0 (xn )
f (xn )
en+1 + r = en + r 0
f (xn )
en f 0 (xn ) f (xn )
en+1 =
f 0 (xn )
xn+1 = xn
(3)
So letting Cn =
f 00 ()
2f 0 (xn )
We get that;
en+1 = Cn en 2
(4)
f (xn )
tn
where
tn =
f (xn ) f (xn1 )
xn xn1
(5)
As we did with the Bisection and Newton-Raphon methods we can use Matlab
to carry out the necessary computation to calculate our root of f(x) to within
10 12. This method requires to initial values as with the bisection method so
again we used x0 = 2 and x1 = 1. Then we obtained the following output;
So for A to be a magic square, its entries must satisfy the following equations;
a11 + a12 + a13 = r;
(Sum of Rows)
(Sum of Columns)
a11 + a22 + a33 = r;
1
1
1
Mv =
1
1
1
1
0
0
1
0
0
1
0
1
0
0
0
1
0
0
0
1
0
0
0
0
1
0
1
0
1
0
1
0
0
0
0
0
1
0
0
1
0
1
1
0
1
0
0
0
1
0
0
0
0
1
1
0
0
0
1
0
0
1
0
1
0
0
0
0
a11
0 a12
1
a13
0
a21 = 0
0
a22
1 a23
1
a31
a32
0
a33
(8)
can be shown to be equal to the equations satisfied by the magic square matrix
A. This can be done by using matrix multiplication of M and v to gain 8 linear
equations as follows:
r + a11 + a12 + a13 = 0;
Solution 8B(b)
Using the command rref in Matlab, we are able to reduce the matrix M to row
reduced echelon form.
By inputting the following into the command line of Matlab, we get the output
as follows:
Figure 5: Using the rref command to find the row reduced form of M
And hence the row reduced
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
0 0 0 0
0 0 0 0
0 0 0 0
0
2/3 2/3
2/3
1/3
1/3
2/3
2/3
1/3
1/3 1/3
4/3 1/3
1/3
2/3
2/3
4/3
1
/3
2/3
(9)
From the row reduced form of M above we can see that the rank of M is equal
to 7, as that is the number of non-zero rows of M in its row reduced form.
Therefore as the rank of a matrix is also equal to its column rank, this tells us
that the matrix has 7 linearly independent columns (The 7 left most columns)
and these are the pivot columns.
So as our system of linear equations has 10 variables but only 7 pivot columns
this means that there are 3 free variables. As this is so, this means the basic
variables , r, a11 , a12 , a13 , a21 , a22 , a23 , corresponding to the pivot columns,
depend on the free variables a31 , a32 and a33 , which can take any real number.
So by choosing values for the free variables a31 , a32 and a33 , this will then determine the values for the rest of the variables, which for any choice of the three
variables is the only solution to (8), as each basic variable depends on the all
three of the free variables as follows:
= 0;
= 0;
= 0;
= 0;
= 0;
= 0;
From here, we want to show that the set of 3 3 magic squares , S3 , (the set
of all 3 3 matrices, of form A, which satisfy (8) ) forms a vector space. For
this it must be shown this set satisfies all properties of a vector space.
Addition of the magic square matrices satisfies A1, A2 , A3 and
A4. As matrix addition for any two matrices in R33 are associative and
commutative, so A1 and A4 hold.
To show A2 holds, consider the zero element for addition of R33 which
is:
0 0 0
0 0 0
0 0 0
It is clear to see this is a magic square as all rows, columns and diagonals
sum to zero, meaning the system of linear equations (8) is satisfied and
hence the zero element of addition is also an element of S3 . So A2 holds.
Finally, for a given element A in S3 , there exists a matrix (A) R33
such that:
By considering (-A), we can see that the sum of rows, columns and leading
diagonals of (-A) are all equal to (a11 + a12 + a13 ) = r, where r is the
row sum of (A). Hence (-A) is also a magic matrix and A3 holds.
For any two 3 3 magic squares, u and v , that: (u + v) =
u + v holds for all R.
This holds by the distributive property of matrices when multiplied by
scalars. That is:
p (X + Y) = p X + p Y
(p + q) A = p A + q A
8
p (q X) = pq (X)
where X is a m n matrix and p, q are scalars. Hence as S3 is a subset of
R33 , then the associative property also holds for all elements of S3 .
For any 3 3 magic square, v , that: 1 v = v
This holds by the identity property of matrices by scalar multiplication.
That is:
1X=X
where X is a mn matrix. And so by a similar arguement for the previous
properties, this also holds for the set S3 .
And so as the above properties hold this means that the set S3 is a vector space
of the field R.
Note that the number of free variables in the system also lets us know the
determinant of the vector space of 3 3 magic squares, and that the determinant is equal to the number of these free variables. This is because all other
variables in the magic squares are determined by the choice of these free variables, and as the free variables can take any real number, the vector space must
contain all magic squares where a31 , a32 and a33 are real numbers. So our basis
must span all possible values of the free variables, and a way to ensure this is
by considering a basis of:
The magic square with free variables, a31 = 1, a32 = 0 and a33 = 0
The magic square with free variables, a31 = 0, a32 = 1 and a33 = 0
The magic square with free variables, a31 = 0, a32 = 0 and a33 = 1
So any linear combination of these magic squares allows for a magic square
with any value of the free variables to be made, and as for each choice of free
variables there is only one magic square corresponding to it, if the set spans all
possible values of the magic square with free variables, a31 , a32 and a33 it spans
all possible magic squares. It is also clear to see that the three magic squares in
the basis are linearly independent as no linear combination of two of the magic
squares free elements can create that of the third. Therefore the dimension of
the vector space is 3.
Solution 8B(c)
Given the matrices below, we want to show that they form a basis. This can be
achieved by considering linear independence between the three matrices. It is
also key to note that each of the matrices are magic matrices as all satisfy the
system of linear equations in (7).
1 1 1
M1 = 1 1 1 with r = 3
1 1 1
0
1 1
1 with r = 0
M2 = 1 0
1 1 0
1 1 0
1 with r = 0
M3 = 1 0
0
1 1
We can show that these matrices are linearly independent as follows.
By considering M2 and M3 , it is clear to see that M3 is not a linear combination
of M2 or vice versa. This is because no scalar multiple of M2 can equal M3 ,
this is even show by considering M2 s top left entry, a zero, which no multiple
of that can be made to equal 1 in the top left entry of M3 . Hence M2 and M3
are linearly independent.
Also M1 is not a linear combination of M2 and M3 , as by considering there row
sums, the row sum of M2 and M3 is zero, and the row sum of M1 is 3. As it is
true that through addition of two magic matrices to form a new magic matrix,
the total of the row sums of the two magic matrices are equal to the row sum
of the resultant matrix (Proof below). Then any linear combination of any two
matrices, say M2 and M3 , with row sum zero cannot create a matrix of row sum
other than zero. Hence M1 is linear independent from M2 and M3 .
Therefore as the 3 matrices are linearly independent and are all elements of
the vector space of 3 3 magic matrices, it is so that as the vector space has
dimension 3, any set of 3 linear independent 3 3 magic matrices form a basis
to the vector space.
10
Proof that summing two magic matrices also sums their row sum
Define:
a11
A = a21
a31
b11
B = b21
b31
a12
a22
a32
b12
b22
b32
a13
a23
a33
b13
b23
b33
and rB = respectively.
(a13 + b13 )
(a23 + b23 )
(a33 + b33 )
A=
(10)
a31 a32 a33 a34
a41 a42 a43 a44
And so for A to be a 44 magic square, its entries satisfy the following equations:
a11 + a12 + a13 + a14 = r;
(Sum of Rows)
(Sum of Columns)
(Sum of Main Diagonals)
(11)
From these linear equations satisfied by A being defined as a magic square, we
can then show this is equivalent to the linear equations M v = 0,where v is the
11
And M is the
1
1
1
1
r
a11
a12
a13
a14
a21
a22
a23
v=
a24
a31
a32
a33
a34
a41
a42
a43
a44
10 17 matrix:
1
0
0
0
1
0
0
0
1
0
1
0
0
0
0
1
0
0
0
0
1
0
0
0
0
0
1
0
0
0
1
0
0
0
0
0
0
1
0
1
0
1
0
0
1
0
0
0
0
0
0
1
0
0
0
1
0
0
1
0
0
1
0
0
0
0
1
0
0
1
0
1
0
0
0
0
0
1
0
0
0
0
1
0
1
0
0
0
0
0
0
0
1
0
0
1
0
0
0
1
0
0
1
0
0
0
1
0
1
0
0
0
1
0
0
0
0
1
0
0
0
0
0
1
1
0
0
0
0
1
0
0
0
1
0
1
0
0
0
0
0
0
0
1
0
0
1
0
0
0
0
0
1
0
It is clear to see that this system of equations gained from M v = 0 are equivalent to those in (12) however each equation is rearranged slightly.
Then by using Matlabs command rref again, we are able to reduce the matrix
M to its row reduced echelon form.
By inputting the following into the command line of Matlab, we get the output
as follows:
12
Figure 6: Using the rref command to find the row reduced form of M
And hence the row reduced echelon form of M is:
1/2 1/2
1/2 3/2
1/2
1/2
3/2
0 1
0 1
1/2
1/2
1/2
1/2
1
/2
From the row reduced form of M above we can see that the rank of M is equal
to 9, as this is the number of non-zero rows of M in its row reduced echelon
form. As the rank of a matrix is also equal to its column rank, this tells us
that the matrix has 9 linearly independent columns (These are the 8 left most
columns and also the 10th column). These columns are also the pivot columns.
Therefore as our new system of linear equations for 4 4 magic squares, has 17
variables but only 9 pivot columns this means that there are 8 free variables.
As this is so, this means the basic variables, r, a11 , a12 , a13 , a14 , a21 , a22 , a23 ,
a31 , depend on the free variables a24 , a32 , a33 , a34 , a41 , a42 , a43 , and a44 , which
can take any real number. So by choosing values for the free variables this will
then determine the values for the basic variables, which for any choice of the 8
free variables is the only solution to M v = 0
13
Now we want to show that the set of 4 4 magic squares with real entries
form a vector space, showing this is very similar to that of the proof that set
of 3 3 magic squares form a vector space. So we can show the set S4 , the set
of 4 4 magic squares, is a vector space by showing it satisfies the following
properties.
Addition of the magic square matrices satisfies A1, A2 , A3 and
A4. As matrix addition for any two matrices in R44 are associative and
commutative, so A1 and A4 hold.
To show A2 holds, consider the zero element for addition of R44 which
is:
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
It is clear to see this is a magic square as all rows, columns and diagonals
sum to zero, meaning the system of linear equations M v = 0 is satisfied
and hence the zero element of addition is also an element of S4 . So A2
holds.
Finally, for a given element A in S4 , there exists a matrix (A) R44
such that:
a11 a12 a13 a14
a11 a12 a13 a14
0
a21 a22 a23 a24 a21 a22 a23 a24 0
A+(A) =
a31 a32 a33 a34 +a31 a32 a33 a34 = 0
0
a41 a42 a43 a44
a41 a42 a43 a44
By considering (-A), we can see that the sum of rows, columns and leading
diagonals of (-A) are all equal to r, where r is the row sum of (A). Hence
(-A) is also a magic matrix and A3 holds.
For the remaining properties of the vector space:
For any two 4 4 magic squares, u and v , that: (u + v) =
u + v holds for all R.
For any 4 4 magic square, v , that: ( + ) v = v + v holds
for all , R..
For any 4 4 magic square, v , that: () v = ( v) holds for
all , R.
For any 4 4 magic square, v , that: 1 v = v
These can be shown to be true using very similar arguments to those in the 33
magic square case, this is because all the distributive, associative and identity
properties for matrices hold for all elements of S4 , as S4 is a subset of R44 .
And hence this shows that the set of 4 4 magic squares, S4 is a vector space.
With a similar argument for that off the set of 3 3 magic squares, we know
that the dimension of the set of all 4 4 magic squares is equal to the number
of free variables in the system of linear equations which the set must satisfy.
Hence the dimension of the vector space of 4 4 magic squares is 8.
14
0
0
0
0
0
0
0
0
0
0
0
0