⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ocn_f.h

📁 图像处理的压缩算法
💻 H
📖 第 1 页 / 共 4 页
字号:
/*------------------------------------------------------------------------------*
 * File Name: OCN_f.h															*
 * Creation: TCZ 7/20/2001														*
 * Purpose: Origin C Header for NAG functions									*
 * Copyright (c) OriginLab Corp.	2001										*
 * All Rights Reserved															*
 * 																				*
 * Modification Log:															*
 *------------------------------------------------------------------------------*/

#ifndef _O_NAG_f_H
#define _O_NAG_f_H

#importdll "ONAG" // NAG DLL prepared by OriginLab

#include <NAG\nag_types.h>

/* begin proto */

/**	f01bnc
		computes a Cholesky factorization of a complex positive-definite Hermitian matrix.
		
Example:
	This example computes the Cholesky factorization of the well-conditioned positive-definite Hermitian matrix
	.
	..
	15 1 - 2i 2 -4 + 3i
	1 + 2i 20 -2 + i 3 - 3i
	2 -2 - i 18 -1 + 2i
	-4 - 3i 3 + 3i -1 - 2i 26
	.
	..
	.

void test_nag_complex_cholesky()
{
	int i, j, n;
	matrix<complex> a;
	a.SetSize(8,8);
	double p[8];
	
	printf("f01bnc Example Program Results\n");
	a[0][0] = 15.0+0.0i;
	a[1][0] = 1.0+2.0i;
	a[1][1] = 20.0+0.0i;
	a[2][0] = 2.0+0.0i;
	a[2][1] = -2.0-1.0i;
	a[2][2] = 18.0+0.0i;
	a[3][0] = -4.0-3.0i;
	a[3][1] = 3.0+3.0i;
	a[3][2] = -1.0-2.0i;
	a[3][3] = 26.0+0.0i;
	n = 4;
	nag_complex_cholesky(n,a,8,p);
	complex gh;
	printf("\n Upper triangle of Complex matrix U by rows\n");
	for (i=0; i<n; ++i)
	{
		printf("\n");
		printf("   (%7.4f,%9.4f)\n", 1.0/p[i], 0.0);
		for (j=i+1; j<n; ++j)
		{
			gh = a[i][j];
			printf("   (%7.4f,%9.4f)\n",gh.m_re, gh.m_im);
		}
	}

}

	The output is following:
	
	Upper triangle of Complex matrix U by rows
	
	( 3.8730, 0.0000)
	( 0.2582, -0.5164)
	( 0.5164, 0.0000)
	(-1.0328, 0.7746)
	( 4.4347, 0.0000)
	(-0.4811, 0.1654)
	( 0.8268, -0.6013)
	( 4.1803, 0.0000)
	( 0.0073, 0.3463)
	( 4.8133, 0.0000)

Parameters:

Return:
	This function returns NAG error code, 0 if no error.
	
	370: Matrix diagonal element a [_value_][_value_] has non-zero imaginary part.
	358: The matrix is not positive-de.nite, possibly due to rounding errors.
	11: On entry, n must not be less than 1: n = _value_.  
	17: On entry, tda = _value_ while n = _value_. These parameters must satisfy tda = n.

	successfully call of the nag_complex_cholesky function.


*/
int nag_complex_cholesky(
int n, // the order of the matrix A.
complex a[], // Input:the lower triangle of the n by n positive-definite Hermitian matrix A. The elements of the array above the diagonal need not be set.  Output: the off-diagonal elements of the upper triangular matrix U. The lower triangle of A is unchanged.
int tda, // the second dimension of the array a as declared in the function from which nag complex cholesky is called.
double p[] // the reciprocals of the real diagonal elements of U.
);

/**	f01mcc
		computes the Cholesky factorization of a real symmetric 
		positive-de.nite variable-bandwidth matrix.

Example:
	To obtain the Cholesky factorization of the symmetric matrix, whose lower triangle is
	.
	......
	1
	2 5
	0 3 13
	0 0 0 16
	5 14 18 8 55
	0 0 0 24 17 77
	.
	......
	.
	For this matrix, the elements of row must be set to 1, 2, 2, 1, 5, 3, and the elements
	within the envelope must be supplied in row order as 1, 2, 5, 3, 13, 16, 5, 14, 18, 8, 
	55, 24, 17, 77.

void test_nag_real_cholesky_skyline()
{

	int i, k, k1, k2, lal, n;
	double a[] = {1.0, 2.0, 5.0, 3.0, 13.0, 16.0, 5.0, 14.0,
				  18.0, 8.0, 55.0, 24.0, 17.0, 77.0};
	double al[36], d[8];
	n = 6;
	int row[] = {1, 2, 2, 1, 5, 3, 0, 0};
	k2 =14;	
	lal = k2;

	int success = nag_real_cholesky_skyline(n, a, lal, row, al, d);
	printf("\n");
	if(success == 0)
	{
		printf(" i d[i] Rowi of unit lower triangle\n\n");
		k2 = 0;
		for (i=0; i<n; ++i)
		{
			k1 = k2;
			k2 = k2+row[i];
			printf(" %3ld%8.3f", i, d[i]);
			for (k=k1; k<k2; k++)
				printf("%8.3f", al[k]);
			printf("\n");
		}
	}
	else
	printf("there is some problem with the function call");

}

	The output is following:
		
	i 	 d[i] 	Rowi of unit lower triangle
		
	0 	 1.000 	1.000
	1 	 1.000 	2.000  1.000
	2 	 4.000 	3.000  1.000
	3 	16.000 	1.000
	4 	 1.000 	5.000  4.000  1.500  0.500  1.000
	5 	16.000 	1.500  5.000  1.000

Parameters:

Return:
	This function returns NAG error code, 0 if no error.

	11: On entry, n must not be less than 1: n = _value_.  On entry, row[_value_] must not be less than 1: row[_value_] = _value_.
	13: On entry, row[_value_] = _value_ while i = _value_.  These parameters must satisfy row[i] = i + 1.
	17: On entry, lal = _value_while row[0]+ . . .+row[n-1] = _value_. These parameters must satisfy lal = row[0]+ . . .+row[n - 1].
	359: The matrix is not positive-de.nite, possibly due to rounding errors. The factorization has been completed but may be very inaccurate.
	358: The matrix is not positive-de.nite, possibly due to rounding errors.

	successfully call of the nag_real_cholesky_skyline function.

*/

