Added the derivative + graph is responsive
This commit is contained in:
@@ -3,7 +3,7 @@ I was bored so i made this tool, it allows you to calculate :
|
||||
* the delta
|
||||
* x1, x2, x0
|
||||
* vertex coordinates
|
||||
* Drawing the graph
|
||||
* Drawing the graph of the function and its derivative
|
||||
|
||||
The names of the functions/variables are in French, uhh use google translate to read the code i guess, sorry for that.
|
||||
|
||||
|
||||
77
polynome.c
77
polynome.c
@@ -52,7 +52,7 @@ enum STATUS Calcul_Sommet(Poly* poly) {
|
||||
}
|
||||
|
||||
enum STATUS Calcul_Fonction(Poly* poly, float x, float *out) {
|
||||
if (poly == NULL) {
|
||||
if (poly == NULL || out == NULL) {
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
@@ -60,23 +60,47 @@ enum STATUS Calcul_Fonction(Poly* poly, float x, float *out) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
enum STATUS Calcul_Derivee(Poly* poly, float x, float *out) {
|
||||
//f'(x)=2ax+b
|
||||
|
||||
if (poly == NULL || out == NULL) {
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
*out = (2 * poly->a * x) + poly->b;
|
||||
return OK;
|
||||
}
|
||||
|
||||
void Dessiner_Separateur() {
|
||||
printf("+-----+");
|
||||
for (int i = 0; i <= LONGUEUR_X*2; i++) {
|
||||
if (i == LONGUEUR_X) {
|
||||
printf("--+-");
|
||||
}
|
||||
else {
|
||||
printf("----");
|
||||
}
|
||||
}
|
||||
printf("-+\n");
|
||||
}
|
||||
|
||||
enum STATUS Dessiner_Graph(Poly* poly) {
|
||||
if (poly == NULL) {
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
printf("+-----+---------------------------------------------+\n");
|
||||
Dessiner_Separateur();
|
||||
for (int j = LONGUEUR_Y; j >= -LONGUEUR_Y; j--) {
|
||||
|
||||
if (j == -10) {
|
||||
if (j < -9) {
|
||||
printf("| %d | ",j);
|
||||
}
|
||||
else if (j == 10 || j < 0) {
|
||||
else if (j > 9 || j < 0) {
|
||||
printf("| %d | ",j);
|
||||
}
|
||||
else if (j == 0) {
|
||||
printf("| %d |--",j);
|
||||
printf("| %d |-",j);
|
||||
}
|
||||
else {
|
||||
printf("| %d | ",j);
|
||||
@@ -84,12 +108,7 @@ enum STATUS Dessiner_Graph(Poly* poly) {
|
||||
|
||||
for (int i = -LONGUEUR_X; i <= LONGUEUR_X+1; i++) {
|
||||
if (i > LONGUEUR_X) {
|
||||
if (j == 0) {
|
||||
printf("-|");
|
||||
}
|
||||
else {
|
||||
printf("|");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -98,12 +117,33 @@ enum STATUS Dessiner_Graph(Poly* poly) {
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
float y2;
|
||||
if (Calcul_Derivee(poly, i, &y2) == FAIL) {
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
if (roundf(y) == j) {
|
||||
if (j == 0) {
|
||||
printf("-o--");
|
||||
}
|
||||
else {
|
||||
printf(" o ");
|
||||
}
|
||||
else if (i == 0) {
|
||||
continue;
|
||||
}
|
||||
if (roundf(y2) == j) {
|
||||
if (j == 0) {
|
||||
printf("+-");
|
||||
printf("-u--");
|
||||
}
|
||||
else {
|
||||
printf(" u ");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i == 0) {
|
||||
if (j == 0) {
|
||||
printf("-+--");
|
||||
}
|
||||
else {
|
||||
printf(" : ");
|
||||
@@ -113,20 +153,25 @@ enum STATUS Dessiner_Graph(Poly* poly) {
|
||||
printf(" ");
|
||||
}
|
||||
else {
|
||||
printf("--");
|
||||
printf("----");
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
// | 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10
|
||||
printf("+-----+---------------------------------------------+\n");
|
||||
Dessiner_Separateur();
|
||||
printf("| | ");
|
||||
for (int k = -LONGUEUR_Y; k <= LONGUEUR_Y; k++) {
|
||||
printf("%d ",abs(k));
|
||||
if (k < 10 && k > -10) {
|
||||
printf("00%d ",abs(k));
|
||||
}
|
||||
else if (k < 100 && k > -100) {
|
||||
printf("0%d ",abs(k));
|
||||
}
|
||||
}
|
||||
printf("|\n");
|
||||
printf("+-----+---------------------------------------------+\n");
|
||||
Dessiner_Separateur();
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -23,8 +23,10 @@ enum STATUS Calcul_x1_x2(Poly* poly);
|
||||
enum STATUS Calcul_x0(Poly* poly);
|
||||
enum STATUS Calcul_Sommet(Poly* poly);
|
||||
enum STATUS Calcul_Fonction(Poly* poly, float x, float *out);
|
||||
enum STATUS Calcul_Derivee(Poly* poly, float x, float *out);
|
||||
|
||||
#define LONGUEUR_X 10
|
||||
#define LONGUEUR_Y 10
|
||||
#define LONGUEUR_X 20
|
||||
#define LONGUEUR_Y 20
|
||||
void Dessiner_Separateur();
|
||||
enum STATUS Dessiner_Graph(Poly* poly);
|
||||
int main();
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 33 KiB |
Reference in New Issue
Block a user