Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • 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
Apr 15, 2004
1
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
 
Replies continue below

Recommended for you

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