function y = saxpy ( n, sa, x, incx, y, incy ) %% SAXPY adds a constant times one vector to another. % % Modified: % % 05 May 2006 % % Author: % % MATLAB translation by John Burkardt % % Reference: % % Jack Dongarra, Cleve Moler, Jim Bunch and Pete Stewart, % LINPACK User's Guide, % SIAM, (Society for Industrial and Applied Mathematics), % 3600 University City Science Center, % Philadelphia, PA, 19104-2688. % ISBN 0-89871-172-X % % Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh, % Basic Linear Algebra Subprograms for Fortran Usage, % Algorithm 539, % ACM Transactions on Mathematical Software, % Volume 5, Number 3, September 1979, pages 308-323. % % Parameters: % % Input, integer N, the number of entries in the vector. % % Input, real SA, the multiplier. % % Input, real X(*), the vector to be scaled and added to Y. % % Input, integer INCX, the increment between successive entries of X. % % Input/output, real Y(*), the vector to which a % multiple of X is to be added. % % Input, integer INCY, the increment between successive entries of Y. % if ( n <= 0 ) y = []; elseif ( sa == 0.0 ) elseif ( incx == 1 & incy == 1 ) y(1:n) = y(1:n) + sa * x(1:n); else if ( 0 <= incx ) ix = 1; else ix = ( - n + 1 ) * incx + 1; end if ( 0 <= incy ) iy = 1; else iy = ( - n + 1 ) * incy + 1; end for i = 1 : n y(iy) = y(iy) + sa * x(ix); ix = ix + incx; iy = iy + incy; end end