ZigBee Matrix algorithm

Source: Internet
Author: User

Sensor.c

#include "Sensor.h"

/*
Matrix multiplication
C = a_t * A =2x2
2x2 x 2x8 = 2x8
2x8 x 8x1 = 2x1
*/


void Matrixmulti_1 (float a[2][8],float b[8][2],float c[2][2])
{
int i,j,q;
for (i = 0;i < 2;i++)
for (j = 0;j < 2;j++)
for (q = 0; q < 8;q++)
C[I][J] + = a[i][q] * B[q][j];
}
void Matrixmulti_2 (float a[2][2],float b[2][8],float c[2][8])
{
int i,j,q;
for (i = 0;i < 2;i++)
for (j = 0;j < 8;j++)
for (q = 0; q < 2;q++)
C[I][J] + = a[i][q] * B[q][j];
}
void Matrixmulti_3 (float a[2][8],float b[8][1],float c[2][1])
{
int i,j,q;
for (i = 0;i < 2;i++)
for (j = 0;j < 1;j++)
for (q = 0; q < 8;q++)
C[I][J] + = a[i][q] * B[q][j];
}
/*
T is the matrix before transpose, K is the matrix after transpose
*/
void Matrixtranspose (float a[n-1][t],float a_t[t][n-1])
{
int i,j;
for (i=0;i<n-1;i++)
for (j=0;j<t;j++)
A_t[j][i] = A[i][j];


}
/*
Calculate determinant
Expand calculation by First line | a|
*/
Float Geta (float arcs[t][t],int N)
{
float ans = 0;
float temp[t][t];
float T;
int i,j,k;


if (n==1)
{
return arcs[0][0];
}
for (i=0;i<n;i++)//N-column of the original determinant
{
for (j=0;j<n-1;j++)//n-1 Line
{
for (k=0;k<n-1;k++)//n-1 column
{
Temp[j][k] = arcs[j+1][(k>=i)? K+1:k];


}
}
t = Geta (temp,n-1);
if (i%2==0)
{
Ans + = arcs[0][i]*t;
}
Else
{
Ans-= arcs[0][i]*t;
}
}
return ans;
}
/*
Computes the cofactor of each element of each column of each row, forming the c*
Arcs[t][t] The adjoint matrix of the original matrix, the series of n matrices, Ans[t][t]
*/
void Getastart (float arcs[t][t],int n,float ans[t][t])
{
int i,j,k,t;
float temp[t][t];
if (n==1)
{
Ans[0][0] = 1;//guarantees the inverse of the matrix of an element to its reciprocal
Return
}
for (i=0;i<n;i++)
{
for (j=0;j<n;j++)
{
for (k=0;k<n-1;k++)
{
for (t=0;t<n-1;t++)
{
Temp[k][t] = arcs[k>=i?k+1:k][t>=j?t+1:t];
}
}
Ans[j][i] = Geta (temp,n-1);
if ((i+j)%2 = = 1)
{
Ans[j][i] =-ans[j][i];
}
}
}

}






Sensor.h

#ifndef sensor_h_included
#define Sensor_h_included


#define N 9 9 points
#define K N-1
#define T 2 Two columns




Float Geta (float arcs[t][t],int N);
void Getastart (float arcs[t][t],int n,float ans[t][t]);
void Matrixtranspose (float a[n-1][t],float a_t[t][n-1]);
void Matrixmulti_1 (float a[2][8],float b[8][2],float c[2][2]);
void Matrixmulti_2 (float a[2][2],float b[2][8],float c[2][8]);
void Matrixmulti_3 (float a[2][8],float b[8][1],float c[2][1]);


#endif//sensor_h_included










Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

ZigBee Matrix algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.