LAPACK 3.11.0
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
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 --
53 -- LAPACK is a software package provided by Univ. of Tennessee, --
54 -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
55*/
56/* Calling DGELS using row-major layout */
57
58/* Includes */
59#include <stdio.h>
60#include <lapacke.h>
61#include "lapacke_example_aux.h"
62
63/* Main program */
64int main (int argc, const char * argv[])
65{
66 /* Locals */
67 double A[5][3] = {{1,1,1},{2,3,4},{3,5,2},{4,2,5},{5,4,3}};
68 double b[5][2] = {{-10,-3},{12,14},{14,12},{16,16},{18,16}};
69 lapack_int info,m,n,lda,ldb,nrhs;
70
71 /* Initialization */
72 m = 5;
73 n = 3;
74 nrhs = 2;
75 lda = 3;
76 ldb = 2;
77
78 /* Print Entry Matrix */
79 print_matrix_rowmajor( "Entry Matrix A", m, n, *A, lda );
80 /* Print Right Rand Side */
81 print_matrix_rowmajor( "Right Hand Side b", n, nrhs, *b, ldb );
82 printf( "\n" );
83
84 /* Executable statements */
85 printf( "LAPACKE_dgels (row-major, high-level) Example Program Results\n" );
86 /* Solve least squares problem*/
87 info = LAPACKE_dgels(LAPACK_ROW_MAJOR,'N',m,n,nrhs,*A,lda,*b,ldb);
88
89 /* Print Solution */
90 print_matrix_rowmajor( "Solution", n, nrhs, *b, ldb );
91 printf( "\n" );
92 exit( 0 );
93} /* End of LAPACKE_dgels Example */
int main()
Definition: cblas_example1.c:7
#define lapack_int
Definition: lapack.h:87
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
#define LAPACK_ROW_MAJOR
Definition: lapacke.h:52
void print_matrix_rowmajor(char *desc, lapack_int m, lapack_int n, double *mat, lapack_int ldm)