Matlab - Normal equation for linear least squares model fitting

  • Thread starter jmher0403
  • Start date
  • #1
22
0

Homework Statement



Im trying to construct a function in matlab that models linear least squares model fitting through the use of normal equations.



Homework Equations



Normal equation

(A'*A*c)=(A'*y)

A= [column vector of all x ; column vector of all 1]
y= [column vector of all y]
c = [b;a] where a&b are coefficients of the best fit line

The Attempt at a Solution




function c=mregress(x,y)
A=[x 1]
B=[y]

c=(A'*A)\(A'*B);

Error in ==> mregress at 2
A=[x 1]


I am very new to matlab and dont know much about it.
I think the problem is representing x a column vector and 1 is also a column vector of 1.

How do I represent this?
 

Answers and Replies

  • #2
312
0
A=[x,ones(n,1)] where n is the number of elements in x.
 

Related Threads on Matlab - Normal equation for linear least squares model fitting

  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
12
Views
2K
Replies
3
Views
1K
  • Last Post
Replies
10
Views
2K
  • Last Post
Replies
7
Views
6K
  • Last Post
Replies
0
Views
2K
Replies
2
Views
3K
  • Last Post
Replies
2
Views
1K
  • Last Post
Replies
3
Views
995
Replies
0
Views
2K
Top