LAPACK usage example

Programming using LAPACK & Execution example

The following is an example of executing a program that solves the simultaneous linear equations. This example program is published on page 147 of the book "Linux 数値計算ツール (大石 進一 著, コロナ社 ISBN 4-339-02378-7)".


Example program

Created a file named "lapacktest.c".

#include <stdio.h>

#define N 3

double A[N*N];

double x[N];

void main(void)

{

static int i;

static long int n=N,inc=1,info,piv[N];

A[0]=1. ; A[1]=3. ; A[2]=1. ;

A[3]=1. ; A[4]=1. ; A[5]=-2. ;

A[6]=1. ; A[7]=-3. ; A[8]=-5. ;

x[0]=1. ; x[1]=5. ; x[2]=10. ;


printf("N = %d\n",N);

dgesv_(&n,&inc,A,&n,piv,x,&n,&info);

for(i=0; i<N; ++i) printf("%lf\n", x[i]);

}


How to compile (example)

$ gcc -llapack -lblas lapacktest.c


Execution example

Enter as follows to execute.

$ ./a.out

Execution result is output as follows.

N = 3

6.000000

-7.000000

2.000000