Guest User

Untitled

a guest
Feb 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. function [ y_out ] = laff_axpy( alpha, x, y )
  2.  
  3. % y = copy( x, y ) copies vector x into vector y
  4. % Vectors x and y can be a mixture of column and/or row vector. In other
  5. % words, x and y can be n x 1 or 1 x n arrays. However, one size must
  6. % equal 1 and the other size equal n.
  7. %
  8. % The reason y is an input parameter is that the input y indicates
  9. % whether the output, y_out, is a column or row vector, and then also
  10. % indicates whether x must be transposed (e.g., if x is a row vector and
  11. % y is a column vector).
  12.  
  13. % Extract the row and column sizes of x and y
  14. [ m_x, n_x ] = size( x );
  15. [ m_y, n_y ] = size( y );
  16.  
  17. % Make sure x and y are (row or column) vectors of equal length
  18. if ( m_x ~= 1 & n_x ~= 1 ) | ( m_y ~= 1 & n_y ~= 1 )
  19. y_out = 'FAILED';
  20. return
  21. end
  22. if ( m_x * n_x ~= m_y * n_y )
  23. y_out = 'FAILED';
  24. return
  25. end
  26. if ~isscalar( alpha )
  27. y_out = 'FAILED';
  28. return
  29. end
  30.  
  31. if ( n_x == 1 ) % x is a column vector
  32. if ( n_y == 1 ) % y is a column vector
  33. % Copy the elements of x into the elements of y
  34. for i=1:m_x
  35. y( i,1 ) = alpha * x( i,1 ) + y( i,1 );
  36. end
  37. else % y is a row vector
  38. % Copy the elements of x into the elements of y
  39. for i=1:m_x
  40. y( 1,i ) = alpha * x( i,1 ) + y( 1,i );
  41. end
  42. end
  43. else % x is a row vector
  44. if ( n_y == 1 ) % y is a column vector
  45. % Copy the elements of x into the elements of y
  46. for i=1:n_x
  47. y( i,1 ) = alpha * x( 1,i ) + y( i,1 );
  48. end
  49. else % y is a row vector
  50. % Copy the elements of x into the elements of y
  51. for i=1:n_x
  52. y( 1,i ) = alpha * x( 1,i ) + y( 1,i );
  53. end
  54. end
  55. end
  56.  
  57. % Return the updated y in y_out
  58. y_out = y;
  59.  
  60. return
  61. end
Add Comment
Please, Sign In to add comment