Index: branch/leng/sp4a3/sp4a3_kalman_extra.h
===================================================================
--- branch/leng/sp4a3/sp4a3_kalman_extra.h	(revision 280)
+++ branch/leng/sp4a3/sp4a3_kalman_extra.h	(revision 281)
@@ -1,11 +1,41 @@
 
 #define error(a) _error(__LINE__,a)
-void _error(int l,char * r);
+void _error(int l,char * r)
+{
+    int i=0;
+    for(i=0;i<l;i++)
+    {
+        printf("%i",r[i]);
+    };
+
+};
 
 #define Plot_Mat(Mat,titre) _Plot_Mat(sizeof(Mat)/sizeof(Mat[0]),sizeof(Mat[0])/sizeof(Mat[0][0]),Mat,titre)
-void _Plot_Mat(int n,int m,double in[n][m], const char* name);
+void _Plot_Mat(int n,int m,double in[n][m], const char* name){
+    int i=0,j=0;
+    printf("%s \n",name);
+    for(i=0;i<n;i++){
+        for(j=0;j<m;j++){
+            printf("%d",in[i][j]);
+        };
+    };
+
+};
 
 #define Equal_Mat_Mat(Mat_A,Mat_B) _Equal_Mat_Mat(sizeof(Mat_A)/sizeof(Mat_A[0]),sizeof(Mat_A[0])/sizeof(Mat_A[0][0]),Mat_A,sizeof(Mat_B)/sizeof(Mat_B[0]),sizeof(Mat_B[0])/sizeof(Mat_B[0][0]),Mat_B)
-int _Equal_Mat_Mat(int na,int ma,double A[na][ma],int nb,int mb,double B[nb][mb]);
+int _Equal_Mat_Mat(int na,int ma,double A[na][ma],int nb,int mb,double B[nb][mb]){
+int i,j;
+int out;
+for (i=0;i<na;i++){
+        for(j=0;j<ma;j++)
+        {
+            if(A[i][j]!=B[i][j])
+            {
+                    out=1;
+            }
+        }
+    }
+   return out;
+}
 
-extern int debug;
+ extern int debug;
Index: branch/leng/sp4a3/sp4a3_kalman.c
===================================================================
--- branch/leng/sp4a3/sp4a3_kalman.c	(revision 280)
+++ branch/leng/sp4a3/sp4a3_kalman.c	(revision 281)
@@ -1,38 +1,75 @@
 //  Pour compiler : gcc sp4a3_kalman.c  -lm
-
 #include <stdlib.h>
 #include <stdio.h>
 #include <math.h>
 
-#include "sp4a3_kalman_extra.h"
+#include "sp4a3_kalman_extra.c"
+
 
-
-void Add_Mat_Mat(int na,int ma,double A[na][ma],int nb,int mb,double b[nb][mb], double out[na][ma]){
-
+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<mb;j++)
+        {
+            out[i][j]=A[i][j]+B[i][j];
+        }
 }
 
 void Inverse_Mat_22(int n,int m,double A[n][m],double B[n][m]){
-
+B[0][0]=-A[1][1]/(A[1][0]*A[0][1]+A[1][1]*A[0][0]);
+B[0][1]=1/(A[1][0]-A[1][1]*A[0][0]/A[0][1]);
+B[1][0]=1/(A[0][1]+A[1][1]*A[0][0]/A[1][0]);
+B[1][1]=-A[0][0]/(A[0][1]*A[1][0]-A[1][1]*A[0][0]);
 }
 
 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];
+        }
+    }
 }
 
