RTKLIB学习笔记——rtkcmn.c(矩阵及向量运算一)

矩阵运算

  • 创建n*m矩阵

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);
  • 创建 n*m  int矩阵

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);
  • 创建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

  • 复制矩阵 n*m

extern void matcpy(double *A, const double *B, int n, int m)
{
    memcpy(A,B,sizeof(double)*n*m);
}

void *memcpy(void *str1, const void *str2, size_t n) 从存储区 str2 复制 n 个字节到存储区 str1

向量运算

  • 计算两个n维向量内积(点乘)

extern double dot(const double *a, const double *b, int n)

 a=[a1,a2,...an] b=[b1,b2,...bn] a\cdot b=a1b1+a2b2+...+anbn

  • 计算n维向量的欧几里得范数(euclid norm)

extern double norm(const double *a, int n)

 内积开根号 a的模 |a|=(a[0]^2+a[1]^2+a[2]^2+)^(1/2)

  • 计算两个三维(3*1)向量的外积

extern void cross3(const double *a, const double *b, double *c)

 

  • 3维向量归一化(单位矢量)

extern int normv3(const double *a, double *b)

 若 |a|<=0, return 0。

单位矢量为b =[a[0]/|a|,a[1]/|a|,a[2]/|a|,]

你可能感兴趣的:(Rtklib学习笔记汇总ing,学习,c++,开发语言)