First of all, on the quiz. I hope you've done that.
The first and the third vectors are orthogonal and then the three vectors have norms square root of 102, square root of 100 and square root of 101.
So it's the first one that has the largest norm.
I thought I'd begin just for fun with something that has no legitimate connection with this course whatsoever, which is the code called M9.
So let's have some fun with that one. We live in a world where almost anything can be explored easily with or without mathematical content.
So let's see here. M9 is a little MATLAB script that's designed to play with colours.
So if I type m nine colour quiz. What happens is that you see a bar of colour that appears.
Now the default way that MATLAB handles colours is B red, green, blue.
So every colour is a linear combination of an amount of red between zero and one,
an amount of green between zero and one, and an amount of blue between zero and one.
Now, this quiz allows you to choose one of 27 options in an attempt to match that colour.
So you've got to decide, is the red 0.5 or one?
And then is the green 0.5 or one? And is the blue 0.5 or one?
So for example, suppose we conjecture that that colour is red.
Then I could type one red, zero green, zero blue.
And I discover we're wrong because that's red. It's different.
So now I turn it over to you. You tell me, what should I try next?
How much red? Point five, I hear how much green?
Zero. How much blue point five.
Wrong again. Okay. What should I try next? More read.
Okay. So should we try 10.5?
Nope. Well. What's that?
101. Yay!
Okay, you win. So that's good. Let's just do a few more.
There are only 27 possibilities. Pretty soon you'll have them all. Okay, let's try it again.
Oh, that's rather the same, but maybe that's good. What do you think? What was the last one?
Remind me, was it 101101?
So what's this? Do you suppose? How much red?
One. How much? Green Point five. How much?
Blue. Hey, we're getting good.
I'll try a couple more. Okay. What's that? Just for fun.
Let's try a pure blue. So if I said 001, now we're pure blue.
And this is clearly not a pure blue. So what do you think it is?
00.5, I think I hear. Now.
50.51. Hey.
Hey. Well done. Okay, we'll do one more. Some of the most fun colours are orange and yellow, and the trouble is, they rarely appear.
It's interesting how our perception has much sharper gradients in some regions than others.
So among these 27 colours, loosely speaking, most of them seem to be green.
Maybe we'll be lucky and get yellow or orange.
We could, of course, keep going until we get yellow or orange.
Oh, we got yellow. Okay. Who knows what yellow is? One read.
I think I heard one read. How much green? One.
How much blue? Point five. Wow, that was impressive.
I'm very impressed. I couldn't have done that even though I've I wrote this code years ago.
I'll do one more and then we'll say, Oh, that's boring. Let's do a more interesting one. Oh, okay.
That's a good one to start with. How much? Red, green and blue. 111.
I think that's right. Actually, I can do that one in my head. Let's see. One, one.
Yeah, you win. Okay, good. We're done. Thank you for allowing me to do that.
So we're talking about orthogonal ity and least squares.
And let me bring us back to where we were in the last lecture where I rather hastily mentioned these squares.
We talked about orthogonal vectors, which are defined by having an inner product at zero.
If you have a whole set of vectors, they're said to be orthogonal.
If they're pairwise orthogonal, if you have a matrix whose columns are authored normal.
There's no name for such a matrix, even though we use them all the time, unless it's square.
And if you have a square matrix who's orthogonal, whose columns are normal,
then it's called an orthogonal matrix, and then it's equal to the transpose as equal to its inverse.
Now, just to remind you, the framework for least squares problems is usually m by n matrices.
So let a, b, m by n, and let's suppose that M is bigger than N.
In applications, it might be much bigger than N. Now, to remind you a least, squares solution to A x equals B.
Is a vector x that minimises the two norm of the residual.
So it's x such that a x minus be measured in our standard square root of the sum of the squares.
Norm is as small as possible.
I'm not giving you a theoretical course on these squares fitting, but I'm just quickly going over some key points in MATLAB.
We haven't talked about algorithms that will begin to do that yet.
In MATLAB, if you type X equals a backslash B, it somehow computes this x.
And let's remind ourselves of the kind of stuff you can get that way.
I'm going to again run the code m8 from last time.
So we had m8 at least squares. And just to remind you.
What happened with that code is we made a piecewise linear function and then we added some random noise to it,
and then we did exactly this kind of thing to fit the data by least squares.
So in fact, every time I run the code, I'll get different random numbers, but a similar fit.
So there we do it again. There we do it again. Different random numbers, similar coefficients, similar fit.
So this is a very small scale, least squares problem that could have been done in 1949.
Of course, we're way beyond that. Now, one reason for doing this is if you've got your code handy,
the last couple of lines of the code, we're showing off a little bit of MATLAB just for fun.
Suppose you click on the red curve then.
That has the effect of making the red curve into the so-called current object in your MATLAB graphics.
So if I now say set GCA, which is get current object,
I can then do things like say line width 20 and so suddenly I've made the current object have a line width of 20 or I could say colour.
What was yellow again? One. 11.5.
What's that? Okay. I'm not pretending not to know.
By the way, I really don't remember what yellow is. Okay, so good.
Very impressive. Okay, so that's just a reminder that we're talking about least squares.
And I want to continue down that road.
And in particular, the main thing today is to talk about the way that numerical linear algebra people think of least squares,
which is in terms of a QR factorisation traditionally in physics, often, for example, people think of a gram Schmidt Factorisation.
This is a way to regard that more algebraically and to connect it with an algorithm that is more numerically stable.
So I want to talk about Q QR factorisation. 2.3.
And. Q and our stand for matrices. Q is orthogonal and R is triangular.
So just to remind you that when we. Oh, these patterns are annoying, aren't they?
Just to remind you that when we rate Q in this field, really, it almost always signifies a matrix whose columns are thought to normal.
So if we have NW columns, then Q is probably going to look like that.
And typically the length of the columns will be greater than the number of columns.
So a matrix like that is going to be rectangular.
And in such a case, if we look at Q transpose Q, then that will be the end by an matrix of inner product of these things.
So that will be equal to the end by an identity.
So pictorially. Q Transpose. Q Looks like this.
On the other hand, if we look at Q Q transpose, which also makes sense as a matrix,
it's an M by M matrix, and it is not equal to the end by M identity.
So let's see it pictorially. It has the right dimensions.
But of course it can't possibly be the Maiam identity, because if you think about it, it has rank on the end.
So whatever this is, it's a matrix of rank m whereas the M by M identity would have rank m.
So it's a rank and square matrix.
Now anyway. A QR factorisation. Are also known as a reduced QR factorisation.
Oops. Of our matrix a.
Is a factorisation of aa into a product of a q times and are.
And I'll just draw the picture and also the formula.
Of course, we have a matrix A which we think of as consisting of N columns from a one to a n.
A reduced q r factorisation rates that.
As a matrix. Q With all the normal columns.
Times. An upper triangular matrix r with entries going from r11 to our and end.
So that would be R one, one, R2 two and so on.
And it's up for triangular. So this would be R one to r1n0 down there.
So this is a factorisation of matrix. A Into matrix.
Q Times matrix are. And this is the basic way that we formulate things when talking about least squares problems.
It's a change of basis in some sense that I will talk about from various angles.
You start with a basis for an end dimensional space consisting of the end columns of a.
You change that to a basis which is the normal and or normality has computational advantages, and it's also directly tied to least squares.
So here. Of course I've said it. Let me write it down.
The columns of Q are required to be authored normal and are is required to be upper triangular.
So if you have a thing like that,
let me remind you that I've been urging you to think of matrix times vector as a linear combination of the columns of the matrix.
So here we have matrix times this vector and this vector and this vector and this vector.
So the first column on the left. Will be.
Q One times are one one. The second column on the left will be a linear combination of Q1 and Q2 with these coefficients and so on.
So let's write that down. A one is a linear combination of just one vector.
A two is a linear combination of two vectors.
And so on. A three is our one three.
Q One plus are two three.
Q Two plus are three, three.
Q three. So each column on the left is a linear combination of columns on the right, with coefficients coming from one column of the matrix.
So we can see there how it's a change of basis, where we're representing the columns of a in the successive columns of.
Q, which are all the normal. So generically.
If a one through a and are linearly independent.
Then we've simply changed basis and we have that the span of those vectors.
Would be the same as the span of the Q vectors.
And by the span I mean the set of all linear combinations.
So generically, this is an n dimensional space and this is a different basis for it.
If they're rank linearly dependent, then the span of these vectors would be of a lower dimension.
And so it would be properly contained in the span of these vectors.
Okay. So that's a QR factorisation.
Now let's play around with the algebra a little more and then talk about the ways that these things are calculated.
So let's multiply on the left by Q transpose.
So I'm going to multiply that equation on the left by. Q Transpose.
Q Transpose is a wide short matrix.
So what I get is. Q transpose a.
And then. Q Transpose times. Q Is the NBA an identity?
So that goes away. And I just get are.
So cue transpose consist of rose from Q one transpose down to.
Q and transpose. A As always consist of columns from a one to an and then are as always are one one down to are and end up or triangular.
So that's another way to see what's going on here. The entries of ah ah inner products of vectors.
Q with is a. So ah.
I. J. We see from here is the inner product of Q II with a J.
Now another way to work with the algebra is let's suppose.
That we have some X, so it's any end vector.
And let's consider the corresponding B eight times x.
So I could then say that B equals x is a linear combination of the columns of a.
So if we have our QR factorisation so if A equals Q are, then we can use the algebra and write it like this.
I'll say b equals a x.
So that's q are x and we could write that as Q times our x.
And now I could multiply on the left by Q transpose and I would get that Q transpose B.
Is equal to our X. So what I'm doing here is stuff you've all seen, I'm sure, from different angles,
but I'm trying to urge you to think of it in terms of columns, of matrices, that's all.
And this factorisation, when you see a formula like this, I hope you remember to interpret it in terms of vectors, of coefficients,
we know that X is the vector of coefficients of an expansion of B in the basis of columns of A,
and that neurone in your brain sees this, which is Q inverse B That must be a vector of coefficients of B.
In the. Basis of columns of.
Q So to be precise, X itself is coefficient vector for B.
In the basis of columns of a.
And then this thing because it's an inverse of something times a vector is the coefficient vector.
Four be. In the basis.
Q one through. Q in. So this formula shows us how you can convert from the A basis to the Q basis.
And in fact, we could do it fully by inverting one of those matrices.
So I could say that our inverse Q transpose B equals X and so on.
Many ways to slice it. Okay.
When I was a student, I like a lot of us, I learned different things in different subjects with completely different language.
So I saw this stuff in physics courses, talked about one way, then I saw it in mathematics courses, talked about another way.
It took me years to be comfortable with all the connections and to see that everything is really the same in the end.
Okay, now I want to talk about how people compute QR Factorisation.
So there's our QR factorisation let's talk about it's computation.
This is kind of neat from a structural point of view.
So we're given a matrix, a rectangular matrix. And we want to find Q and R.
One way to view that is we're trying to find. Q which is an orthogonal basis.
Another way to view it is we're trying to find our which is the sort of equivalent a triangular matrix.
And it turns out those two ways of looking at it lead to the two great classes of algorithm.
So one of them is called Graham Schmidt and the other is called Householder.
So let me write the heading for Graham Schmidt. The way I think of Graham Schmidt.
Which is a pre-computer idea. Well, there's another word.
Graham Schmitt, orthogonal ization. The word or thought.
Canonisation says what it's all about. It's an algorithm in which we orthogonal ize the columns of a.
And the way I like to think of it is it's a process of triangular or orthogonal ization.
By which I mean. As you'll see, it's making a orthogonal by a sequence of triangular operations.
And let me skip ahead, leaving some blank space here to the other one, which is householder.
So householder triangular is Asian.
Is the dual of this idea. And this is a post computer idea.
This is a process of orthogonal triangular ization.
Big words. Takes a while to write them. Now those words are nearly enough for you to figure out, given enough time what's going on.
You know, your goal is to take a and convert it into. Q Times are.
I'm in effect telling you there are two natural ways to do that. You can either try to make the columns of or orthogonal write it down.
You'll get Graham Smith or you can try to make a upper triangular using orthogonal operations.
Write that down. You'll get householder. Let me say a little more.
So the Graham Schmidt idea. Viewed from an algebraic point of view consist of taking your matrix A and multiplying it on the right by a sequence.
Of triangular matrices. I haven't really told you what we're doing at an operational level,
but algebraically Gram Schmidt consists of taking your matrix and doing things to it until it becomes.
Orthogonal until the columns become all the normal. Now, what does that really mean?
When you multiply a matrix on the right by something.
You're taking linear combinations of columns. And the grand Schmidt idea is to construct the first column of Q.
By normalising the first column of a construct.
The second column of Q as a linear combination of the first two columns of the third
column of Q is a linear combination of the first three columns of A and so on.
So it's doing a succession of operations on columns of A to make them orthogonal.
I'm not going to write down the formulas, partly because most of us have seen them in one context or another.
It's essentially these formulas. You use these formulas one by one to construct the entries of R, such that the columns have become orthogonal.
You go through these operations acting on column one, one and two, one, two, three.
All the way up to an operational acting on all the columns and.
This then. Is a product of upper triangular matrices, which we can call its trying upper triangular itself because it's a product of them.
If we call it a if we call that our inverse, then algebraically speaking we found a equals Q are.
Okay. So many of you know Graham Schmidt, I'm sure some of you don't.
But any way you can, if you're curious about the details,
look it up and then have some fun interpreting what you find as multiplications of a matrix on the right by elementary matrices.
The one I want to emphasise more is the householder approach. Which is less obvious, but in fact is the standard approach for moderate sized matrices.
If you type Q are in MATLAB, it's this method that's used.
If you do least squares in MATLAB, it's this method that's used.
It's the best way to deal accurately with matrices that are not so big as to cause sparsity challenges.
So I want to talk about householder. And before I do that, let's look at the paper, which is one of the handouts.
So this is a greatest hit of numerical analysis. It's from 1958.
Unitary triangular ization of a non symmetric matrix.
By Austin Householder, which was one of the great figures of numerical linear algebra after the war.
A real character. Smart guy. Whisky drinker.
Good man. He died some years ago, but he had a huge influence on generations of people.
I love this paper. It's so readable and it's so short.
It's essentially three pages long. And it really did change the world.
Nobody had noticed, to first approximation.
This duality the whole world had been thinking in terms of orthogonal ising things.
Householder noticed that you could equally well triangular five things and moreover that it was numerically more stable.
So the rounding error is causing more trouble with this method than with this method.
Quite a remarkable observation. The the previous thing that had come along is called Given's rotations, which has a bit of the same flavour.
But Householder did it in the really the ultimate way, I think.
So we're going to say a bit about what he does and maybe left next lecture, but not right now.
What he does do formally. Is take a matrix a.
And instead of acting on its columns, which would be multiplying by stuff on the right,
he acts on its rows, which means multiplying by stuff on the left.
So the picture is. House holder starts from a matrix, which we imagine being a dense matrix, rectangular.
And he wants to make it up a triangular.
And what he does is, first of all, multiply it on the left by something that turns it into this structure 0000.
So in the first column, the zeros are introduced.
So that step consists of multiplying out, playing it on the left by an orthogonal matrix.
Q one. Then at the next step, zeros are introduced in the second column below the diagonal.
So that would be the multiplication on the left by another.
Orthogonal matrix.
So by a sequence of orthogonal operations, household triangular ization takes the dense matrix and turns it into a upper triangular matrix.
So finally for this one, we have a third multiplication and now it would be upper triangular.
So we're done. We've done it end times. And now we have an upper triangular matrix called our.
And if. Same thing as before. If we call that Q inverse or Q transpose.
Then we've got a equals Q are.
When I was your age and studying numerical analysis, I was told that this was simply better than not more accurate, less subject to rounding errors.
The truth is a little more subtle than that. There are in many basic applications.
That's true, and it certainly gives you more nearly orthogonal matrices.
Q However, it turns out that orthogonal ity sometimes matters, and another time it doesn't matter.
So it's not always true that the accuracy makes a difference.
And there is an advantage to this approach, which is that it generalises more readily to sparse problems.
So often you'll find that if your matrix is 1000 by a thousand, you're doing this.
If it's a billion by a million, you may find yourself closer to there.
Lots of possibilities. I want to play around with this stuff and see what happens.
So let's go to the code called M10. So this is just illustrating QR factorisation.
So I'll say a. Equals a random.
Sorry, a zero. Matrix of dimension seven by three.
There we are. And now I'm going to put some numbers into the matrix.
So I'll say a of colon, a notation we haven't used before.
But you can see what it does will be 1 to 21 squared.
So that takes the vector 1 to 21 squared and puts it into the A without changing the shape in the usual order that we've talked about several times.
So there we have an arbitrary matrix. Let's now say Q are equals.
Q are of a comma zero, which is not labs notation for the reduced q r factorisation.
If we do, that will get a Q in and on. So what you see here is that.
Q You can't tell there are the normal vector column vectors, but they are as obviously upper triangular.
You can immediately see, by the way, why. This way of thinking is kind of a post computer way of thinking.
Anything to do with author normality is not something you're going to write down on paper.
There are square roots all over the place. These are numbers easy to compute and hard to work with on paper.
So orthogonal linear algebra is really a post computer technology.
But anyway, a is equal to QR and I could do all sorts of things.
I could say a minus QR, for example. Mathematically, that should be the zero matrix.
Of course, with rounding errors it won't be exactly zero.
There it is. That's actually bigger than you might think.
But the reason is that a itself is pretty big because it had entries in the hundreds.
So ten to the minus 12th relative to the scale of a is fine.
Here's a again if we look at the norm of the first column of a.
Square root of the sum of the squares of those numbers. There it is. Let me remind you, there's the matrix.
Ah, so because Q is an author normalised version of A.
The first column of Q is a normalisation of the first column of A, therefore the scalar has to come out there.
So that's why 68 equals 68. Similarly, if you look at the norm of the second column of a.
And compare it with the norm of the second column of Ah.
You find they're the same because we're taking all the directions away and putting them into Q and all the magnitudes of A and putting them into our.
Now cue is orthogonal. It's a seven by three matrix with the normal column.
So if I take Q transpose times Q.
You get the three by three identity.
If I take Q times Q transpose, then that would be a seven by seven matrix, which can't possibly be the identity because it only has rank three.
And indeed, if I say rank of ants. It's three.
I guess the final thing in this demo is to get through a big one to see how nice it is to live in the 21st century.
So suppose I say a equals round n of 1e41e3.
So there we have a random matrix with 10,000 rows and 1000 columns.
Pretty big. And let's do a QR factorisation.
I'll say q r equals q r of a comma zero.
Talk. So on this laptop, it takes something like 4 seconds.
But of course, we're dealing with 10 million entries. And in fact, it's it's an N cubed operation.
So the amount of work scales as 10,000 times 1000 squared.
So we're doing a lot of computing. Let's see how accurate it was.
So suppose I say what's the maximum entry of the absolute value of Q?
Transpose Q. Minus the identity of size 1e3.
Okay, so we've just made a CU matrix that's 10,000 by 1000, and its columns are supposed to be all the normal.
Are they really are the normal? Pretty good, right?
If we had done it with Graham Schmidt, they would be not even close to the normal.
But householder achieves this even with these incredible matrices.
It's interesting to think historically about that.
So this theory was developed by Householder and Wilkinson and others in an era when even 100 by 100 was too big for most experiments.
Those guys would have been playing around with matrices of size 20 or 30.
And that's the power of theory, right? They proved theorems about stability, which showed that the method really works.
And here we are 50 years later, doing it on matrices a thousand times bigger.
Just amazing. Okay.
So I want to get back to least squares problems. Okay.
We? Okay.
We already have mentioned them a bit. I want to now connect them with QR factorisation.
So this is called section 2.5. Linear at least squares.
There are, of course, also nonlinear squares problems, which will say a little bit about in a couple of weeks.
The history here is wonderful. This was discovered by Gauss and by legendary independently.
And boy, they had a big fight. So I think Gauss maybe did it first, but typically didn't publish this in the 1790s.
And when they found out about each other, they were furious. Gauss was not a very nice man, but he was pretty bright.
There's a great book. Sort of the standard numerical book about this stuff.
Of course, these squares is everywhere, it's in statistics, everywhere and so on.
But from a numerical linear algebra point of view, the standard book is by Bjork, who is not a rock star except in the mathematical sense.
So just to remind you, we're always dealing here with rectangular matrices.
So A is my N and M is bigger than N.
And we're looking for solutions such that a X minus B in the tune arm is minimal.
And the picture I drew last lecture. Let me draw it again. Lies in the space.
R m. And the picture I like to draw consists of a subspace of RAM, which is the range of a.
Also known as the column space of a.
And whenever we do these squares, we're trying to find a vector in the range of a that's as close as possible to be.
So we think of B as being a vector out here somewhere. And we're trying to find.
That point there, that's not X, that's acts.
So that's the point in the range of A as close as possible to be.
It's obvious intuitively, at least, that there is an unique such point.
There's not necessarily a unique X, but there's a unique X.
And our job is to find it in the way we find it mathematically is to exploit this orthogonal property.
The least squares norm has the property that the residual which is this vector is characterised
by being orthogonal to the range of a and I mentioned all of this at the end of.
Last lecture. So that orthogonal is a condition. The range of AA must be orthogonal to the residual.
So that leads us to the condition we identified at the end of the last lecture, which is that A transpose B minus X should be the zero vector.
This is the residual and it must be orthogonal to each column of a, which is enough to make it orthogonal to the range of a.
So these are the normal equations a transpose a x equals a transpose b.
So as a rule, you shouldn't use this method as long as your matrices are small enough to to do dense
linear algebra with don't solve any squares problem by solving the system of equations.
The reason is that a transpose sort of squares the il conditioning of the problem.
So it'll you'll get a less accurate answer.
On the other hand, for very large problems with sparsity issues, often this is the best way to go because it maintains sparsity.
And to a certain degree. Let me mention a theorem about this stuff, which is that if the rank of A is N, so A has full rank, that's equivalent.
To transpose a being symmetric positive definite a transpose.
They will always be symmetric and it will always be a semi definite.
So its eigenvalues can never be negative, but they might be zero.
However, if rank of A is equal to N rather than less than n, then all the eigenvalues are positive, which means it's non singular.
So a transpose is non singular if and only if rank of his end.
Which means that the solution vector x is unique.
So X is always unique and the picture sort of makes that obvious, but the vector x corresponding to that is unique if and only if A has full rank.
So there are three ways we can easily talk about computing X.
We've just in effect shown one of them we could solve the normal equation.
It's a symmetric, positive, definite system. Normally we could solve that system and find x, but let's do it the other way.
Let's do it via q our factorisation. So how do we solve?
Least squares via QR. Well, the idea is if we have a North a normal basis for the range of AA, then the problem should be an easy one.
We won't have to invert anything. We're going to have to take some inner product.
That's what the QR Factorisation gives us and we're a little short on time, so I'm going to write it down rather quickly.
We're trying to project be orthogonal into that range space.
Let's write down an equation for that. So a X is the orthogonal projection.
Of B on to. Range of.
That means. That acts.
I'll write it down and then explain why it's right. It can be written as Q.
Q transpose. B. Now, why is that? Well, this is going to give me expansion coefficients.
I'm speaking fast and loose here, I'm afraid.
And then this is going to take those expansion coefficients and multiply them by the appropriate vectors.
So I'm afraid I am speaking quickly here. But it's a projection process where you take me and you take in our products in order to find coefficients,
and then those use those coefficients in the appropriate basis.
Now, if you multiply on the left by Q transpose. Then you get.
May make sure I've got this right. I want to assume that a is QR so we let's see, we have QR.
X equals Q Q transpose B multiplied by Q transpose.
So we get our x equals Q transpose B,
and that's the key equation that we can solve to do at least squares problem by the Q our factorisation so I'm sorry
this is going to quickly the idea is you take a you factor it into Q times R and then you solve this equation,
you multiply Q transpose by B to get your coefficients, as it were, in that basis.
And then you solve this equation to translate back to the original a basis.
So that's the algorithm. Let's do it.
And the final demo here is the one called M11.
So if I say following the script here, I'm going to say t equals two pi times a vector of length of thousand.
So this is now a set of points scattered between zero and two pi, a thousand points,
and I'll say B equals T over five plus and then use a T over five.
And then using a logical operation, I'll say.
T less than pi, so that vector will be zero when t is bigger than pi and one when t is less than pi.
So if I plotted. I've just constructed that.
Vector. This is a vector of length. 1000 plotted by straight lines.
Now let's make a matrix which has five columns that are trigonometric functions.
So say A is equal to the thousand by five matrix cosine of zero t sign of t cosine of t sign of two.
T cosine of two. Thousand by five matrix.
And now let's solve the least squares problem in three different ways.
So one way. Is to just use backslash so I could say x1 equals a backslash.
B this is doing whatever matlab does, which is in fact the q r factorisation and we could plot the result.
I can plot a times x one as a red line and there you see the least squares fit.
On the other hand, we could explicitly use the QR factorisation and do it ourself rather than relying on MATLAB backslash.
So let's do that. I could say Q comma R equals Q are of a zero.
And then I could say x2 equals R backslash q transpose b.
Now that's a hazardous way to write it, because who knows whether the backslash was done before the vector.
This is a better way to write it.
So here, that operation means first we multiply B by Q transpose, and then we solve the problem r x equals that vector.
So if I do that, I have another version of X. This was the first one we computed.
This is the second one we computed. They're pretty much the same x one minus x two.
There they are. They're not identical notice.
So obviously MATLAB did something slightly different from what we did.
Finally, let's do the normal equations and I don't want to tell you these are bad merely that they're different.
I could solve the problem by a transpose a.
Backslash A transpose B and this is mathematically different.
This is not what backslash is doing. It's really a different algorithm that advantageous, sometimes disadvantageous other times.
If I look at the error here, I see that in this case it's fine.
Nothing went wrong in this case. Okay.
I think that's it for today. Thanks.