Code covered by the BSD License  

Highlights from
Numerical Methods Using MATLAB, 4e

image thumbnail

Numerical Methods Using MATLAB, 4e

by

 

23 Dec 2003 (Updated )

Companion software to accompany the book "Numerical Methods Using MATLAB"

[A,B]=lsline(X,Y)
function [A,B]=lsline(X,Y)

%Input    - X is the 1xn abscissa vector
%            - Y is the 1xn ordinate vector
%Output - A is the coeefficient of x in Ax + B
%            - B is the constant coefficient in Ax + B

%  NUMERICAL METHODS: Matlab Programs
% (c) 2004 by John H. Mathews and Kurtis D. Fink
%  Complementary Software to accompany the textbook:
%  NUMERICAL METHODS: Using Matlab, Fourth Edition
%  ISBN: 0-13-065248-2
%  Prentice-Hall Pub. Inc.
%  One Lake Street
%  Upper Saddle River, NJ 07458

xmean=mean(X);
ymean=mean(Y);
sumx2=(X-xmean)*(X-xmean)';
sumxy=(Y-ymean)*(X-xmean)';
A=sumxy/sumx2;
B=ymean-A*xmean;

Contact us