Linear Least Squares: Solving 3D Data Points in C++

Lindley
Messages
6
Reaction score
0
I have a simple problem. I have a set of 3D data points and I want to fit a line through them using linear least squares. I understand the basic approach required: set up two matrices such that Ax = b, then make it a square matrix A^t*Ax = A^t*b, then solve for x using a Cholesky decomposition. (I'm working in C++ using the Eigen 2.0 matrix library.)

The problem is that I'm not sure how to set up A and b to begin with. This would be simple if the data points were in 2D: b would be a column vector of all the ys, and A would be an Nx2 matrix with [x, 1] on each row. Then the unknowns would be x = [m, b] for the normal y = mx+b line.

But with 3D points, it's less clear to me how I have to arrange things.

Also, any suggestions for how to make the operation more numerically stable (such as subtracting off the mean from each data point, I know that one at least) would be welcome.
 
Physics news on Phys.org
It depends on what type of line you have such as can it be curved or is it only straight. If it is straight or you are trying to fit a straight line to the data then the following way could be possible, but only if the data points can be numbered from 1 to n. If you can do this then you can split your data into 3 groups of parametric equations of (t,x), (t,y), (t,z) which are all 2D and you can figure it out from there. After you get all three you would have the parametric function <x(t),y(t),z(t)>.
 
I only need straight lines.

The parametric approach makes sense, thanks, I'll give that a try!
 
##\textbf{Exercise 10}:## I came across the following solution online: Questions: 1. When the author states in "that ring (not sure if he is referring to ##R## or ##R/\mathfrak{p}##, but I am guessing the later) ##x_n x_{n+1}=0## for all odd $n$ and ##x_{n+1}## is invertible, so that ##x_n=0##" 2. How does ##x_nx_{n+1}=0## implies that ##x_{n+1}## is invertible and ##x_n=0##. I mean if the quotient ring ##R/\mathfrak{p}## is an integral domain, and ##x_{n+1}## is invertible then...
The following are taken from the two sources, 1) from this online page and the book An Introduction to Module Theory by: Ibrahim Assem, Flavio U. Coelho. In the Abelian Categories chapter in the module theory text on page 157, right after presenting IV.2.21 Definition, the authors states "Image and coimage may or may not exist, but if they do, then they are unique up to isomorphism (because so are kernels and cokernels). Also in the reference url page above, the authors present two...
I asked online questions about Proposition 2.1.1: The answer I got is the following: I have some questions about the answer I got. When the person answering says: ##1.## Is the map ##\mathfrak{q}\mapsto \mathfrak{q} A _\mathfrak{p}## from ##A\setminus \mathfrak{p}\to A_\mathfrak{p}##? But I don't understand what the author meant for the rest of the sentence in mathematical notation: ##2.## In the next statement where the author says: How is ##A\to...
Back
Top