| mxvg_c |
|
Table of contents
Procedure
mxvg_c ( Matrix times vector, general dimension )
void mxvg_c ( const void * m1,
const void * v2,
SpiceInt nr1,
SpiceInt nc1r2,
void * vout )
AbstractMultiply a matrix and a vector of arbitrary size. Required_ReadingNone. KeywordsMATRIX VECTOR Brief_I/OVARIABLE I/O DESCRIPTION -------- --- -------------------------------------------------- m1 I Left-hand matrix to be multiplied. v2 I Right-hand vector to be multiplied. nr1 I Row dimension of `m1' and length of `vout'. nc1r2 I Column dimension of `m1' and length of `v2'. vout O Product vector m1*v2. Detailed_Input
m1 is a double precision matrix of arbitrary size which
forms the left-hand matrix of the multiplication.
v2 is a double precision vector on the right of the
multiplication.
nr1 is the row dimension of `m1' and length of `vout'.
nc1r2 is the column dimension of `m1' and length of `v2'.
Detailed_Output
vout is the double precision vector which results from
the multiplication
vout = (m1) x v2
`vout' has length `nr1'.
`vout' may overwrite `m1' or `v2'.
ParametersNone. Exceptions
1) If memory cannot be allocated to create the temporary matrix
required for the execution of the routine, the error
SPICE(MALLOCFAILED) is signaled.
FilesNone. Particulars
The code reflects precisely the following mathematical expression
For each value of the subscript `i' from 1 to `nr1',
vout(i) = Summation from k=1 to nc1r2 of ( m1(i,k) * v2(k) )
Examples
The numerical results shown for this example may differ across
platforms. The results depend on the SPICE kernels used as
input, the compiler and supporting libraries, and the machine
specific arithmetic implementation.
1) Given a 2x3 matrix and a 3-vector, multiply the matrix by
the vector.
Example code begins here.
/.
Program mxvg_ex1
./
#include <stdio.h>
#include "SpiceUsr.h"
int main( )
{
/.
Local variables.
./
SpiceDouble vout [2];
/.
Define `m' and `vin'.
./
SpiceDouble m [2][3] = { { 1.0, 1.0, 1.0 },
{ 2.0, 3.0, 4.0 } };
SpiceDouble vin [3] = { 1.0, 2.0, 3.0 };
/.
Multiply `m' by `vin'.
./
mxvg_c ( m, vin, 2, 3, vout );
printf( "M times VIN:\n" );
printf( "%10.3f %9.3f\n", vout[0], vout[1] );
return ( 0 );
}
When this program was executed on a Mac/Intel/cc/64-bit
platform, the output was:
M times VIN:
6.000 20.000
Restrictions
1) The user is responsible for checking the magnitudes of the
elements of `m1' and `v2' so that a floating point overflow does
not occur.
Literature_ReferencesNone. Author_and_InstitutionN.J. Bachman (JPL) J. Diaz del Rio (ODC Space) W.L. Taber (JPL) Version
-CSPICE Version 1.2.0, 04-JUL-2021 (JDR)
Changed input argument name "nrow1" to "nr1" for consistency with
other routines.
Updated short error message for consistency within CSPICE wrapper
interface: MEMALLOCFAILED -> MALLOCFAILED.
Edited the header to comply with NAIF standard. Added complete code
example based on the existing example.
-CSPICE Version 1.1.0, 25-JUL-2001 (NJB)
Changed protoype: inputs "m1" and "v2" are now type
(const void *). Implemented interface macro for casting inputs
"m1" and "v2" to const.
-CSPICE Version 1.0.1, 08-FEB-1998 (NJB)
Corrected a comment describing the local macro INDEX. Made
miscellaneous code format corrections.
-CSPICE Version 1.0.0, 25-OCT-1997 (NJB) (WLT)
Based on SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)
Index_Entriesmatrix times n-dimensional vector Link to routine mxvg_c source file mxvg_c.c |
Fri Dec 31 18:41:09 2021