Example #1
0
def calculate_ground_state_wf(d, e, saved_lanczos_vectors):
    """Calculates the ground state wavefunction.
    
    Parameters
    ----------
    d : a numpy array with ndim = 1.
        The elements of the diagonal of the tridiagonal matrix. The size
	of `d`.
    e : a numpy array with ndim = 1.
        The off-diagonal elements of the tridiagonal matrix. The size of
	`e` equals the size of `d`, and it is padded with a zero at the
	end. 
    saved_lanczos_vectors : a list of Wavefunctions.
        The Lanczos vectors that are saved.

    Returns
    -------
    result : a Wavefunction.
        The ground state function (normalized).
    """
    evals, evecs = diagonalize_tridiagonal_matrix(d, e, True)
    min_index = np.argsort(evals)[0]
    coefficients_of_gs_in_krylov_space = evecs[:, min_index]
    assert (
        len(saved_lanczos_vectors) == len(coefficients_of_gs_in_krylov_space))

    result = Wavefunction(saved_lanczos_vectors[0].left_dim,
                          saved_lanczos_vectors[0].right_dim)
    result.set_to_zero()
    for i in range(len(saved_lanczos_vectors)):
        result.as_matrix += (coefficients_of_gs_in_krylov_space[i] *
                             saved_lanczos_vectors[i].as_matrix)

    result.normalize()
    return result
Example #2
0
def calculate_ground_state_wf(d, e, saved_lanczos_vectors): 
    """Calculates the ground state wavefunction.
    
    Parameters
    ----------
    d : a numpy array with ndim = 1.
        The elements of the diagonal of the tridiagonal matrix. The size
	of `d`.
    e : a numpy array with ndim = 1.
        The off-diagonal elements of the tridiagonal matrix. The size of
	`e` equals the size of `d`, and it is padded with a zero at the
	end. 
    saved_lanczos_vectors : a list of Wavefunctions.
        The Lanczos vectors that are saved.

    Returns
    -------
    result : a Wavefunction.
        The ground state function (normalized).
    """
    evals, evecs = diagonalize_tridiagonal_matrix(d, e, True)
    min_index = np.argsort(evals)[0]
    coefficients_of_gs_in_krylov_space = evecs[:, min_index]
    assert(len(saved_lanczos_vectors) == len(coefficients_of_gs_in_krylov_space))
    
    result = Wavefunction(saved_lanczos_vectors[0].left_dim,
		          saved_lanczos_vectors[0].right_dim) 
    result.set_to_zero()
    for i in range(len(saved_lanczos_vectors)):
        result.as_matrix += ( coefficients_of_gs_in_krylov_space[i] * 
		saved_lanczos_vectors[i].as_matrix )

    result.normalize()
    return result