How Can MATLAB Solve Least Squares for Predicting Comet Distances?

In summary, given a matrix A and a vector b, with specific values, the distance between b and the column space of A can be determined using the MATLAB function lsqr(A,b). The resulting solution provides the necessary values to compute the distance, which can be rounded up to 4 decimals.
  • #1
zenith92
10
0

Homework Statement



The distance traveled by a comet is described with the following equation:

r = B + re cos (θ)

B (Beta) and e are constants

θ 0.88 1.10 1.42 1.77 2.14 2.91 3.85
r 8.27 5.49 3.53 2.50 1.95 1.52 5.21

These were some of the measurements, which can be written in the form Ax = b.

Task 1: design an m-file for the matrix A and the vector b with unknown vector
x = [ B
e]

Task 2: calculate the least squares x in Ax = b in MATLAB (use A\b or lsqr(A,b)

Task 3: determine the r if θ = 4.60 (approx. in 4 decimal)


Homework Equations



look up

The Attempt at a Solution



so I made the m-file with:

A = [0.88 1.10 1.42 1.77 2.14 2.91 3.85; 8.27 5.49 3.53 2.50 1.95 1.52 5.21]'
b = [8.27 5.49 3.53 2.50 1.95 1.52 5.21]'
Did lsqr(A,b) and got

lsqr converged at iteration 2 to a solution with relative residual 2.1e-015

ans =

-0.0000
1.0000

did the A \ b thing and got ans =

0.0000
1.0000

So my question is what would the r be that they're asking for me, i'd say close to 1.90?

but i don't know if the m-file is correct, you guys have an idea? Thanks!
 
Physics news on Phys.org
  • #2
Welcome to PF!

Pls explain how you got the matrix A. Looks like the first column is θ and the second column is r. If so, it isn't right. Also, looking at your equation:

r = B + re cos (θ)

The dependent variable r also shows up on the right side. Is this correct?
 
Last edited:
  • #3
The equation is correct, I know it's a little weird

And the A matrix is also correct right? The θ is the first column and the r is the second, or wait why is that wrong? The 'table' is exactly like I wrote in my first post except I made it into columns in MATLAB to calculate the least squares or is that not needed? Because if I let it the way it is I won't get an answer in MATLAB
 
  • #4
Hmmm, some things really seem out of whack here:

1. If the equation truly is r = B + re cos (θ) it means r = B / (1 - e cos (θ)) which is non-linear in e

2. The equation fits the data very poorly, unless the last data point (3.85, 5.21) is a typo. If the value for r is more like 1.21 instead of 5.21 the fit is reasonable. You might want to double check the data values.

3. As far as I can tell, the Matlab function lsqr is for linear least squares, which won't solve your non-linear problem.

4. It appears you've been given no instruction on how to formulate / solve least squares problems. What's the purpose of the exercise?
 
Last edited:
  • #5
I had to translate the original exercise and left out some details that i thought wasn't relevant. But the equation is correct.

The lsqr was given as solution for the least squares problem in the exercise. The values are different for each student. The the last r value is supposed to be 1.71 + 0.5 x (times) a where a is a number specific to each student. I think I'll just guess the r to be somewhere near 1.90, thank you for the support though, very appreciated :)

(unless you got something else by now haha)
 
  • #6
Well, I'm baffled then. Maybe others in this forum can see something I'm missing.
 
  • #7
I have another exercise here...

PROBLEM

Given are the matrix A (7rows times 3columns):

A = [0,-0.7,-0.1,-0.7,0,0.7,0.1; 0.7,0,-0.7,-0.1,-0.7,0,0.7; 0.1,0.7,0,-0.7,-0.1,-0.7,0]';

And a vector b: b = zeros(7,1); b(7) = 1.7;

Determine with MATLAB what the distance is between b and the column space Col A. Round the distance up to 4 decimals.

SOLUTION

I entered the matrix and vector and then used lsqr(A,b) and got the following solutions:

lsqr(A,b)
lsqr converged at iteration 3 to a solution with relative residual 0.86

ans =

-0.0009
0.6134
-0.0867

With these I then computed that the distance should be 0.6195. Now, I'm not sure if this is correct since I didn't read the whole chapter yet, only bits here and there since I still need to read a chapter before it. But can someone confirm if this is correct and if not what would the correct answer be?
 
  • #8
Anyone?
 

Related to How Can MATLAB Solve Least Squares for Predicting Comet Distances?

1. What is Least Squares with MATLAB?

Least Squares with MATLAB is a statistical method used to find the best fitting line or curve through a set of data points. It minimizes the sum of the squared errors between the actual data points and the predicted values by the model.

2. How does Least Squares with MATLAB work?

In this method, MATLAB calculates the slope and y-intercept of the line of best fit by minimizing the sum of the squared errors between the data points and the predicted values. This is done through an iterative process until the smallest error is achieved.

3. What are the advantages of using Least Squares with MATLAB?

Using Least Squares with MATLAB allows for a quick and efficient way to find the best fitting line or curve through a set of data points. It also provides a measure of how well the model fits the data, and can be used to make predictions for new data points.

4. Can Least Squares with MATLAB be used for non-linear data?

Yes, Least Squares with MATLAB can be used for non-linear data. It allows for the fitting of polynomial, exponential, and other non-linear models to the data.

5. Are there any limitations to using Least Squares with MATLAB?

While Least Squares with MATLAB is a powerful tool for finding the best fitting line or curve through a set of data points, it does have some limitations. It assumes that the data follows a linear or non-linear trend, and may not be suitable for data with complex patterns or outliers.

Back
Top