Two small questions about using matrices for finding best straight line by linear regression

Martincg

New member
Joined
Jul 4, 2023
Messages
4
In examples I have seen so far which show how to find a line which best fits a set of points, the equations are set out in a matrix form and so I am learning about matrices.
To simplify suppose we have thre points then the eqautions are
x1*m +c = y1
x2*m +c = y2
x3*m + c = y3
(m is the slope, c the offset)
in matrix form we can have (I don't know how to draw a matrix here)


matrix.png

so say this is
X M = Y
Then to remove the X on the left side we need to multiply X by the inverse of X, and to do that we need X to be a square matrix. If X is n x 2 then we can multiply by a matrix D say which is 2 x n to give n x n.
In the examples I have seen D is chosen to be the transpose of X.

Question 1
Why use the transpose of X? couldn't we use any matrix within reason which is 2 x n?

Question 2
How does the whole think work anyhow considering that the measured points will not be exactly on the straight line so really we should write
x1*m +c = y1 + e1
x2*m +c = y2 + e2
x3*m + c = y3 + e3
where e is the error in y.
Is the assumption that if the errors were included in the calculation then they would average out to zero?

The same questions relate to finding the best circle for a set of measured points.
 
Last edited:
Oh. It's not my formula but one I've found in a few links to finding the best straight line and circle. Where I found these methods they were called linear regressison. Whatever it is called the technique seems to find a good fit. What should it be called?
I don't know what you mean by minimizing e1 squared etc . The x,y values are measured data and the errors are unknown.
If I've called the method the wrong name I don't see that it means my questions about the application of the method aren't reasonable and so I think it could be expected that I get an answer which helps me.
 
Oh. It's not my formula but one I've found in a few links to finding the best straight line and circle. Where I found these methods they were called linear regressison.
It would be very helpful if you showed us at least one of these links, so we could have a better idea where you are coming from. We might also be able to suggest a better source, if the source you used is lacking something.

The phrase "your formula" doesn't imply you invented it, just that it is the one you are asking about!
 
I doubt there will be many enthusiasts to watch a 25 minute video to figure out where your problem comes from. Plus, the video is about circle fitting, which is a completely different and more complicated then fitting a straight line. Have you looked at the link I posted earlier ?
 
The first part of the video is about fitting a straight line. It then progresses to fitting a circle. I need to do both.
True, asking someone to watch that video is a bit silly. I watched it because I wanted to find a method I could use which was better than I could invent.
I did follow the link you gave so thank you for that. However, since I have only been learning about matrices since I watched that video a couple of weeks ago, the explanation you pointed to was beyond my understanding at the moment.
For now, because I need to get something achieved in a short time and I have a lot of other things to deal with, I am going to use the approach to get the results I need and accept that I don't fully understand it, but I can write a program to use the method. Every curve or line can be limited to a restricted range of points so that the distance of each point from the line is within some tolerance and the worst is that I will end up with more line segments than I might prefer, but hopefully a lot fewer than drawing straight lines between each point. My only aim is to reduce a set of meaured points, which form an outline of a 2D shape, to as few straight lines and arcs as possible for a given tolerance.
 
Top