Skip to content
Snippets Groups Projects
Commit a0af03d6 authored by simon.cirilli's avatar simon.cirilli
Browse files

Fonction de tests

parent 1b4cf51e
No related branches found
No related tags found
No related merge requests found
No preview for this file type
...@@ -38,13 +38,26 @@ int main() { ...@@ -38,13 +38,26 @@ int main() {
point p = findBestDroite(v); point p = findBestDroite(v);
printf("Sol Analytique : a: %f b: %f\n",p.x,p.y); printf("Sol Analytique : a: %f b: %f\n",p.x,p.y);
point drt; point drt;
drt.x = 6; drt.x = 6;
drt.y = 6; drt.y = 6;
p = descenteGradient(0.0001,drt,v); p = descenteGradient(0.000001,drt,v);
printf("Sol Numérique : a: %f b: %f\n",p.x,p.y); printf("Sol Numérique : a: %f b: %f\n",p.x,p.y);
//Tests
point drtTest;
drtTest.x = 0;
drtTest.y = 2;
vector vecTest = nuagePoints(drtTest, 30, 0, 20);
p = descenteGradient(0.000001,drtTest,v);
//Très proche de la sol numérique donc peut-être augmenter le bruit
printf("Sol Numérique : a: %f b: %f\n",p.x,p.y);
vector_free(&v); vector_free(&v);
vector_free(&vecTest);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
No preview for this file type
...@@ -37,7 +37,7 @@ point descenteGradient(double precision, point drt, vector pts){ ...@@ -37,7 +37,7 @@ point descenteGradient(double precision, point drt, vector pts){
double oldptx = 0; double oldptx = 0;
double oldpty = 0; double oldpty = 0;
double testSortie=1; double testSortie=1;
double lambda = 0.0001; double lambda = 0.000001;
while(testSortie > precision){ while(testSortie > precision){
gradientx = 0; gradientx = 0;
gradienty = 0; gradienty = 0;
...@@ -56,15 +56,28 @@ point descenteGradient(double precision, point drt, vector pts){ ...@@ -56,15 +56,28 @@ point descenteGradient(double precision, point drt, vector pts){
oldpty = pt.y; oldpty = pt.y;
pt.x = oldptx - (lambda * gradientx); pt.x = oldptx - (lambda * gradientx);
// printf("ptx : %f\n",pt.x);
pt.y = oldpty - (lambda * gradienty); pt.y = oldpty - (lambda * gradienty);
// printf("pty : %f\n",pt.y);
//Sortie //Sortie
testSortie = sqrt(pow(pt.x - oldptx,2) + pow(pt.y - oldpty,2)); testSortie = sqrt(pow(pt.x - oldptx,2) + pow(pt.y - oldpty,2));
// printf("%f\n",testSortie);
} }
return pt; return pt;
} }
vector nuagePoints(point drt, int len, int minP, int maxP){
vector vec;
vector_init(&vec);
srand( time( NULL ) );
double bruit;
point add;
// Il faut prend drt proche de la solution Analytique
for(int i = 0; i < len; i++){
bruit = ((double) rand()*(1-(-1))/(double)RAND_MAX-(-1));
add.x = ((double) rand()*(maxP-minP)/(double)RAND_MAX-minP);
add.y = drt.x * add.x + drt.y + bruit;
vector_push(&vec,add);
}
return vec;
}
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#include <time.h>
#include "vector.h" #include "vector.h"
...@@ -18,4 +19,7 @@ point findBestDroite(vector pts); ...@@ -18,4 +19,7 @@ point findBestDroite(vector pts);
// Numérique // Numérique
point descenteGradient(double precision, point drt, vector pts); point descenteGradient(double precision, point drt, vector pts);
// Tests
vector nuagePoints(point drt, int len, int minP, int maxP);
#endif #endif
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment