diff --git a/README.md b/README.md index ca7325f..22d7a38 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,11 @@ # EulerMethod A repository for the implementation of the Euler method +Program uses. +-main.c +-funciones.c +-funciones.h +-tipo.h +both .h are included in main.c +gcc -o main.exe main.c funciones.c +Grafica.dat is with "2" in ecuation +Graphic.dat is with "0.2" in ecuation diff --git a/TDA_P1_v1.pdf b/TDA_P1_v1.pdf new file mode 100644 index 0000000..84b6b20 Binary files /dev/null and b/TDA_P1_v1.pdf differ diff --git a/TDA_P1_v2.pdf b/TDA_P1_v2.pdf new file mode 100644 index 0000000..dd729d1 Binary files /dev/null and b/TDA_P1_v2.pdf differ diff --git a/TDA_P1_v3.pdf b/TDA_P1_v3.pdf new file mode 100644 index 0000000..3f27e95 Binary files /dev/null and b/TDA_P1_v3.pdf differ diff --git a/d b/d new file mode 100644 index 0000000..741b1f2 --- /dev/null +++ b/d @@ -0,0 +1,48 @@ +commit e69cad06c35d7b656e5830de62e7f1f4a81b0963 (HEAD -> Students) +Author: CASTRO BOUQUET ILDEFONSO +Date: Thu Oct 1 11:21:25 2020 -0500 + + English Traduction, added function for resolving ecuation, executable added, prueba.c isn't part of programm just for tests, graphic.dat is now the output of the program. + +commit 30348dc829359c4c53bec2b9eb1a29885f5fea35 +Author: CASTRO BOUQUET ILDEFONSO +Date: Sun Sep 27 20:01:33 2020 -0500 + + First Commit + +commit 8d31a53dbeeb1f428b8d86b31999a4a2108ab0fc (origin/Students, origin/HEAD) +Merge: a313d56 2dff68b +Author: Cesar Angeles <36006369+CesarAng28@users.noreply.github.com> +Date: Sat Sep 26 10:52:56 2020 -0500 + + Merge pull request #3 from DavidEPA2001/Students + + Add files via upload + +commit a313d56d9bd20bc569d78bcbcd9746757765350b +Author: Cesar Angeles +Date: Fri Sep 25 14:50:29 2020 -0500 + + removed example file + +commit 2dff68be77193a4fde9c0ac771360e9d5d3f1a12 +Author: DavidEPA2001 <70725973+DavidEPA2001@users.noreply.github.com> +Date: Thu Sep 24 23:38:21 2020 -0500 + + Add files via upload + + PDF introduccion + +commit ca580d80f96be5fa25d9b61a37539df9eef66095 +Author: Cesar Angeles +Date: Thu Sep 24 17:37:16 2020 -0500 + + Added Doc.docx + +commit 904bfe742f02b876ebf703de621df0221b469fd9 (origin/master) +Author: Cesar Angeles <36006369+CesarAng28@users.noreply.github.com> +Date: Tue Sep 22 11:07:14 2020 -0500 + + Create README.md + + Added README file diff --git a/funciones.c b/funciones.c new file mode 100644 index 0000000..6682656 --- /dev/null +++ b/funciones.c @@ -0,0 +1,154 @@ +// +// funciones.c +// +// +// Created by Castro Bouquet Ildefonso on 27/09/2020. +// Created by Venegas Ramirez Giovanni Josue on 27/09/2020. +// + +/* Libraries */ +#include +#include + +#include"tipo.h" + +/* funciones.c -- Functions */ + +/** +*This function generates a menu for the program, asking if user wants to set values or use the predetermined. +* +*@param +* datos(DATOS *) +* +*/ +void menu(DATOS *datos) +{ + float x; + do + { + printf("====================================================\n"); + printf("= MENU =\n"); + printf("=1) Set values for Dt, Weight, K or cuantity =\n"); + printf("=2) Calculate Graphic =\n"); + printf("= =\n"); + printf("====================================================\n"); + printf("Input an option: "); + scanf("%f",&x); + if((x!=1)&&(x!=2)) + { + printf("Thats not a valid value.\n"); + } + if(x==2) + { + return; + } + if(x == 1) + { + do + { + printf("Insert value for Dt (s):"); + scanf("%f",&datos->delta); + if(datos->delta<=0) + { + printf("Value out of range (>0-infinity)\n"); + } + }while(datos->delta<=0); + do + { + printf("Introduce weight value (kg):"); + scanf("%f",&datos->masa); + if(datos->masa<=0) + { + printf("Value out of range (>0-infinity)\n"); + } + }while(datos->masa<=0); + do + { + printf("Introduce value for k constant of the bongee(N/m^2):"); + scanf("%f",&datos->k); + if(datos->k<=0) + { + printf("Value out of range (>0-infinity)\n"); + } + }while(datos->k<=0); + do + { + printf("Introduce how many dots are going to be calculated:"); + scanf("%d",&datos->cantDelta); + if(datos->cantDelta<=0) + { + printf("Value out of range (>0-infinity)\n"); + } + }while(datos->cantDelta<=0);//es el valor del for, quiero 15 medidas, osea de x hasta x+15deltas + } + }while(x!=2); +} + +/** +*This function creates a file and saves the location on a variable. +* +*@param +* file(FILE *) +*@returns +* 0 if cant create a file +* 1 if file had been created corretly +*/ +int CreateFile(FILE **file) +{ + *file=fopen("graphic.dat","w"); + if(*file==NULL) + { + return 0; + } + else + { + return 1; + } +} + +/** +*This function takes the array and print the information from it to the file. +* +*@param +* files(FILE *) +* array[][](float *) +* +*/ +void FillFile(FILE *file,float array[][2],DATOS *datos) +{ + int i; + for(i=0;icantDelta;i++) + { + fprintf(file,"%f, %f\n",array[i][0],array[i][1]); + } +} + +/** +*This function takes the variables and replace them in the main ecuation, solve it, and save the results in the array. +* +*@param +* datos(DATOS *) +* array[][](float *) +* +*/ +void DesarrolloEcuacion(DATOS *datos,float array[][2]) +{ + float t,n; + int i; + t=0; + for (i=0; icantDelta; i++) + { + if(i==0) + { + array[i][1]=10; + array[i][0]= t; //time value + array[i+1][1]=10; + } + if(i>=1) + { + array[i+1][1]=0-(array[i-1][1])*((1)+(((datos->k)*(datos->delta)*(datos->delta))/datos->masa))+(0.2)*(array[i][1])*(datos->delta)+(datos->delta)*(datos->delta)*9.81;/*agregar 0.2*/ + } + t=t+datos->delta; + array[i+1][0]= t; //time value + } +} \ No newline at end of file diff --git a/funciones.h b/funciones.h new file mode 100644 index 0000000..52489d1 --- /dev/null +++ b/funciones.h @@ -0,0 +1,65 @@ +// +// funciones.h +// +// +// Created by Castro Bouquet Ildefonso on 27/09/2020. +// Created by Venegas Ramirez Giovanni Josue on 27/09/2020. +// +#ifndef funciones_h +#define funciones_h + +#include + +#ifdef funciones_IMPORT + #define EXTERN +#else + #define EXTERN extern +#endif + +/* funciones.h -- Function prototypes */ + +/** +*This function generates a menu for the program, asking if user wants to set values or use the predetermined. +* +*@param +* datos(DATOS *) +* +*/ +EXTERN void menu(DATOS *datos); + +/** +*This function creates a file and saves the location on a variable. +* +*@param +* file(FILE *) +*@returns +* 0 if cant create a file +* 1 if file had been created corretly +*/ +EXTERN int CreateFile(FILE **file); + +/** +*This function takes the array and print the information from it to the file. +* +*@param +* files(FILE *) +* array[][](float *) +* +*/ +EXTERN void FillFile(FILE *file,float array[][2],DATOS *datos); + +/** +*This function takes the variables and replace them in the main ecuation, solve it, and save the results in the array. +* +*@param +* datos(DATOS *) +* array[][](float *) +* +*/ +EXTERN void DesarrolloEcuacion(DATOS *datos,float array[][2]); + + +#undef funciones_IMPORT +#undef EXTERN + +#endif /* funciones_h */ diff --git a/grafica.dat b/grafica.dat new file mode 100644 index 0000000..307057b --- /dev/null +++ b/grafica.dat @@ -0,0 +1,100 @@ +0.000000, 10.000000 +0.100000, 10.000000 +0.200000, -9.785233 +0.300000, -10.180938 +0.400000, 9.761258 +0.500000, 10.559104 +0.600000, -9.533319 +0.700000, -10.739663 +0.800000, 9.496070 +0.900000, 11.117182 +1.000000, -9.254760 +1.100000, -11.296820 +1.200000, 9.204046 +1.300000, 11.673141 +1.400000, -8.949183 +1.500000, -11.851300 +1.600000, 8.884834 +1.700000, 12.225858 +1.800000, -8.616258 +1.900000, -12.401965 +2.000000, 8.538120 +2.100000, 12.774178 +2.200000, -8.255688 +2.300000, -12.947642 +2.400000, 8.163632 +2.500000, 13.316912 +2.600000, -7.867225 +2.700000, -13.487130 +2.799999, 7.761142 +2.899999, 13.852845 +2.999999, -7.450662 +3.099999, -14.019198 +3.199999, 7.330467 +3.299999, 14.380734 +3.399999, -7.005839 +3.499999, -14.542591 +3.599999, 6.871469 +3.699999, 14.899308 +3.799999, -6.532646 +3.899998, -15.056022 +3.999998, 6.384064 +4.099998, 15.407269 +4.199998, -6.031019 +4.299998, -15.558184 +4.399998, 5.868214 +4.499998, 15.903299 +4.599998, -5.500949 +4.699998, -16.047747 +4.799998, 5.323936 +4.899998, 16.386057 +4.999998, -4.942480 +5.099998, -16.523357 +5.199997, 4.751300 +5.299997, 16.854179 +5.399997, -4.355711 +5.499997, -16.983644 +5.599997, 4.150435 +5.699997, 17.306284 +5.799997, -3.740797 +5.899997, -17.427217 +5.999997, 3.521525 +6.099997, 17.740976 +6.199996, -3.097952 +6.299996, -17.852676 +6.399996, 2.864815 +6.499996, 18.156843 +6.599996, -2.427451 +6.699996, -18.258598 +6.799996, 2.180608 +6.899996, 18.552465 +6.999996, -1.729630 +7.099996, -18.643562 +7.199996, 1.469272 +7.299995, 18.926411 +7.399995, -1.004888 +7.499995, -19.006128 +7.599995, 0.731240 +7.699995, 19.277237 +7.799995, -0.253689 +7.899995, -19.344852 +7.999995, -0.032994 +8.099995, 19.603500 +8.199995, 0.523439 +8.299995, -19.658295 +8.399996, -0.822867 +8.499996, 19.903755 +8.599997, 1.325900 +8.699997, -19.945002 +8.799997, -1.637749 +8.899998, 20.176556 +8.999998, 2.153028 +9.099998, -20.203533 +9.199999, -2.476940 +9.299999, 20.420456 +9.400000, 3.004091 +9.500000, -20.432444 +9.600000, -3.339673 +9.700001, 20.634022 +9.800001, 3.878284 +9.900002, -20.630306 diff --git a/graphic.dat b/graphic.dat new file mode 100644 index 0000000..4830dc1 --- /dev/null +++ b/graphic.dat @@ -0,0 +1,100 @@ +0.000000, 10.000000 +0.100000, 10.000000 +0.200000, -10.535233 +0.300000, -10.945939 +0.400000, 11.292351 +0.500000, 12.182048 +0.600000, -11.891640 +0.700000, -13.336951 +0.800000, 12.713971 +0.900000, 14.800744 +1.000000, -13.379354 +1.100000, -16.203627 +1.200000, 14.268329 +1.300000, 17.937397 +1.400000, -15.000508 +1.500000, -19.634090 +1.600000, 15.955970 +1.700000, 21.687485 +1.800000, -16.753786 +1.900000, -23.731752 +2.000000, 17.773399 +2.100000, 26.162968 +2.200000, -18.633158 +2.300000, -28.617779 +2.400000, 19.711664 +2.500000, 31.494926 +2.600000, -20.626305 +2.700000, -34.433929 +2.799999, 21.754585 +2.899999, 37.836617 +2.999999, -22.712637 +3.099999, -41.345821 +3.199999, 23.876541 +3.299999, 45.366940 +3.399999, -24.860813 +3.499999, -49.546635 +3.599999, 26.039717 +3.699999, 54.294415 +3.799999, -27.025705 +3.899998, -59.261364 +3.999998, 28.190722 +4.099998, 64.861725 +4.199998, -29.144615 +4.299998, -70.751663 +4.399998, 30.256401 +4.499998, 77.350868 +4.599998, -31.132650 +4.699998, -84.321327 +4.799998, 32.138714 +4.899998, 92.088982 +4.999998, -32.877060 +5.099998, -100.322510 +5.199997, 33.708466 +5.299997, 109.454994 +5.399997, -34.230305 +5.499997, -119.162758 +5.599997, 34.797676 +5.699997, 129.887039 +5.799997, -35.001644 +5.899997, -141.312897 +5.999997, 35.190292 +6.099997, 153.890884 +6.199996, -34.946899 +6.299996, -167.315979 +6.399996, 34.610924 +6.499996, 182.049301 +6.599996, -33.756084 +6.699996, -197.797104 +6.799996, 32.711250 +6.899996, 215.032516 +6.999996, -31.038441 +7.099996, -233.474579 +7.199996, 29.053585 +7.299995, 253.609970 +7.399995, -26.304419 +7.499995, -275.172119 +7.599995, 23.091112 +7.699995, 298.663086 +7.799995, -18.944012 +7.899995, -323.832489 +7.999995, 14.144131 +8.099995, 351.199524 +8.199995, -8.200719 +8.299995, -380.532074 +8.399996, 1.371571 +8.499996, 412.368622 +8.599997, 6.859604 +8.699997, -446.497406 +8.799997, -16.263086 +8.899998, 483.478363 +8.999998, 27.386011 +9.099998, -523.122437 +9.199999, -40.032528 +9.299999, 566.013428 +9.400000, 54.786942 +9.500000, -611.987366 +9.600000, -71.494171 +9.700001, 661.654541 +9.800001, 90.783211 +9.900002, -714.878662 diff --git a/main.c b/main.c new file mode 100644 index 0000000..141bf9c --- /dev/null +++ b/main.c @@ -0,0 +1,52 @@ +// +// main.c +// +// +// Created by Castro Bouquet Ildefonso on 27/09/2020. +// Created by Venegas Ramirez Giovanni Josue on 27/09/2020. +// + +/* Libraries */ +#include +#include + +/* Custom Libraries */ +#include"tipo.h" +#include"funciones.h" + +/* Main */ +int main(void) +{ + system("clear"); + int i; + FILE *file,*gnu_socket; + DATOS datos; + /*Predetermined values, set by the problem, can be changed from menu function*/ + datos.delta=0.1; + datos.masa=60; + datos.k=500; + datos.cantDelta=100; + /**/ + menu(&datos); + float array[datos.cantDelta][2]; + DesarrolloEcuacion(&datos,array); + i=CreateFile(&file); + if(i==0)/*Validate if file cant be created*/ + { + printf("ERROR File couldnt me created\n"); + exit(1); + } + FillFile(file,array,&datos); + if(i==1) + { + fclose(file); + } + char *nombre="graphic"; + gnu_socket=popen("gnuplot -persist","w"); + fprintf(gnu_socket,"plot \"%s.dat\" using 1:2 with lines\n",nombre);/*Command for calling gnuplot internally*/ + pclose(gnu_socket); + /*for(i=0;i +#include + +/* Variables */ +typedef struct DATOS +{ + float delta,masa,k; + int cantDelta; +}DATOS; \ No newline at end of file