本文整理汇总了C++中Matrix::Div方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix::Div方法的具体用法?C++ Matrix::Div怎么用?C++ Matrix::Div使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix
的用法示例。
在下文中一共展示了Matrix::Div方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
Matrix Matrix::operator/(const double &b) const{
if(b == 0)
throw(Error(1,"Dividing by 0 !",0));
Matrix a = *this;
a.Div(b);
return a;
}
示例2: main
//.........这里部分代码省略.........
// Mat-Mat Subtraction test
m.Sub(m_);
if (m(1, 1) == 1.0 && m(2, 2) == 0.0) {
cout << "[PASS]";
} else {
cout << "[FAIL]";
}
cout << " Matrix-by-matrix Sub" << endl;
// Mat-Mat - test
n = m_ - m - m;
if (n(1, 1) == -1.0 && n(2, 2) == 3.0) {
cout << "[PASS]";
} else {
cout << "[FAIL]";
}
cout << " Matrix-by-matrix Sub with -" << endl;
// Mat-Mat Multiplication test
m(2, 3) = 9.0;
m2(1, 1) = 5.0;
n = m.Mult(m2);
if (n(1, 1) == 5.0 && n(2, 1) == 18) {
cout << "[PASS]";
} else {
cout << "[FAIL]";
}
cout << " Matrix-by-matrix Mult" << endl;
// Mat-Mat * test
n = m * m2;
if (n(1, 1) == 5.0 && n(2, 1) == 18) {
cout << "[PASS]";
} else {
cout << "[FAIL]";
}
cout << " Matrix-by-matrix Mult with *" << endl;
// Mat-T Addition test
if (m(1, 1) == 1.0 && m(2, 3) == 9.0) {
cout << "[PASS]";
} else {
cout << "[FAIL]";
}
cout << " Matrix-by-value Add" << endl;
// Mat-T + test
n = m + 1.0;
if (n(1, 1) == 2.0 && n(2, 3) == 10.0) {
cout << "[PASS]";
} else {
cout << "[FAIL]";
}
cout << " Matrix-by-value +" << endl;
// Mat-T Subtraction test
m.Sub(-2.0);
if (m(1, 1) == 3.0 && m(2, 3) == 11.0) {
cout << "[PASS]";
} else {
cout << "[FAIL]";
}
cout << " Matrix-by-value Sub" << endl;
// Mat-T - test
n = m - 5.0;
if (n(1, 1) == -2.0 && n(2, 3) == 6.0) {
cout << "[PASS]";
} else {
cout << "[FAIL]";
}
cout << " Matrix-by-value -" << endl;
// Mat-T Multiplication test
m.Mult(4.0);
if (m(1, 1) == 12.0 && m(2, 3) == 44.0) {
cout << "[PASS]";
} else {
cout << "[FAIL]";
}
cout << " Matrix-by-value Mult" << endl;
// Mat-T Multiplication test
n = m * 11.0;
if (n(1, 1) == 132.0 && n(2, 3) == 484.0) {
cout << "[PASS]";
} else {
cout << "[FAIL]";
}
cout << " Matrix-by-value *" << endl;
// Mat-T Division test
m.Div(2.0);
if (m(1, 1) == 6.0 && m(2, 3) == 22.0) {
cout << "[PASS]";
} else {
cout << "[FAIL]";
}
cout << " Matrix-by-value Div" << endl;
}