How Can MATLAB Solve Least Squares for Predicting Comet Distances?

zenith92
Messages
9
Reaction score
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
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:
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
 
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:
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)
 
Well, I'm baffled then. Maybe others in this forum can see something I'm missing.
 
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?
 
Anyone?
 
Back
Top