-void Sub_Mat_Mat(int na,int ma,double A[na][ma],int nb,int mb,double b[nb][mb], double out[na][ma]){
-
+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<mb;j++)
+        {
+            out[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 out[na][mb]){
-
+int i,j;
+    for (i=0;i<na;i++)
+    {
+        for(j=0;j<mb;j++)
+        {
+            out[i][j]=A[i][j]*B[i][j];
+
+        }
+
+    }
 }
 
 
 
-void tests_unitaires(void){
+void tests_unitaires(void){
+    //matrices preparation
+    double test[2][2]={{0,0},{0,0}};
+     double A22[2][2]={{21,21},{3,0}};
+      double B22[2][2]={{18,13},{63,3}};
+    double C22a[2][2]={{39,34},{66,3}};
+     double C22b[2][2]={{3,8},{-60,-3}};
+      double C22c[2][2]={{1701,336},{54,39}};
+       double C22d[2][2]={{21,3},{21,0}};
 	//Matrices d'entrée
 	double T21a[2][1]={{7},{-5}};
 	double T21b[2][1]={{-3},{46}};
@@ -67,25 +104,31 @@
 	double RST44[4][4]={{-11,-11,-7,-11},{-15,-17,-16,-32},{-69,-37,-5,3},{-49,-6,-9,-45}};
 	double RMT44T44[4][4]={{816,412,192,304},{1155,583,379,687},{1146,668,466,758},{486,308,222,338}};
 
-	printf("Execution des tests unitaires.\n");
-	Transpose_Mat(2,4,T24,R42);		if (!Equal_Mat_Mat(RTT24,R42)) 		error("Erreur calcul Transposition 2x4");
-	Transpose_Mat(4,4,T44a,R44);	if (!Equal_Mat_Mat(RTT44,R44)) 		error("Erreur calcul Transposition 4x4");
-	Inverse_Mat_22(2,2,T22a,R22);	if (!Equal_Mat_Mat(RInvT22,R22)) 	error("Erreur calcul Inversion 2x2");
-	Add_Mat_Mat(2,2,T22a,2,2,T22b,R22);	if (!Equal_Mat_Mat(RAT22,R22)) 		error("Erreur calcul Addition 2x2");
-	Add_Mat_Mat(4,4,T44a,4,4,T44b,R44);	if (!Equal_Mat_Mat(RAT44,R44)) 		error("Erreur calcul Addition 4x4");
-	Add_Mat_Mat(4,1,T41a,4,1,T41b,R41);	if (!Equal_Mat_Mat(RAT41,R41)) 		error("Erreur calcul Addition 4x1");
-	Sub_Mat_Mat(2,1,T21a,2,1,T21b,R21);	if (!Equal_Mat_Mat(RST21,R21)) 		error("Erreur calcul Soustraction 2x1");
-	Sub_Mat_Mat(4,4,T44a,4,4,T44b,R44);	if (!Equal_Mat_Mat(RST44,R44)) 		error("Erreur calcul Soustraction 4x4");
-	Mul_Mat_Mat(4,4,T44a,4,4,T44b,R44);	if (!Equal_Mat_Mat(RMT44T44,R44)) 	error("Erreur calcul Multiplication 4x4 4x4");
-	Mul_Mat_Mat(4,4,T44a,4,1,T41a,R41);	if (!Equal_Mat_Mat(RMT44T41,R41)) 	error("Erreur calcul Multiplication 4x4 4x1");
-	Mul_Mat_Mat(4,4,T44a,4,2,T42a,R42);	if (!Equal_Mat_Mat(RMT44T42,R42)) 	error("Erreur calcul Multiplication 4x4 4x2");
-	Mul_Mat_Mat(4,2,T42a,2,1,T21a,R41);	if (!Equal_Mat_Mat(RMT42T21,R41)) 	error("Erreur calcul Multiplication 4x2 2x1");
-	Mul_Mat_Mat(4,2,T42a,2,2,T22a,R42);	if (!Equal_Mat_Mat(RMT42T22,R42)) 	error("Erreur calcul Multiplication 4x2 2x2");
-	Mul_Mat_Mat(4,2,T42a,2,4,T24,R44);	if (!Equal_Mat_Mat(RMT42T24,R44)) 	error("Erreur calcul Multiplication 4x2 2x4");
-	Mul_Mat_Mat(2,4,T24,4,1,T41a,R21);	if (!Equal_Mat_Mat(RMT24T41,R21)) 	error("Erreur calcul Multiplication 2x4 4x1");
-	Mul_Mat_Mat(2,4,T24,4,2,T42a,R22);	if (!Equal_Mat_Mat(RMT24T42,R22)) 	error("Erreur calcul Multiplication 2x4 4x2");
-	Mul_Mat_Mat(2,4,T24,4,4,T44a,R24);	if (!Equal_Mat_Mat(RMT24T44,R24)) 	error("Erreur calcul Multiplication 2x4 4x4");
-	printf("Test unitaires OK.\n");
+	printf("Execution des tests unitaires.\n");
+	Equal_Mat_Mat(R42,R42); if (!_Equal_Mat_Mat(4,2,R42,4,2,R42)) 		error("Erreur calcul Egalite 2x4");
+	Equal_Mat_Mat(T24,R42); if (!_Equal_Mat_Mat(2,4,T24,4,2,R42))        error("Erreur calcul Egalite 2x4");
+	Transpose_Mat(2,4,T24,R42);		if (!_Equal_Mat_Mat(2,4,RTT24,4,2,R42)) 		error("Erreur calcul Transposition 2x4");
+	Transpose_Mat(4,4,T44a,R44);	if (!_Equal_Mat_Mat(4,4,RTT44,4,4,R44)) 		error("Erreur calcul Transposition 4x4");
+	Inverse_Mat_22(2,2,T22a,R22);	if (!_Equal_Mat_Mat(2,2,RInvT22,2,2,R22)) 	error("Erreur calcul Inversion 2x2");
+	Add_Mat_Mat(2,2,T22a,2,2,T22b,R22);	if (!_Equal_Mat_Mat(2,2,RAT22,2,2,R22)) 		error("Erreur calcul Addition 2x2");
+	Add_Mat_Mat(4,4,T44a,4,4,T44b,R44);	if (!_Equal_Mat_Mat(4,4,RAT44,4,4,R44)) 		error("Erreur calcul Addition 4x4");
+	Add_Mat_Mat(4,1,T41a,4,1,T41b,R41);	if (!_Equal_Mat_Mat(4,1,RAT41,4,1,R41)) 		error("Erreur calcul Addition 4x1");
+	Sub_Mat_Mat(2,1,T21a,2,1,T21b,R21);	if (!_Equal_Mat_Mat(2,1,RST21,2,1,R21)) 		error("Erreur calcul Soustraction 2x1");
+	Sub_Mat_Mat(4,4,T44a,4,4,T44b,R44);	if (!_Equal_Mat_Mat(4,4,RST44,4,4,R44)) 		error("Erreur calcul Soustraction 4x4");
+	Mul_Mat_Mat(4,4,T44a,4,4,T44b,R44);	if (!_Equal_Mat_Mat(4,4,RMT44T44,4,4,R44)) 	error("Erreur calcul Multiplication 4x4 4x4");
+	Mul_Mat_Mat(4,4,T44a,4,1,T41a,R41);	if (!_Equal_Mat_Mat(4,1,RMT44T41,4,1,R41)) 	error("Erreur calcul Multiplication 4x4 4x1");
+	Mul_Mat_Mat(4,4,T44a,4,2,T42a,R42);	if (!_Equal_Mat_Mat(4,4,RMT44T42,4,2,R42)) 	error("Erreur calcul Multiplication 4x4 4x2");
+	Mul_Mat_Mat(4,2,T42a,2,1,T21a,R41);	if (!_Equal_Mat_Mat(4,2,RMT42T21,4,1,R41)) 	error("Erreur calcul Multiplication 4x2 2x1");
+	Mul_Mat_Mat(4,2,T42a,2,2,T22a,R42);	if (!_Equal_Mat_Mat(4,2,RMT42T22,4,2,R42)) 	error("Erreur calcul Multiplication 4x2 2x2");
+	Mul_Mat_Mat(4,2,T42a,2,4,T24,R44);	if (!_Equal_Mat_Mat(4,2,RMT42T24,4,4,R44)) 	error("Erreur calcul Multiplication 4x2 2x4");
+	Mul_Mat_Mat(2,4,T24,4,1,T41a,R21);	if (!_Equal_Mat_Mat(4,1,RMT24T41,2,1,R21)) 	error("Erreur calcul Multiplication 2x4 4x1");
+	Mul_Mat_Mat(2,4,T24,4,2,T42a,R22);	if (!_Equal_Mat_Mat(4,2,RMT24T42,2,2,R22)) 	error("Erreur calcul Multiplication 2x4 4x2");
+	Mul_Mat_Mat(2,4,T24,4,4,T44a,R24);	if (!_Equal_Mat_Mat(4,4,RMT24T44,2,4,R24)) 	error("Erreur calcul Multiplication 2x4 4x4");
+	printf("Test unitaires OK.\n");
+	printf("Execution des tests unitaires des calculs matriciels.\n");
+	Add_Mat_Mat(2,2,A22,2,2,B22,test);
+	Plot_Mat(test,"A+B=");
+	printf("Tests unitaires des calculs matriciels OK.\n");
 }
 
 int main(int argc,char **argv){
@@ -107,7 +150,7 @@
 	double oldx,oldy;
 	double dx=0,dy=0,dt=0.1;
 	int cpt = 0;
-
+    int debug=0;
 	// kalman param
 	double sigma_etat = 10.0;
 	double sigma_observation = 2.0;
@@ -126,7 +169,12 @@
 	double R[2][2] = 	{{sigma_observation*sigma_observation, 0},
 						 {0 , sigma_observation*sigma_observation}};
 
-	double K[4][2];
+	double K[4][2];
+	double Ktemp[4][2];
+	double Res[4][4]= {{0, 0, 0, 0},
+						 {0, 0, 0, 0},
+						 {0, 0, 0, 0},
+						 {0, 0, 0, 0}};
 	double H[2][4] = 	{{1, 0, 0, 0},
 						 {0, 1, 0, 0}};
 	double HT[4][2];
@@ -156,24 +204,46 @@
 
 			debug=0; ///Mettre à 1 pour afficher les matrices.
 			///Ajouter votre code ci-dessous///
-			// Kalman
+			// Kalman
+			///prediction
+            X=Mul_Mat_Mat(4,1,X,4,4,F,Res);
+
+            // X = F*X
+			Plot_Mat(X," X(k+1|k) = ");
+
+
+            P=Mul_Mat_Mat(4,4,F,4,4,P,Res);
+            P=Mul_Mat_Mat(4,4,P,4,4,FT,Res);
+            P=Add_Mat_Mat(4,4,P,4,4,Q,Res);
+
+            //P = F*P*F'+Q;
+			Plot_Mat(P,"P(k+1|k) = F.P(k|k).FT + Q = ");
+
+            ///gain
+            K=Mul_Mat_Mat(4,4,P,2,4,HT,Res);
+            Ktemp=Mul_Mat_Mat(2,4,H,4,4,P,Res);
+            Ktemp=Mul_Mat_Mat(4,2,Ktemp,2,4,HT,Res);
+            Ktemp=Inverse_Mat_22(2,2,Add_Mat_Mat(4,2,Ktemp,2,2,R),Res);
+
+            // K = P*H' / ( H*P*H' + R);
+			Plot_Mat(K,"K = ");
+            ///mise a jour recursive
+            X=Add_Mat_Mat(4,1,X,4,1,Mul_Mat_Mat(4,2,K,2,1,delta,Res));
+
+            //X = X + K*([xb(i);yb(i)]-H*X);
+			//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=Sub_Mat_Mat(4,4,P,4,4,Mul_Mat_Mat(4,4,Mul_Mat_Mat(4,2,K,2,4,H,Res),4,4,P,Res));
+
+            // P = P - K*H*P;
+            Plot_Mat(P," P(k+1|k+1) = P(k+1|k) - K.H.P(k+1|k) = ");
+
+            delta=Sub_Mat_Mat(2,1,Mul_Mat_Mat(4,1,X,2,4,H,Res),2,1,Mul_Mat_Mat(2,4,H,4,1,X,Res)));
+
 
-			// X = F*X
-			Plot_Mat(X," X(k+1|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);
-			Plot_Mat(K,"K = ");
-
-			//X = X + K*([xb(i);yb(i)]-H*X);
-			//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;
-            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 ///
 		}
 		t = cpt * dt;
