Exemple d'appel de la routine DPBSV en C

#include <stdio.h>
#include <malloc.h>
#include <math.h>
#define MMAX 100

extern void dpbsv_(char *, int *, int *, int *, double *, int *, double *, int *
, int *);

void main()
{
        int i,j,M=5;
        double AB[MMAX*MMAX][MMAX+1], B[MMAX*MMAX];
        char UPLO = 'L';
        int NRHS = 1, N=M*M, KD=M, LDAB=MMAX+1, INFO;
/*
        remplissage de la matrice : mise a zero
*/
        for (i=0;i<N;i++) {
            for (j=0;j<M+1;j++) {
                AB[i][j] = 0.;
            }
        }
/*
        remplissage des 3 diagonales
*/
        for (i=0;i<N;i++) {
            AB[i][0] = 4.;
            AB[i][1] = -1.;
            AB[i][M] = -1.;
        }
/*
        mise a zero des coefficients dans la 2e diagonale
*/
        for (i=0;i<M;i++) {
            AB[(i+1)*M-1][1] = 0.;
        }
/*      
        remplissage du second membre
*/
        for (i=0;i<N;i++) {
            B[i]=0.;
        }
        for (i=0;i<M;i++) {
            B[i] += i+1;
        }
        for (i=0;i<M;i++) {
            B[M*i] += i+1;
        }
        for (i=0;i<M;i++) {
            B[M*i+M-1] += M+1+i+1;
        }
        for (i=0;i<M;i++) {
            B[M*(M-1)+i] += i+1+M+1;
        }
/*
        appel de DPBSV
*/
        dpbsv_(&UPLO,&N, &KD, &NRHS, &(AB[0][0]), 
                                        &LDAB, B, &N, &INFO);
/*
        impression du resultat
*/
        for (i=0;i<M;i++) {
          for (j=0;j<M;j++) {
            printf("index: %d computed: %f error: %le \n",
                M*i+j,B[M*i+j],B[M*i+j]-(i+1+j+1));
          }
        }
}

Voilà le résultat du programme :

index: 0 computed: 2.000000 error: -4.440892e-16 
index: 1 computed: 3.000000 error: -8.881784e-16 
index: 2 computed: 4.000000 error: -8.881784e-16 
index: 3 computed: 5.000000 error: -8.881784e-16 
index: 4 computed: 6.000000 error: 0.000000e+00 
index: 5 computed: 3.000000 error: -8.881784e-16 
index: 6 computed: 4.000000 error: -4.440892e-16 
index: 7 computed: 5.000000 error: -1.776357e-15 
index: 8 computed: 6.000000 error: 0.000000e+00 
index: 9 computed: 7.000000 error: -8.881784e-16 
index: 10 computed: 4.000000 error: -4.440892e-16 
index: 11 computed: 5.000000 error: -8.881784e-16 
index: 12 computed: 6.000000 error: -8.881784e-16 
index: 13 computed: 7.000000 error: 8.881784e-16 
index: 14 computed: 8.000000 error: -8.881784e-16 
index: 15 computed: 5.000000 error: 8.881784e-16 
index: 16 computed: 6.000000 error: 0.000000e+00 
index: 17 computed: 7.000000 error: -1.776357e-15 
index: 18 computed: 8.000000 error: -1.776357e-15 
index: 19 computed: 9.000000 error: 0.000000e+00 
index: 20 computed: 6.000000 error: -8.881784e-16 
index: 21 computed: 7.000000 error: -8.881784e-16 
index: 22 computed: 8.000000 error: -1.776357e-15 
index: 23 computed: 9.000000 error: -1.776357e-15 
index: 24 computed: 10.000000 error: 0.000000e+00

EPFL-IACS-ASN