Home > utilities > svec2.m

# svec2

## PURPOSE

## SYNOPSIS

function [evec, idiag] = svec2(emat)

## DESCRIPTION

     [evec, idiag] = svec2(emat)
     vectorization of a (generally full) symmetric matrix;
     upper triangle is vectorized row-wise
     INPUT: evac...symmetric matrix
     OUPUT: evec...upper triangle of emat stored row-wise in a vector
            idiag...vector oex72f indices of diagonal entries of emat in evec

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

## SOURCE CODE

    0001 function [evec, idiag] = svec2(emat)
    0002 %
    0003 % [evec, idiag] = svec2(emat)
    0004 % vectorization of a (generally full) symmetric matrix;
    0005 % upper triangle is vectorized row-wise
    0006 % INPUT: evac...symmetric matrix
    0007 % OUPUT: evec...upper triangle of emat stored row-wise in a vector
    0008 %        idiag...vector oex72f indices of diagonal entries of emat in evec
    0009
    0010 % This file is a part of PENLAB package distributed under GPLv3 license
    0011 % Copyright (c) 2013 by  J. Fiala, M. Kocvara, M. Stingl
    0012 % Last Modified: 27 Nov 2013
    0013
    0014 m = size(emat,2);
    0015 idiag(1) = 1;
    0016 k = m;
    0017
    0018 evec = zeros(m*(m+1)/2,1);
    0019 evec(1:m) = emat(1:m,1);
    0020 for j=2:m
    0021     i = idiag(j-1) + k;
    0022     idiag(j) = i;
    0023     k = k-1;
    0024     evec(i:i+k-1) = emat(j:m,j);
    0025 end
    0026
    0027 end