Index: branch/faye_awasemou/sp4a3/sp4a3_kalman.c
===================================================================
--- branch/faye_awasemou/sp4a3/sp4a3_kalman.c	(revision 475)
+++ branch/faye_awasemou/sp4a3/sp4a3_kalman.c	(revision 476)
@@ -7,12 +7,29 @@
 #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;//i=variable permettant de parcourir les lignes et j=variable permettant de parcourir les colonnes
+    for(i=0;i<na;i++)
+    {
+        for(j=0;j<nb;j++)
+        {
+            R[i][j]=A[i][j]+B[i][j];
+
+        }
+    }
 
 }
 
-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 B[n][m]){
+    float detA;
+    detA=1/((A[0][0]*A[1][1])-(A[1][0]*A[0][1]));
+    B[0][0]=A[1][1]*detA;
+    B[0][1]=-A[0][1]*detA;
+    B[1][0]=-A[1][0]*detA;
+    B[1][1]=A[0][0]*detA;
+
 
+
 }
 
 void Transpose_Mat(int n,int m,double A[n][m],double R[m][n]){
@@ -22,11 +39,34 @@
 			R[j][i]=A[i][j];
 }
 
-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 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;//i=variable permettant de parcourir les lignes et j=variable permettant de parcourir les colonnes
+    for(i=0;i<na;i++)
+    {
+        for(j=0;j<mb;j++)
+        {
+            R[i][j]=A[i][j]-B[i][j];
+
+        }
+    }
 
 }
 
-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 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;//i=variable permettant de parcourir les lignes et j=variable permettant de parcourir les colonnes
+    for(i=0;i<na;i++)
+    {
+        for(j=0;j<mb;j++)
+        {
+            R[i][j]=0;
+            for(k=0;k<ma;k++)
+            {
+                 R[i][j]=R[i][j]+ A[i][k]*B[k][j];
+
+            }
+
+        }
+    }
 
 }
 
@@ -136,7 +176,26 @@
 						 {0, 1, 0, dt},
 						 {0, 0, 1, 0},
 						 {0, 0, 0, 1}};
-	double FT[4][4];
+	double FT[4][4];
+    double X1[4][1];
+    double X2[4][1];
+    double X3[4][1];
+    double A1[4][4];
+    double A2[4][4];
+    double P1[4][4];
+    double P2[4][4];
+    double G1[2][4];
+    double G2[2][2];
+    double G3[2][2];
+    double G4[2][2];// inversion de G3
+    double G5[4][2];
+    double DELTA1[2][1];
+    double DELTA[2][1];
+    double M1[2][1];
+    double M2[4][1];
+    double obs[2][1]={{xobs}, {yobs}};
+    double M3[4][4];
+    double M4[4][4];
 	Transpose_Mat(4,4,F,FT);
 
 	while(fscanf(fichier, "%lf %lf %lf", &t, &xobs, &yobs)>0){
@@ -154,24 +213,57 @@
 		{
 			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
+			// Kalman
+			Plot_Mat(X," X(k|k) = ");
 
-			// X = F*X
-			Plot_Mat(X," X(k+1|k) = ");
+//PREDICTION
+			// X = F*X
+
+
+			Mul_Mat_Mat(4,4,F,4,1,X,X1);// X1=F*X
+			Plot_Mat(X1," X(k+1|k) = ");
+			Plot_Mat(P," P(k|k) = ");
+
 
-			//P = F*P*F'+Q;
-			Plot_Mat(P,"P(k+1|k) = F.P(k|k).FT + Q = ");
 
-			// K = P*H' / ( H*P*H' + R);
+			//P = F*P*F'+Q;
+			Mul_Mat_Mat(4,4,F,4,4,P,A1);// A1=F*P
+			Mul_Mat_Mat(4,4,A1,4,4,FT,A2);// A2=F*P*FT
+			Add_Mat_Mat(4,4,A2,4,4,Q,P1);// P1=F*P*FT+Q
+			Plot_Mat(P,"P(k+1|k) = F.P(k|k).FT + Q = ");
+
+        //GAIN
+			// K = P*H' / ( H*P*H' + R);
+
+			Mul_Mat_Mat(4,4,H,4,4,P1,G1);//G1=H*P1
+			Mul_Mat_Mat(4,4,G1,4,4,HT,G2);//G2=H*P1*HT
+			Add_Mat_Mat(4,4,G2,4,4,R,G3);//G2=H*P1*HT
+			Plot_Mat(G3," H.P(k+1|k).HT+R = ");
+			Inverse_Mat_22(2,2,G3,G4);//G3=(H*P1*HT+R)
+			Mul_Mat_Mat(4,4,P1,4,2,HT,G5);//G5=P1*TH
+			Mul_Mat_Mat(4,2,G5,2,2,G3,K);//K=G5*G3
+			Plot_Mat(G4," INV(H.P(k+1|k).HT+R) = ");
 			Plot_Mat(K,"K = ");
-
-			//X = X + K*([xobs(i);yobs(i)]-H*X);
-			//Plot_Mat(Delta,"DELTA = Obs - H.X(k+1|k)");
+//MISE A JOUR
+            //X = X + K*([xobs(i);yobs(i)]-H*X);
+			//Plot_Mat(Delta,"DELTA = Obs - H.X(k+1|k)");
+
+
+            Mul_Mat_Mat(2,4,H,4,1,X1,M1);
+            Sub_Mat_Mat(2,1,obs,2,1,M1,DELTA1);
+            Mul_Mat_Mat(4,2,K,2,1,DELTA1,M2);
+            Add_Mat_Mat(4,1,X,4,1,M2,X3);
+            Sub_Mat_Mat(2,1,obs,2,1,M1,DELTA);
+            Plot_Mat(obs," obs = ");
+            Plot_Mat(DELTA,"DELTA =obs -H.X(k+1|k) ");
             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,M3);
+			Mul_Mat_Mat(4,4,M3,4,4,P,M4);
+			Sub_Mat_Mat(4,4,P1,4,4,M4,P2);
             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 ///
