示例#1
0
文件: Matrix.cpp 项目: eyeq/Matrix
Matrix Matrix::LowerTriangular() const {
	if (!IsSquare()) {
		throw "Exception : Not a square matrixe.\n";
		exit(EXIT_FAILURE);
	}

	Matrix m = Clone();
	const int N = Row();
	for (int i = N - 1; i >= 0; i--) {
		for (int j = i - 1; j >= 0; j--) {
			if (abs(m(i, i)) < abs(m(j, i))) {
				m.SwapRow(i, j);
			}
		}
		double aii = m(i, i);
		if (aii == 0.0) {
			throw "Exception : Can not calculate.\n";
			exit(EXIT_FAILURE);
		}
		
		for (int j = 0; j < N; j++) {
			if (i >= j) {
				continue;
			}
			double aji = m(j, i);
			for (int k = 0; k < N; k++) {
				m(j, k) -= m(i, k) * aji / aii;
			}
		}
	}
	return m;
}
示例#2
0
//==========================================================================
// Class:			Matrix
// Function:		GetInverse
//
// Description:		Returns the inverse of this matrix.  If this matrix is badly
//					scaled or is rectangular, the psuedo-inverse is returned.
//
// Input Arguments:
//		None
//
// Output Arguments:
//		inverse	= Matrix&
//
// Return Value:
//		bool, true for success, false otherwise
//
//==========================================================================
bool Matrix::GetInverse(Matrix &inverse) const
{
	if (!IsSquare() || GetRank() != rows)
		return GetPsuedoInverse(inverse);

	// Don't see a point to having two inverse methods -> always use the same method
	return GetPsuedoInverse(inverse);
}
示例#3
0
void ExpandSquare(Image& tex)
{
	if(IsSquare(tex))
		return;
	Image old = tex;

	makeSquareDimensions(tex);
	tex.clear();
	old.blit(tex);
}
// Load and save to an XML file
void CDrawSquare::SaveXML( CXMLWriter &xml )
{
    xml.addTag(GetXMLTag(IsSquare()));

    xml.addAttribute( _T("a"), CDPoint(m_point_a) );
    xml.addAttribute( _T("b"), CDPoint(m_point_b) );
    xml.addAttribute( _T("style"), Style );
    xml.addAttribute( _T("fill"), Fill );

    xml.closeTag();
}
示例#5
0
文件: Matrix.cpp 项目: eyeq/Matrix
double Matrix::Trace() const {
	if (!IsSquare()) {
		throw "Exception : Not a square matrixe.\n";
		exit(EXIT_FAILURE);
	}

	double f = 0.0;
	for (int i = 0; i < Row(); i++) {
		f += (*this)(i, i);
	}
	return f;
}
示例#6
0
void StretchSquare(Image& tex)
{
	if(IsSquare(tex))
		return;
	ImageOperator oldtex = tex;
	makeSquareDimensions(tex);
	ImageOperator newtex;

	newtex.initialize(tex.w, tex.h);
	oldtex.stretchBlit(newtex);

	newtex.output(tex, tex.format);
}
示例#7
0
文件: Matrix.cpp 项目: eyeq/Matrix
double Matrix::Abs() const {
	if (!IsSquare()) {
		throw "Exception : Not a square matrixe.\n";
		exit(EXIT_FAILURE);
	}

	Matrix m = UpperTriangular();
	double f = 1.0;
	for (int i = 0; i < Row(); i++) {
		f *= m(i, i);
	}
	return f;
}
示例#8
0
/*************************************************
	Function: 		main
	Description: 	主函数
	Calls: 			scanf	printf
	Called By:		编译器
	Input: 			无
	Output: 		无
	Return: 		0
*************************************************/
int main(void)
{
	int i;
	printf("the result is:\n");
	
	//在100-999之间查找
	for (i = 100; i < 1000; i++)
	{
		if (IsSquare(i) && IsFun(i))
		{
			printf("%d\t", i);
		}
	}
	printf("\n");
}
示例#9
0
int main(){
	char text[20000],out[20000];
	int t;
	scanf("%d",&t);
	getchar();
	while(t--){
		gets(text);
		if(IsSquare(strlen(text))){
			DigitalFortress(text,out);
			puts(out);
			memset(out,'\0',sizeof(out));
		}
		else
			printf("INVALID\n");
	}
	return 0;
}
示例#10
0
文件: Matrix.cpp 项目: eyeq/Matrix
Matrix Matrix::Inverse() const {
	if (!IsSquare()) {
		throw "Exception : Not a square matrixe.\n";
		exit(EXIT_FAILURE);
	}

	Matrix m = Clone();
	const int N = Row();
	Matrix e = IdentityMatrix(N);
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (abs(m(i, i)) < abs(m(j, i))) {
				m.SwapRow(i, j);
			}
		}
		double aii = m(i, i);
		if (aii == 0.0) {
			throw "Exception : Can not calculate.\n";
			exit(EXIT_FAILURE);
		}

		for (int j = 0; j < N; j++) {
			m(i, j) /= aii;
			e(i, j) /= aii;
		}
		for (int j = 0; j < N; j++) {
			if (i == j) {
				continue;
			}
			double aji = m(j, i);
			for (int k = 0; k < N; k++) {
				m(j, k) -= m(i, k) * aji;
				e(j, k) -= m(i, k) * aji;
			}
		}
	}
	return e;
}
示例#11
0
void Matrix::MakeLU()
{
	if (!IsSquare())
	{
		throw MException(L"The matrix is not square!");
	}
	L = IdentityMatrix(rows, cols);
	U = Duplicate();

	pi = new int[rows];
	for (int i = 0; i < rows; i++)
	{
		pi[i] = i;
	}

	double p = 0;
	double pom2;
	int k0 = 0;
	int pom1 = 0;

	for (int k = 0; k < cols - 1; k++)
	{
		p = 0;
		for (int i = k; i < rows; i++) // find the row with the biggest pivot
		{
			if (abs((*U)(i,k)) > p)
			{
				p = abs((*U)(i,k));
				k0 = i;
			}
		}
		if (p == 0) // samé nuly ve sloupci
		{
			throw MException(L"The matrix is singular!");
		}

		pom1 = pi[k]; // switch two rows in permutation matrix
		pi[k] = pi[k0];
		pi[k0] = pom1;

		for (int i = 0; i < k; i++)
		{
			pom2 = (*L)(k,i);
			(*L)(k,i) = (*L)(k0,i);
			(*L)(k0,i) = pom2;
		}

		if (k != k0)
		{
			detOfP *= -1;
		}

		for (int i = 0; i < cols; i++) // Switch rows in U
		{
			pom2 = (*U)(k,i);
			(*U)(k,i) = (*U)(k0,i);
			(*U)(k0,i) = pom2;
		}

		for (int i = k + 1; i < rows; i++)
		{
			(*L)(i,k) = (*U)(i,k) / (*U)(k,k);
			for (int j = k; j < cols; j++)
			{
				(*U)(i,j) = (*U)(i,j) - (*L)(i,k) * (*U)(k,j);
			}
		}
	}
}