int  nag_real_cholesky_skyline(
int n, // the order of the matrix A.
double a[], // the elements within the envelope of the lower triangle of the positive-de.nite symmetric matrix A, taken in row by row order.
int lal, // the smaller of the dimensions of the arrays a and al as declared in the function from which nag real cholesky skyline is called.
int row[], // contain the width of row i of the matrix A.
double al[], // : the elements within the envelope of the lower triangular matrix L, taken in row by row order.
double d[] // the diagonal elements of the diagonal matrix D. Note that the determinant of A is equal to the product of these diagonal elements.

);


/**	f01qcc
		finds the QR factorization of the real m by n matrix A, where m = n.

Example:
	To obtain the QR factorization of the 5 by 3 matrix
	A =
	.
	....
	2.0 2.5 2.5
	2.0 2.5 2.5
	1.6 -0.4 2.8
	2.0 -0.5 0.5
	1.2 -0.3 -2.9


void test_nag_real_qr()
{
	double zeta[10];
	matrix a;
	a.SetSize(20,10);
	int i, j, m, n;
	m = 5;
	n = 3; 
	a[0][0] = 2.0; 
	a[0][1] = 2.5;
	a[0][2] = 2.5;
	a[1][0] = 2.0;
	a[1][1] = 2.5;
	a[1][2] = 2.5;
	a[2][0] = 1.6;
	a[2][1] = -0.4;
	a[2][2] = 2.8;
	a[3][0] = 2.0;
	a[3][1] = -0.5;
	a[3][2] = 0.5;
	a[4][0] = 1.2;
	a[4][1] = -0.3;
	a[4][2] = -2.9;
 
	nag_real_qr(m, n, a, 10, zeta);
	printf("QR factorization of A\n\n");
	printf("Vector zeta\n");
	for (i = 0; i < n; ++i)
		printf(" %8.4f", zeta[i]);
	printf("\n\n");
	printf("Matrix A after factorization (upper triangular part is R)\n");
	for (i = 0; i < m; ++i)
	{
		for (j = 0; j < n; ++j)
			printf(" %8.4f", a[i][j]);
		printf("\n");
	}
}

	The output is following:
	
	QR factorization of A
	
	Vector zeta
	
	1.2247 1.1547 1.2649
	
	Matrix A after factorization (upper triangular part is R)
	
	-4.0000 	-2.0000 	-3.0000
	 0.4082 	-3.0000 	-2.0000
	 0.3266 	-0.4619 	-4.0000
	 0.4082 	-0.5774 	 0.0000
	 0.2449 	-0.3464 	-0.6325
	
Parameters:

Return:
	This function returns NAG error code, 0 if no error.
	
	17: On entry, m = _value_ while n = _value_. These parameters must satisfy m = n.  On entry, tda = _value_ while n = _value_. These parameters must satisfy tda = n.
	11: On entry, n must not be less than 0: n = _value_.
	
	successfully call of the nag_real_qr function.


*/

int  nag_real_qr(
int m, // the number of rows of A.
int n, // the number of columns of A.
double a[], // Input: the leading m by n part of the array a must contain the matrix to be factorized.  Output: the n by n upper triangular part of a will contain the upper triangular matrix R and the m by n strictly lower triangular part of a will contain details of the factorization as described in Section 3.
int tda, // the second dimension of the array a as declared in the function from which nag real qr is called.
double zeta[] // contains the scalar zeta_k for the kth transformation. 
);


