Révision 444
Ajouté par Youssef MORSY il y a presque 3 ans
branch/MORSY/sp4a3/sp4a3_kalman.c | ||
---|---|---|
// Pour compiler : gcc sp4a3_kalman.c -lm
|
||
|
||
#include <stdlib.h>
|
||
#include <stdio.h>
|
||
#include <math.h>
|
||
|
||
#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]){
|
||
|
||
// Pour compiler : gcc sp4a3_kalman.c -lm
|
||
|
||
#include <stdlib.h>
|
||
#include <stdio.h>
|
||
#include <math.h>
|
||
|
||
#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]){
|
||
int i,j;
|
||
double l;
|
||
if(na==nb && ma==mb)
|
||
|
||
{
|
||
for (int i = 0; i < na; i++)
|
||
{
|
||
for (int j = 0; j < mb; j++)
|
||
{
|
||
l=A[i][j] + B[i][j];
|
||
R[i][j] = l;
|
||
}
|
||
}
|
||
}
|
||
|
||
else
|
||
|
||
{
|
||
printf("Dimensions trop grandes\n");
|
||
}
|
||
}
|
||
|
||
|
||
void Inverse_Mat_22(int n,int m,double A[n][m],double B[n][m]){
|
||
int i,j,k,l;
|
||
double c,AA[n][m]; //une nouvelle matrice AA prends le meme valeur de la matrice pour ne pas changer les valeurs de la matrce A
|
||
for (int i = 0; i < n; i++)
|
||
{
|
||
for (int j = 0; j < m; j++)
|
||
{
|
||
AA[i][j] = A[i][j];
|
||
}
|
||
}
|
||
k=AA[0][0];
|
||
c=1/(A[0][0]*AA[1][1]-AA[1][0]*AA[0][1]); //calculer le determinant de la matrice AA
|
||
AA[0][0]=AA[1][1]; //calculer la transpose de la comatrice de A
|
||
AA[1][1]=k;
|
||
AA[1][0]=-AA[1][0];
|
||
AA[0][1]=-AA[0][1];
|
||
for (int i = 0; i < n; i++)
|
||
{
|
||
for (int j = 0; j < m; j++)
|
||
{
|
||
B[i][j] = c*AA[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];
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
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;
|
||
if(na==nb && ma==mb)
|
||
{
|
||
for (int i = 0; i < na; i++)
|
||
{
|
||
for (int j = 0; j < mb; j++)
|
||
{
|
||
R[i][j] = A[i][j] - B[i][j]; // faire la soustraction membre a membre de
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
printf("Dimensions trop grandes\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,l;
|
||
if(ma==nb){ // pour multiplier deux matrice il faut que nb de ligne de matrice a= nb de colonnes du matrice b
|
||
for (int i = 0; i < na; i++)
|
||
{
|
||
for (int j = 0; j < mb; j++)
|
||
{
|
||
R[i][j] = 0;
|
||
for (int l = 0; l < ma; l++)
|
||
{
|
||
R[i][j] += A[i][l] * B[l][j]; // multiplication ligne*colonne
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
else{
|
||
printf("Dimensions trop grandes\n");
|
||
|
||
}
|
||
}
|
||
|
||
void Inverse_Mat_22(int n,int m,double A[n][m],double B[n][m]){
|
||
|
||
}
|
||
|
||
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 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 tests_unitaires(void){
|
||
//Matrices d'entrée
|
||
double T21a[2][1]={{7},{-5}};
|
Formats disponibles : Unified diff
implantation add,sum,invrse,sub