Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

linear least sqaures minimization coding needed urgently

Status
Not open for further replies.

tiziana

Computer
Joined
Apr 15, 2004
Messages
1
Location
MT
Hi all!
I need to find the parameters a, b and c by solving the following linear least-squares parameter minimisation problem:
sum[i=1,1=n{a*X_i + b*Y_i + c - Z_i}^2]

where vectors X, Y and Z are known.

Any idea on how to implement in Matlab. Please I really need help cos it is a small part of my ptoject but it has got me stuck

thanks
 
The backslash operator "\" automatically performs a least squares regression for over-determined systems of equations

Try this
Code:
% assumes X Y and Z are column vectors
% rewrite the equation as a*X + b*Y + c*1 = Z
% now write in matrix form Ax = f
[rows, dummy] = size(X); %number of elements in the vector 
A = [X Y ones(rows,1)];
f = Z;
x = A\f; % do the least squares
a = x(1)
b = x(2)
c = x(3)



--
Dr Michael F Platten
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top