当前位置: 首页>>代码示例>>C++>>正文


C++ Matrix::Div方法代码示例

本文整理汇总了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;
			}
开发者ID:francoisludewig,项目名称:MecaSolid,代码行数:7,代码来源:Matrix.cpp

示例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;
}
开发者ID:henryYunhui,项目名称:matrix,代码行数:101,代码来源:tests.cpp


注:本文中的Matrix::Div方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。