Révision 565
Ajouté par Domingos Joao BRAVO il y a presque 3 ans
sp4a3_kalman.c | ||
---|---|---|
#include "sp4a3_kalman_extra.h"
|
||
|
||
|
||
void Add_Mat_Mat(int na,int ma,double A[na][ma],int nb,int mb,double B[nb][mb], double R[na][ma]){
|
||
|
||
void Add_Mat_Mat(int na,int ma,double A[na][ma],int nb,int mb,double B[nb][mb], double R[na][ma])
|
||
{
|
||
int i,j;
|
||
double AddM;
|
||
if(na==nb && ma==mb) //Si le nombre de lignes de A=B et si les colonnes de A=B
|
||
{
|
||
for(i=0;i<na;i++)
|
||
{
|
||
for(j=0;j<mb;j++)
|
||
{
|
||
AddM=A[i][j] + B[i][j];
|
||
R[i][j]=AddM;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
printf("Les deux matrices nont pas la meme taille\n");
|
||
}
|
||
}
|
||
|
||
void Inverse_Mat_22(int n,int m,double A[n][m],double B[n][m]){
|
||
|
||
void Inverse_Mat_22(int n,int m,double A[n][m],double R[n][m])
|
||
{
|
||
double Det;
|
||
|
||
Det=(A[0][0]*A[1][1])-(A[0][1]*A[1][0]);//Calcul du déterminant
|
||
R[0][0]=(1/Det)*A[1][1];
|
||
R[0][1]=-(1/Det)*A[0][1];
|
||
R[1][0]=-(1/Det)*A[1][0];
|
||
R[1][1]=(1/Det)*A[0][0];
|
||
}
|
||
|
||
void Transpose_Mat(int n,int m,double A[n][m],double R[m][n]){
|
||
void Transpose_Mat(int n,int m,double A[n][m],double R[m][n])
|
||
{
|
||
int i,j;
|
||
for (i=0;i<n;i++)
|
||
for (j=0;j<m;j++)
|
||
R[j][i]=A[i][j];
|
||
}
|
||
for (i=0;i<n;i++)
|
||
{
|
||
for (j=0;j<m;j++)
|
||
{
|
||
R[j][i]=A[i][j];//Les lignes deviennent les colonnes et les colonnes devinnent les lignes
|
||
}
|
||
|
||
}
|
||
|
||
|
||
void Sub_Mat_Mat(int na,int ma,double A[na][ma],int nb,int mb,double B[nb][mb], double R[na][ma]){
|
||
|
||
|
||
}
|
||
|
||
void Mul_Mat_Mat(int na,int ma,double A[na][ma], int nb,int mb,double B[nb][mb], double R[na][mb]){
|
||
void Sub_Mat_Mat(int na,int ma,double A[na][ma],int nb,int mb,double B[nb][mb], double R[na][ma])
|
||
{
|
||
int i,j;
|
||
double SubM;
|
||
if(na==nb && ma==mb)// Même condition que l'adiction
|
||
{
|
||
for(i=0;i<na;i++)
|
||
{
|
||
for(j=0;j<mb;j++)
|
||
{
|
||
SubM=A[i][j] - B[i][j];
|
||
R[i][j]=SubM;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
printf("Les deux matrices nont pas la meme taille\n");
|
||
}
|
||
}
|
||
|
||
void Mul_Mat_Mat(int na,int ma,double A[na][ma], int nb,int mb,double B[nb][mb], double R[na][mb])
|
||
{
|
||
int i,j,k;
|
||
if(ma==nb)
|
||
{
|
||
for (int i = 0; i < na; i++)
|
||
{
|
||
for (int j = 0; j < mb; j++)
|
||
{
|
||
R[i][j] = 0;
|
||
for (int k = 0; k < ma; k++)
|
||
{
|
||
R[i][j] += A[i][k] * B[k][j];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
printf("Les colonnes de A et les lignes de B ne sont pas les memes\n");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
void tests_unitaires(void){
|
||
void tests_unitaires(void)
|
||
{
|
||
//Matrices d'entrée
|
||
double T21a[2][1]={{7},{-5}};
|
||
double T21b[2][1]={{-3},{46}};
|
||
... | ... | |
double T42a[4][2]={{-73,45},{10,12},{-41,-35},{8,-23}};
|
||
double T44a[4][4]={{1,2,7,4},{6,5,7,8},{9,8,7,6},{5,4,3,2}};
|
||
double T44b[4][4]={{12,13,14,15},{21,22,23,40},{78,45,12,3},{54,10,12,47}};
|
||
|
||
//Matrices résultat
|
||
double R21[2][1],R22[2][2],R24[2][4],R41[4][1],R42[4][2],R44[4][4];
|
||
|
||
... | ... | |
{0, 0, 1, 0},
|
||
{0, 0, 0, 1}};
|
||
double FT[4][4];
|
||
Transpose_Mat(4,4,F,FT);
|
||
Transpose_Mat(4,4,F,FT);
|
||
|
||
double X_l[4][1],X_2[2][1],X_3[2][1],X_4[4][1],X_5[4][1];
|
||
double P_1[4][4],P_2[4][4],P_3[4][4],P4[4][4],P5[4][4],P6[4][4];
|
||
double K_1[4][2],K_2[2][2],K_3[2][2],K_4[2][2],K_5[4][2],K_6[4][2];
|
||
|
||
|
||
while(fscanf(fichier, "%lf %lf %lf", &t, &xobs, &yobs)>0){
|
||
printf("-------------%04d--------------\n",cpt);
|
||
... | ... | |
{
|
||
t -= t0;xobs -= x0;yobs -= y0;
|
||
|
||
debug=0; ///Mettre à 1 pour afficher les matrices.
|
||
debug=1; ///Mettre à 1 pour afficher les matrices.
|
||
///Ajouter votre code ci-dessous///
|
||
// Kalman
|
||
|
Formats disponibles : Unified diff
Implantation des fonctions: Transposée, addiction, soustraction, inverse et multiplication.