set_diagonal [MTL Home] Programmers Guide
  Contents | Index |  Search 


Category:algorithms Component type:function
Prototype
template <class Matrix, class T>
void set_diagonal(Matrix& A, const T& alpha) ;
Description
Set the value of the elements on the main diagonal of A to alpha.
Definition
mtl.h
Requirements on types
  • T must be convertible to Matrix::value_type.
Preconditions
Complexity
O(min(m,n)) for dense matrices, O(nnz) for sparse matrices (except envelope, which is O(m))
Example
In tri_pack_sol.cc:
  const int N = 4;
  Matrix A(N, N);

  set_diagonal(A, 1);

  //C         1.0                         8.0
  //C     A = 2.0  1.0              b =  25.0
  //C         3.0  5.0  1.0              79.0
  //C         4.0  6.0  7.0  1.0        167.0

  A(1,0) = 2; A(2,1) = 5; A(3,2) = 7;
  A(2,0) = 3; A(3,1) = 6;
  A(3,0) = 4;

Notes
See also

[MTL Home] Copyright © 1998,1999 University of Notre Dame. All Rights Reserved.