extern double *mat(int n, int m)
1、n<=0 or m>=0 return NULL
2、内存分配错误 !(p=(double *)malloc(sizeof(double)*n*m))
fatalerr("matrix memory allocation error: n=%d,m=%d\n",n,m);
extern int *imat(int n, int m)
1、n<=0 or m>=0 return NULL
2、内存分配错误 !(p=(int *)malloc(sizeof(int)*n*m))
fatalerr("integer matrix memory allocation error: n=%d,m=%d\n",n,m);
extern double *zeros(int n, int m)
#if #else #endif 预处理命令
NOCALLOC if ((p=mat(n,m))) for (n=n*m-1;n>=0;n--) p[n]=0.0;
#else
1、 n<=0 or m>=0 return NULL
2、内存分配错误 !(p=(double *)malloc(sizeof(int)*n*m))
fatalerr("matrix memory allocation error: n=%d,m=%d\n",n,m);
extern double *eye(int n)
if ((p=zeros(n,n))) for (i=0;i eg. n=0,则p[0]=p[3]=1.0 void *memcpy(void *str1, const void *str2, size_t n) 从存储区 str2 复制 n 个字节到存储区 str1。 内积开根号 a的模 |a|=(a[0]^2+a[1]^2+a[2]^2+)^(1/2) 若 |a|<=0, return 0。 单位矢量为b =[a[0]/|a|,a[1]/|a|,a[2]/|a|,]
复制矩阵 n*m
extern void matcpy(double *A, const double *B, int n, int m)
{
memcpy(A,B,sizeof(double)*n*m);
}
向量运算
计算两个n维向量内积(点乘)
extern double dot(const double *a, const double *b, int n)
计算n维向量的欧几里得范数(euclid norm)
extern double norm(const double *a, int n)
计算两个三维(3*1)向量的外积
extern void cross3(const double *a, const double *b, double *c)
3维向量归一化(单位矢量)
extern int normv3(const double *a, double *b)