/**	f01qdc
		performs one of the transformations B := QB or B := QT B, where B 
		is an m by ncolb real matrix and Q is an m by m orthogonal matrix, 
		given as the product of Householder transformation matrices.

Example:
	To obtain the matrix QTB for the matrix B given by
	B =
	.
	....
	1.1 0 0 .00
	0.90 0.00
	0.60 1.32
	0.00 1.10
	-0.80 -0.26
	.
	....
	following the QR factorization of the 5 by 3 matrix A given by
	A =
	.
	....
	2.0 2.5 2.5
	2.0 2.5 2.5
	1.6 -0.4 2.8
	2.0 -0.5 0.5
	1.2 -0.3 -2.9
	.

void test_nag_real_apply_q()
{
	double zeta[10];
	matrix a, b;
	a.SetSize(20,10);
	b.SetSize(20,5);
	int i, j, m, n, ncolb;
	m = 5;
	n = 3;
	a[0][0] =2.0;
	a[0][1] =2.5;
	a[0][2] =2.5;
	a[1][0] =2.0;
	a[1][1] =2.5;
	a[1][2] =2.5;
	a[2][0] =1.6;
	a[2][1] =-0.4;
	a[2][2] =2.8;
	a[3][0] =2.0;
	a[3][1] =-0.5;
	a[3][2] =0.5;
	a[4][0] =1.2;
	a[4][1] =-0.3;
	a[4][2] =-2.9;
	
	b[0][0] =1.1;
	b[0][1] =0.0;

	b[1][0] =0.9;
	b[1][1] =0.0;

	b[2][0] =0.6;
	b[2][1] =1.32;

	b[3][0] =0.0;
	b[3][1] =1.1;

	b[4][0] =-0.8;
	b[4][1] =-0.26;
	ncolb = 2;
	nag_real_qr(m, n, a, 10, zeta);
	nag_real_apply_q(Transpose, Nag_ElementsSeparate, m, n, a, 10, zeta,
					ncolb, b, 5);
	printf("Matrix Q'*B\n");
	for (i = 0; i < m; ++i)
	{
		for (j = 0; j < ncolb; ++j)
			printf(" %8.4f", b[i][j]);
		printf("\n");
	}
}

	The output is following:
	
	Matrix Q'*B
	
	-1.0000 	-1.0000
	-1.0000 	 1.0000
	-1.0000 	-1.0000
	-0.1000 	 0.1000
	-0.1000	 	-0.1000

	
	
Parameters:

Return:
	This function returns NAG error code, 0 if no error.
	
	70: On entry, parameter trans had an illegal value.  On entry, parameter wheret had an illegal value.
	17: On entry, m = _value_ while n = _value_. These parameters must satisfy m = n.  On entry, tda = _value_ while n = _value_. These parameters must satisfy tda = n.  On entry, tdb = _value_ while ncolb = _value_. These parameters must satisfy tdb = ncolb.
	11: On entry, n must not be less than 0: n = _value_.  On entry, ncolb must not be less than 0: ncolb = _value_.
	73: Memory allocation failed.

	successfully call of the nag_real_apply_q function.

*/
	int  nag_real_apply_q(
	MatrixTranspose trans, 
	Nag_WhereElements wheret,
	int m, // the number of rows of A.
	int n, // the number of columns of A.
	double a[], // contain details of the matrix Q.
	int tda, // the second dimension of the array a as declared in the function from which nag real apply q is called.
	double zeta[], // contain the elements of zeta.
	int ncolb, // the number of columns of B.
	double b[], // Input: the leading m by ncolb part of the array b must contain the matrix to be transformed.  Output: b is overwritten by the transformed matrix.
	int tdb // the second dimension of the array b as declared in the function from which nag real apply q is called.
	
	);


/**	f01qec
		returns the .rst ncolq columns of the real m by m orthogonal matrix Q,
		where Q is given as the product of Householder transformation matrices.


Example:
	To obtain the 5 by 5 orthogonal matrix Q following the QR factorization 
	of the 5 by 3 matrix A given by
	A =
	.
	....
	2.0 2.5 2.5
	2.0 2.5 2.5
	1.6 -0.4 2.8
	2.0 -0.5 0.5
	1.2 -0.3 -2.9
	.
	....

void test_nag_real_form_q()
{
	double zeta[10];
	matrix a, q;
	a.SetSize(20,10);
	q.SetSize(20,20);
	int i, j, m, n, ncolq;
	m = 5;
	n = 3;
	a[0][0] =2.0;
	a[0][1] =2.5;
	a[0][2] =2.5;
	a[1][0] =2.0;
	a[1][1] =2.5;
	a[1][2] =2.5;
	a[2][0] =1.6;
	a[2][1] =-0.4;
	a[2][2] =2.8;
	a[3][0] =2.0;
	a[3][1] =-0.5;
	a[3][2] =0.5;
	a[4][0] =1.2;
	a[4][1] =-0.3;
	a[4][2] =-2.9;
	
	nag_real_qr(m, n, a, 10, zeta);

	for (j = 0; j < n; ++j)
		for (i = 0; i < m; ++i)
			q[i][j] = a[i][j];
	ncolq = m;
	nag_real_form_q(Nag_ElementsSeparate, m, n, ncolq, q, 20,
					zeta);
	printf("Matrix Q\n");
	for (i = 0; i < m; ++i)
	{
		for (j = 0; j < ncolq; ++j)
			printf(" %8.4f", q[i][j]);
		printf("\n");
	}
}

	The output is following:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -