1 /* 2 3 -Procedure mxm_c ( Matrix times matrix, 3x3 ) 4 5 -Abstract 6 7 Multiply two 3x3 matrices. 8 9 -Disclaimer 10 11 THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE 12 CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. 13 GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE 14 ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE 15 PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" 16 TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY 17 WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A 18 PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC 19 SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE 20 SOFTWARE AND RELATED MATERIALS, HOWEVER USED. 21 22 IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA 23 BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT 24 LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, 25 INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, 26 REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE 27 REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. 28 29 RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF 30 THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY 31 CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE 32 ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. 33 34 -Required_Reading 35 36 None. 37 38 -Keywords 39 40 MATRIX 41 42 */ 43 44 #include "SpiceUsr.h" 45 #include "SpiceZmc.h" 46 #undef mxm_c 47 48 mxm_c(ConstSpiceDouble m1[3][3],ConstSpiceDouble m2[3][3],SpiceDouble mout[3][3])49 void mxm_c ( ConstSpiceDouble m1 [3][3], 50 ConstSpiceDouble m2 [3][3], 51 SpiceDouble mout[3][3] ) 52 53 /* 54 55 -Brief_I/O 56 57 VARIABLE I/O DESCRIPTION 58 -------- --- -------------------------------------------------- 59 m1 i 3x3 double precision matrix. 60 m2 i 3x3 double precision matrix. 61 mout o 3x3 double precision matrix. mout is the product 62 m1*m2. 63 64 -Detailed_Input 65 66 m1 is an arbitrary 3x3 double precision matrix. 67 68 m2 is an arbitrary 3x3 double precision matrix. 69 70 -Detailed_Output 71 72 mout is a 3x3 double precision matrix. mout is the product 73 m1*m2. mout may overwrite either m1 or m2. 74 75 -Parameters 76 77 None. 78 79 -Particulars 80 81 The code reflects precisely the following mathematical expression 82 83 For each value of the subscripts i and j from 1 to 3: 84 85 mout(i,j) = summation from k=1 to 3 of ( m1(i,k) * m2(k,j) ) 86 87 The intermediate results of the operation above are buffered in a 88 temporary matrix which is later moved to the output matrix. 89 Thus, to save space in the calling program, mout can be actually 90 be m1 or m2 if desired without interfering with the computations. 91 92 -Examples 93 94 Let m1 = | 1. 1. 0. | 95 | | 96 | -1. 1. 0. | 97 | | 98 | 0. 0. 1. | 99 100 101 and m2 = | 1. 0. 0. | 102 | | 103 | 0. 1. 1. | 104 | | 105 | 0. -1. 1. | 106 107 then the call 108 109 mxm_c ( m1, m2, mout ); 110 111 produces the matrix 112 113 mout = | 1. 1. 1. | 114 | | 115 | -1. 1. 1. | 116 | | 117 | 0. -1. 1. | 118 119 120 -Restrictions 121 122 None. 123 124 -Exceptions 125 126 Error free. 127 128 -Files 129 130 None. 131 132 -Author_and_Institution 133 134 E.D. Wright (JPL) 135 W.M. Owen (JPL) 136 137 -Literature_References 138 139 None. 140 141 -Version 142 143 -CSPICE Version 1.0.0, 16-APR-1999 (EDW) 144 145 -Index_Entries 146 147 matrix times matrix 3x3_case 148 149 -& 150 */ 151 152 153 { /* Begin mxm_c */ 154 155 /* 156 Local variables 157 */ 158 159 SpiceInt i; 160 SpiceInt j; 161 SpiceDouble mtemp[3][3]; 162 163 164 for ( i = 0; i <= 2; ++i) 165 { 166 167 for ( j = 0; j <= 2; ++j) 168 { 169 mtemp[i][j] = m1[i][0] * m2[0][j] + 170 m1[i][1] * m2[1][j] + 171 m1[i][2] * m2[2][j]; 172 } 173 174 } 175 176 177 /* 178 Copy the results from the temporary matrix to the return matrix. 179 */ 180 MOVED ( mtemp, 9, mout ); 181 182 183 } /* End mxm_c */ 184