Index: branch/mbaye/sp4a3/sp4a3_kalman.c
===================================================================
--- branch/mbaye/sp4a3/sp4a3_kalman.c	(revision 352)
+++ branch/mbaye/sp4a3/sp4a3_kalman.c	(revision 353)
@@ -3,35 +3,84 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <math.h>
-
 #include "sp4a3_kalman_extra.h"
 
+//Addition de deux matrices
+void Add_Mat_Mat(int na,int ma,double A[na][ma],int nb,int mb,double B[nb][mb], double out[na][ma])
+{
+    int i,j;
+    for (i=0;i<na;i++)
+    {
+        for (j=0;j<ma;j++)
+        {
+            out[i][j]=A[i][j]+B[i][j];
+        }
+    }
+}
 
-void Add_Mat_Mat(int na,int ma,double A[na][ma],int nb,int mb,double b[nb][mb], double out[na][ma]){
-
+//Calculer le déterminant d'une matrice 2*2
+double determinant(double A[2][2]) // determinant d'une matrice carrée
+{
+    double D;
+    D=A[0][0]*A[1][1]-A[1][0]*A[0][1];
+    return D;
+}
+
+//Calculer l'inverse d'une matrice 2*2
+void Inverse_Mat_22(int n,int m,double A[n][m],double B[n][m])
+{
+    double deter;
+    deter=determinant(A);
+    B[0][0]=A[1][1]/deter;
+    B[1][1]=A[0][0]/deter;
+    B[1][0]=-A[1][0]/deter;
+    B[0][1]=-A[0][1]/deter;
 }
-
-void Inverse_Mat_22(int n,int m,double A[n][m],double B[n][m]){
-
+
+//Calculer la transposée d'une matrice
+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];
+        }
+    }
 }
-
-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];
+
+//Faire la soustraction de deux matrices
+void Sub_Mat_Mat(int na,int ma,double A[na][ma],int nb,int mb,double B[nb][mb], double out[na][ma])
+{
+    int i,j;
+    for (i=0;i<na;i++)
+    {
+        for (j=0;j<ma;j++)
+        {
+            out[i][j]=A[i][j]-B[i][j];
+        }
+    }
 }
-
-void Sub_Mat_Mat(int na,int ma,double A[na][ma],int nb,int mb,double b[nb][mb], double out[na][ma]){
-
+
+//Faire la multiplication deux matrices
+void Mul_Mat_Mat(int na,int ma,double A[na][ma], int nb,int mb,double B[nb][mb], double out[na][mb])
+{
+    int i,j,k;
+    for(i=0;i<na;i++)
+    {
+        for(j=0;j<mb;j++)
+        {
+            out[i][j]=0;
+            for(k=0;k<ma;k++)
+            {
+                out[i][j]+=A[i][k]*B[k][j];
+            }
+        }
+     }
 }
 
-void Mul_Mat_Mat(int na,int ma,double A[na][ma], int nb,int mb,double B[nb][mb], double out[na][mb]){
-
-}
-
-
-
+//Test unitaires
 void tests_unitaires(void){
 	//Matrices d'entrée
 	double T21a[2][1]={{7},{-5}};
@@ -154,24 +203,51 @@
 		{
 			t -= t0;x -= x0;y -= y0;
 
-			debug=0; ///Mettre à 1 pour afficher les matrices.
+			debug=1; ///Mettre à 1 pour afficher les matrices.
 			///Ajouter votre code ci-dessous///
 			// Kalman
-
-			// X = F*X
-			Plot_Mat(X," X(k+1|k) = ");
-
-			//P = F*P*F'+Q;
+
+			// X = F*X
+            Mul_Mat_Mat(4,4,F,4,1,X,X1);  // F*X=X1
+            Plot_Mat(X," X(k+1|k) = ");
+            Plot_Mat(P,"P(k|k) = ");
+
+			//P = F*P*F'+Q;
+            double I[4][4];
+            double I1[4][4];
+            Mul_Mat_Mat(4,4,F,4,4,P,I);    // F*P=I
+            Mul_Mat_Mat(4,4,I,4,4,FT,I1);  // F*P*FT=I1
+            Add_Mat_Mat(4,4,I1,4,4,Q,P);  // I1+Q=P;
 			Plot_Mat(P,"P(k+1|k) = F.P(k|k).FT + Q = ");
 
-			// K = P*H' / ( H*P*H' + R);
+			// K = P*H' / ( H*P*H' + R);
+			double J[2][4];
+			double J1[2][4];
+			double J2[2][2];
+			double J3[2][2];
+			Mul_Mat_Mat(2,4,H,4,4,P,J); //H*P=J
+			Mul_Mat_Mat(2,4,J,4,2,HT,J1); //J*H'=J1
+			Add_Mat_Mat(2,4,J1,2,2,R,J2); //J1+R=J2
+			Inverse_Mat_22(2,2,J2,J3); //J2'=J3
+
+			Mul_Mat_Mat(4,4,P,4,2,HT,J4); //P*H'=J4
+			Mul_Mat_Mat(4,2,J4,2,2,J3,K); //J4*J3'=K
 			Plot_Mat(K,"K = ");
 
-			//X = X + K*([xb(i);yb(i)]-H*X);
-			//Plot_Mat(Delta,"DELTA = Obs - H.X(k+1|k)");
+			//X = X + K*([xb(i);yb(i)]-H*X);
+            double b[2][1]={{xb},{yb}}
+            double K1[2][1];
+            double delta[2][1];
+            double K2[4][1];
+            Mul_Mat_Mat(2,4,H,4,1,X,K1);  // H*X = K1
+            Sub_Mat_Mat(2,1,b,2,1,K1,delta);  // ([xb(i);yb(i)]-H*X)=delta
+            Mul_Mat_Mat(4,2,K,2,1,delta,K2);  // K*([xb(i);yb(i)]-H*X)=K3
+            Add_Mat_Mat(4,1,X,4,1,K2,X);   // X + K*([xb(i);yb(i)]-H*X)=X;
             Plot_Mat(X," X(k+1|k+1) = X(k+1|k) + K.Delta = ");
 
-			// P = P - K*H*P;
+			// P = P - K*H*P;
+			Mul_Mat_Mat(4,2,K,2,4,H,L1); //K*H=L1
+			Mul_Mat_Mat(4,4,L1)
             Plot_Mat(P," P(k+1|k+1) = P(k+1|k) - K.H.P(k+1|k) = ");
 
 			/// La matrice X doit contenir la position filtrée ///
