LAPACK
3.9.0
LAPACK: Linear Algebra PACKage
example_DGELS_rowmajor.c
Go to the documentation of this file.
1
/*
2
LAPACKE Example : Calling DGELS using row-major layout
3
=====================================================
4
5
The program computes the solution to the system of linear
6
equations with a square matrix A and multiple
7
right-hand sides B, where A is the coefficient matrix
8
and b is the right-hand side matrix:
9
10
Description
11
===========
12
13
In this example, we wish solve the least squares problem min_x || B - Ax ||
14
for two right-hand sides using the LAPACK routine DGELS. For input we will
15
use the 5-by-3 matrix
16
17
( 1 1 1 )
18
( 2 3 4 )
19
A = ( 3 5 2 )
20
( 4 2 5 )
21
( 5 4 3 )
22
and the 5-by-2 matrix
23
24
( -10 -3 )
25
( 12 14 )
26
B = ( 14 12 )
27
( 16 16 )
28
( 18 16 )
29
We will first store the input matrix as a static C two-dimensional array,
30
which is stored in row-major layout, and let LAPACKE handle the work space
31
array allocation. The LAPACK base name for this function is gels, and we
32
will use double precision (d), so the LAPACKE function name is LAPACKE_dgels.
33
34
thus lda=3 and ldb=2. The output for each right hand side is stored in b as
35
consecutive vectors of length 3. The correct answer for this problem is
36
the 3-by-2 matrix
37
38
( 2 1 )
39
( 1 1 )
40
( 1 2 )
41
42
A complete C program for this example is given below. Note that when the arrays
43
are passed to the LAPACK routine, they must be dereferenced, since LAPACK is
44
expecting arrays of type double *, not double **.
45
46
47
LAPACKE Interface
48
=================
49
50
LAPACKE_dgels (row-major, high-level) Example Program Results
51
52
-- LAPACKE Example routine (version 3.7.0) --
53
-- LAPACK is a software package provided by Univ. of Tennessee, --
54
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
55
December 2016
56
57
*/
58
/* Calling DGELS using row-major layout */
59
60
/* Includes */
61
#include <stdio.h>
62
#include <
lapacke.h
>
63
#include "
lapacke_example_aux.h
"
64
65
/* Main program */
66
int
main
(
int
argc,
const
char
* argv[])
67
{
68
/* Locals */
69
double
A[5][3] = {1,1,1,2,3,4,3,5,2,4,2,5,5,4,3};
70
double
b[5][2] = {-10,-3,12,14,14,12,16,16,18,16};
71
lapack_int
info,m,n,lda,ldb,nrhs;
72
73
/* Initialization */
74
m = 5;
75
n = 3;
76
nrhs = 2;
77
lda = 3;
78
ldb = 2;
79
80
/* Print Entry Matrix */
81
print_matrix_rowmajor
(
"Entry Matrix A"
, m, n, *A, lda );
82
/* Print Right Rand Side */
83
print_matrix_rowmajor
(
"Right Hand Side b"
, n, nrhs, *b, ldb );
84
printf(
"\n"
);
85
86
/* Executable statements */
87
printf(
"LAPACKE_dgels (row-major, high-level) Example Program Results\n"
);
88
/* Solve least squares problem*/
89
info =
LAPACKE_dgels
(
LAPACK_ROW_MAJOR
,
'N'
,m,n,nrhs,*A,lda,*b,ldb);
90
91
/* Print Solution */
92
print_matrix_rowmajor
(
"Solution"
, n, nrhs, *b, ldb );
93
printf(
"\n"
);
94
exit( 0 );
95
}
/* End of LAPACKE_dgels Example */
lapack_int
#define lapack_int
Definition:
lapack.h:21
LAPACKE_dgels
lapack_int LAPACKE_dgels(int matrix_layout, char trans, lapack_int m, lapack_int n, lapack_int nrhs, double *a, lapack_int lda, double *b, lapack_int ldb)
Definition:
lapacke_dgels.c:35
print_matrix_rowmajor
void print_matrix_rowmajor(char *desc, lapack_int m, lapack_int n, double *mat, lapack_int ldm)
Definition:
lapacke_example_aux.c:5
lapacke_example_aux.h
lapacke.h
main
int main(int argc, const char *argv[])
Definition:
example_DGELS_rowmajor.c:66
LAPACK_ROW_MAJOR
#define LAPACK_ROW_MAJOR
Definition:
lapacke.h:53
LAPACKE
example
example_DGELS_rowmajor.c
Generated on Wed May 5 2021 15:10:31 for LAPACK by
1.8.16