LAPACK (4) -- solving matrix feature values and feature vectors

Source: Internet
Author: User
Tags lapack

Use Example 2) solve the matrix feature value and feature vector Av =
V. The function prototype is as follows,

Lapack_int LAPACKE_dgeev (int matrix_order, char jobvl, char jobvr,
Lapack_int n, double * a, lapack_int lda, double * wr,
Double * wi, double * vl, lapack_int ldvl, double * vr,
Lapack_int ldvr );
/*
Params:
Matrix_order LAPACK_COL_MAJOR or LAPACK_ROW_MAJOR
Jobvl N, indicating that the Left feature vector is not required. V indicates that the request is required.
Jobvr and jobvl are the right feature vector options.
N matrix columns
A matrix
Number of rows in the lda a matrix. lda> = max of (1, n)
Real part of the feature value returned by wr
Virtual part of the feature value returned by wi
Storage space of vl left feature vectors
Number of rows in the left feature vector of ldvl
Storage space of the right feature vector in vr
Number of rows in the right feature vector of ldvr
Return:
Info = 0, SUCCESS,
-I, the parameter I is incorrect.
+ I, indicating execution error
*/

The test code is as follows,

#include <stdio.h>

//lapacke headers
#include "lapacke.h"
#include "lapacke_config.h"
#include "lapacke_utils.h"

extern lapack_int LAPACKE_dgeev( int matrix_order, char jobvl, char jobvr,
lapack_int n, double* a, lapack_int lda, double* wr,
double* wi, double* vl, lapack_int ldvl, double* vr,
lapack_int ldvr );

int main(){
int matrix_order = LAPACK_COL_MAJOR;
char jobvl = 'N';
char jobvr = 'V';
int n = 4;
double A[16] = {
0.35, 0.09, -0.44, 0.25,
0.45, 0.07, -0.33, -0.32,
-0.14, -0.54, -0.03, -0.13,
-0.17, 0.35, 0.17, 0.11
};
int lda = n;
double wr[4] = {0,0,0,0};
double wi[4] = {0,0,0,0};
double vl[16];
int ldvl = 4;
double vr[16];
int ldvr = 4;

int info = LAPACKE_dgeev(matrix_order,jobvl,jobvr,n,A,lda,wr,wi,vl,ldvl,vr,ldvr);
if(info==0){
int i = 0;
int j = 0;
for(i=0;i<n;i++){
printf("eigenvalue %d:\n",i);
printf("%.6g + i %.6g \t",wr[i],wi[i]);
printf("right eigenvector: ");
for(j=0;j<ldvr;j++)
printf("%.6g \t",vr[i*4+j]);
printf("\n");
}
printf("SUCCESS\n");
}

return 0;
}

The test results are as follows,

eigenvalue 0:
0.799482 + i 0 right eigenvector: -0.655089 -0.523629 0.536218 -0.0956068
eigenvalue 1:
-0.0994125 + i 0.400792 right eigenvector: -0.193302 0.251857 0.0971825 0.675954
eigenvalue 2:
-0.0994125 + i -0.400792 right eigenvector: 0.254632 -0.522405 -0.308384 0
eigenvalue 3:
-0.100657 + i 0 right eigenvector: 0.125333 0.332022 0.593838 0.722087
SUCCESS

You can refer to the following link for verification.
Http://www.nag.co.uk/lapack-ex/examples/results/dgeev-ex.r

There are some changes in the description of function parameters. The lda and ldvl parameters indicate the number of rows corresponding to the matrix.

In addition, a website provides lapack Test Data Based on which we can check whether our function is correct.
Http://www.nag.co.uk/lapack-ex/node136.html#index

There are some notes for LAPACK. For details, refer
Http://hi.baidu.com/hplonline/blog/category/c%26%2347%3Bc%2B%2B

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.