📄 e.cpp
字号:
void SetMat (int m, int n, REAL * a[], REAL val)
/*====================================================================*
* *
* Initialize an m x n matrix with a constant value val . *
* *
*====================================================================*
* *
* Input parameters: *
* ================ *
* m int m; ( m > 0 ) *
* row number of matrix *
* n int n; ( n > 0 ) *
* column number of matrix *
* a REAL * a[]; *
* matrix *
* val constant value *
* *
* Output parameter: *
* ================ *
* a matrix with constant value val in every position *
* *
*====================================================================*/
{
int i, j;
for (i = 0; i < m; i++)
for (j = 0; j < n; j++)
a[i][j] = val;
}
static char Separator[] =
"--------------------------------------------------------------------";
int WriteHead (FILE *fp, char * string)
/*====================================================================*
* *
* Put out header with text in string in file fp. *
* *
*====================================================================*
* *
* Input parameters: *
* ================ *
* string char *string; *
* text of headertext (last byte is a 0) *
* *
* Return value : *
* ============= *
* = 0 All ok *
* = -1 Error writing onto stdout *
* = -2 Invalid text for header *
* *
*====================================================================*/
{
if (string == NULL) return (-2);
if (fprintf (fp,"\n%s\n%s\n%s\n\n", Separator, string, Separator) <= 0)
return (-1);
return 0;
}
int WriteHead1( char * string)
/*====================================================================*
* *
* Put out header with text in string in stdout. *
* *
*====================================================================*
* *
* Input parameters: *
* ================ *
* string char *string; *
* text of headertext (last byte is a 0) *
* *
* Return value : *
* ============= *
* = 0 All ok *
* = -1 Error writing onto stdout *
* = -2 Invalid text for header *
* *
*====================================================================*/
{
if (string == NULL) return (-2);
if (printf ("\n%s\n%s\n%s\n\n", Separator, string, Separator) <= 0)
return (-1);
return 0;
}
int WriteEnd (FILE *fp)
/*====================================================================*
* *
* Put out end of writing onto file fp. *
* *
*====================================================================*
* *
* Return value : *
* ============= *
* = 0 All ok *
* = -1 error writing onto stdout *
* *
*====================================================================*/
{
if (fprintf (fp,"\n%s\n\n", Separator) <= 0) return (-1);
return 0;
}
int WriteEnd1(void)
/*====================================================================*
* *
* Put out end of writing onto stdout. *
* *
*====================================================================*
* *
* Return value : *
* ============= *
* = 0 All ok *
* = -1 error writing onto stdout *
* *
*====================================================================*/
{
if (printf ("\n%s\n\n", Separator) <= 0) return (-1);
return 0;
}
void LogError (char * string, int rc, char * file, int line)
/*====================================================================*
* *
* Put out error message onto stdout. *
* *
*====================================================================*
* *
* Input parameters: *
* ================ *
* string char *string; *
* text of error massage (final byte is 0) *
* rc int rc; *
* error code *
* file char *file; *
* name of C file in which error was encountered *
* line int line; *
* line number of C file with error *
* *
*====================================================================*/
{
if (string == NULL)
{
printf ("Unknown ERROR in file %s at line %d\n", file, line);
return;
}
if (rc == 0)
printf ("ERROR: %s, File %s, Line %d\n", string, file, line);
else
printf ("ERROR: %s, rc = %d, File %s, Line %d\n",
string, rc, file, line);
return;
}
REAL epsroot(void) /* Compute square root of the machine constant ...*/
/***********************************************************************
* Compute square root of the machine constant, if not already done. *
* *
* global names used: *
* ================== *
* REAL, boolean, FALSE, TRUE, SQRT, MACH_EPS *
***********************************************************************/
{
static REAL save_mach_eps_root;
static boolean schon_berechnet = FALSE;
if (! schon_berechnet)
schon_berechnet = TRUE,
save_mach_eps_root = SQRT(MACH_EPS);
return save_mach_eps_root;
}
REAL epsquad(void) /* Find the machine constant squared .........*/
/***********************************************************************
* Compute the square of the machine constant, if not already done. *
* *
* global names used: *
* ================== *
* REAL, boolean, FALSE, TRUE, MACH_EPS *
***********************************************************************/
{
static REAL save_mach_eps_quad;
static boolean schon_berechnet = FALSE;
if (! schon_berechnet)
schon_berechnet = TRUE,
save_mach_eps_quad = MACH_EPS * MACH_EPS;
return save_mach_eps_quad;
}
// End of file basis_r.cpp
// Header file of vmblock.cpp
#ifndef VMBLOCK_H_INCLUDED
#define VMBLOCK_H_INCLUDED
#include <malloc.h>
/***********************************************************************
* symbolic names that let the user choose the kind of dynamical data *
* structure to be allocated upon calling vmalloc() *
***********************************************************************/
#define VEKTOR 0 /* for a REAL vector */
/*.IX{VEKTOR}*/
#define VVEKTOR 1 /* for a vector with elements */
/*.IX{VVEKTOR}*/
/* of given size */
#define MATRIX 2 /* for a REAL matrix */
/*.IX{MATRIX}*/
#define IMATRIX 3 /* for an int matrix */
/*.IX{IMATRIX}*/
#define MMATRIX 4 /* for a matrix of 4x4 matrices */
/*.IX{PMATRIX}*/
/* (with elements of type `mat4x4') */
#define UMATRIX 5 /* for a lower triangular matrix */
/*.IX{UMATRIX}*/
#define PMATRIX 6 /* for a matrix of points in R3 */
/*.IX{PMATRIX}*/
/***********************************************************************
* operations on a vector matrix list *
***********************************************************************/
void *vminit /* create an empty vector/matrix list ...........*/
(
void
); /* address of list ...................*/
void *vmalloc /* create a dynamic vector or matrix ............*/
(
void *vmblock, /* address of a vector/matrix list ...*/
int typ, /* kind of vector or matrix ..........*/
size_t zeilen, /* length (vector) or number of rows .*/
size_t spalten /* number of columns or element size .*/
); /* address of the created object .....*/
bool vmcomplete /* check vector/matrix list for lack of memory ..*/
(
void *vmblock /* address of list ...................*/
); /* no lack of memory? ................*/
void vmfree /* free the memory for a vektor/matrix list .....*/
(
void *vmblock /* address of list ...................*/
);
#endif
/* ------------------------- END vmblock.h -------------------------- */
/* ----------------------- MODULE vmblock.cpp ----------------------- *
***********************************************************
* Reference: *
* *
* "Numerical Algorithms with C, by Gisela Engeln-Muellges *
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -