MPU6050のサンプルプログラム2
Dependencies: ConfigFile SDFileSystem mbed
Fork of LAURUS_program by
Vector_Matrix_operator.cpp
00001 #include "Vector_Matrix_operator.h" 00002 00003 Vector operator*(const Matrix& lhm, const Vector& rhv) { 00004 if (lhm.GetCol() != rhv.GetDim()) error("Irregular Dimention"); 00005 Vector retVec(lhm.GetRow()); 00006 00007 for (int i = 1; i <= lhm.GetRow(); i++) { 00008 float temp = 0.0f; 00009 for (int j = 1; j <= rhv.GetDim(); j++) { 00010 temp += lhm.GetComp(i, j)*rhv.GetComp(j); 00011 } 00012 retVec.SetComp(i, temp); 00013 } 00014 00015 retVec.CleanUp(); 00016 00017 return retVec; 00018 } 00019 00020 Vector operator*(const Vector& lhv, const Matrix& rhm) { 00021 if (lhv.GetDim() != rhm.GetRow()) error("Irregular Dimention"); 00022 Vector retVec(rhm.GetCol()); 00023 00024 for (int i = 1; i <= rhm.GetCol(); i++) { 00025 float temp = 0.0f; 00026 for (int j = 1; j <= lhv.GetDim(); j++) { 00027 temp += lhv.GetComp(j) * rhm.GetComp(j, i); 00028 } 00029 retVec.SetComp(i, temp); 00030 } 00031 00032 retVec.CleanUp(); 00033 00034 return retVec; 00035 }
Generated on Thu Jul 14 2022 07:53:07 by 1.7.2