diff --git a/Euler.c b/Euler.c new file mode 100644 index 0000000..60efc29 --- /dev/null +++ b/Euler.c @@ -0,0 +1,107 @@ +#include +#include +#include + +#include "Euler.h" + +int euler_menu (float *k, float *m, float *position1, float *position2, float *dt, float *t){ + + int opcion; + do{ + printf("Calculo de salto bungee con método de Euler.\n\n"); + printf ("Bienvenido. Favor de ingresar los datos.\n"); + printf("1. Ingresar la constante del Bongee (k): \n"); + printf("2. Ingresar la masa de la persona (m): \n"); + printf("3. Ingresar la posicion inicial (Xo): \n"); + printf("4. Ingresar la diferencia de tiempo (dt): \n"); + printf("5. Ingresar el tiempo a medir (t): \n"); + printf("6. Calcular y salir. (Es necesario ingresar primero todos los datos)\n"); + printf("7. Salir.\n"); + printf("Opcion: "); + scanf ("%d", &opcion); + + switch (opcion){ + case 1: + printf("k = "); + scanf("%f",k); + break; + case 2: + printf("m = "); + scanf("%f",m); + break; + case 3: + printf("Xo = "); + scanf("%f",position1); + *position2 = *position1; + break; + case 4: + printf("dt = "); + scanf("%f",dt); + printf("Regresar? [S/*] "); + break; + case 5: + printf("t = "); + scanf("%f",t); + break; + case 7: + printf("Saliendo...\n"); + exit(1); + break; + default: + if(opcion != 6) + printf("Opcion invalida.\n"); + break; + }//switch + + }while (opcion != 6); + return 0; +} + +void euler_print (float position, float time) +{ + printf("position: %f\t",position); + printf("time: %f\n",time); +} + +float euler_form (float k, float m, const double g, float position1, float position2, float dt){ + float position; + float p1 = (-1*position1)*(1+((k*(dt*dt))/m)); + float p2 = 2 * position2; + float p3 = (dt*dt)*g; + position=p1+p2+p3; + return position; +} + +int euler_list (float position, conditions **first, float time){ + conditions *node, *aux; + node= (conditions*) malloc (sizeof (conditions)); + if (node==NULL){ + printf ("No se asigno el espacio en memoria.\n"); + exit (0); + } + node->position=position; + node->time = time; + node->sig=NULL; + + if (*first==NULL){ + *first=node; + } + else{ + aux = *first; + while (aux->sig != NULL) + aux = aux->sig; + aux->sig = node; + } + return 0; +} + +int euler_free (conditions *first){ + conditions *aux; + aux=first; + while (aux != NULL){ + first=first->sig; + free (aux); + aux=first; + } + return 0; +} diff --git a/Euler.h b/Euler.h new file mode 100644 index 0000000..bdae568 --- /dev/null +++ b/Euler.h @@ -0,0 +1,38 @@ +// +// Euler.h +// +// +// Created by Team 3. +// + +#ifndef Euler_h +#define Euler_h + +#include +#include + +typedef struct euler { + float position; + float time; + struct euler *sig; +}conditions; + +#ifdef Euler_IMPORT + #define EXTERN +#else + #define EXTERN extern +#endif + +EXTERN int euler_menu (float *k, float *m, float *position1, float *position2, float *dt, float *t); + +EXTERN void euler_print (float position, float time); + +EXTERN float euler_form (float k, float m, const double g, float position1, float position2, float dt); + +EXTERN int euler_list (float position, conditions **first, float time); + +EXTERN int euler_free (conditions *first); + +#undef Euler_IMPORT +#undef EXTERN +#endif /* Euler_h */ diff --git a/Files.c b/Files.c new file mode 100644 index 0000000..63cfe89 --- /dev/null +++ b/Files.c @@ -0,0 +1,37 @@ +#include +#include + +#include "Euler.h" + +FILE * file_new(char *name, char *mode){ + FILE *fp; + fp = fopen (name, mode); + return fp; +} + +void file_write(FILE * fp, conditions *first){ + conditions *node; + node=first; + while (node != NULL){ + fprintf(fp, "%f,",node->position); + fprintf(fp, "%f\n",node->time); + node = node->sig; + } + fclose (fp); +} + +void gnuplot () { + int i; + char *labels[] = {"set title \"Movimiento\"", + "set ylabel \"Posicion(x)\"", + "set xlabel \"Tiempo(t)\"", + "set grid", + "set datafile separator','", + "set terminal png", + "set output 'Posicion VS Tiempo.png'", + "plot \"datos.csv\" with lines"}; + FILE *VentanaGnuPlot = popen ("gnuplot -persist", "w"); + for (i=0; i<8; i++) + fprintf(VentanaGnuPlot, "%s \n", labels[i]); + pclose (VentanaGnuPlot); +} diff --git a/Files.h b/Files.h new file mode 100644 index 0000000..0719c45 --- /dev/null +++ b/Files.h @@ -0,0 +1,70 @@ +// +// Files.h +// +// +// Created by Team 3. +// + +#ifndef Files_h +#define Files_h + +#include +#include + +#include "Euler.h" + +#ifdef Files_IMPORT + #define EXTERN +#else + #define EXTERN extern +#endif + + +/* Files.h -- Function prototypes */ + +/** + * Instanciates a new file pointer identified via its name and mode. + * @param + * name (char *): + * Name of the file + * mode (char *): + * Mode of file to be opened {r, rb, a, ab, w, wb} + * + * @return FILE * opened_file. +*/ +EXTERN FILE * file_new(char *name, char *mode); + + + +/** + * Writes a dynamic list into a file. + * @param + * file (FILE *): + * Storage file + * first (conditions): + * The first node of the dynamic list + * aux (conditions): + * The auxiliary of the dynamic list + * node (conditions): + * The actual node of the dynamic list + * + * @return void. +*/ +EXTERN void file_write(FILE * file, conditions *first); + +/** + * Opens a gnuplot instance to graphicate the data from a file. + * @param + * name (char *): + * Name of the file + * + * @return void. +*/ +EXTERN void gnuplot (); + +#undef files_IMPORT +#undef EXTERN + + + +#endif /* Files_h */ diff --git a/Implementation b/Implementation new file mode 100644 index 0000000..259345f Binary files /dev/null and b/Implementation differ diff --git a/Implementation.c b/Implementation.c new file mode 100644 index 0000000..fbf3219 --- /dev/null +++ b/Implementation.c @@ -0,0 +1,80 @@ +// +// Implementation.c +// +// +// Created by Team 3. +// +/** +* Our sample program. +* @copyright 2020 by TDA +* @license as you wish +* @author Team 3. +* @version 2020-09-30 +* @file +*/ + + +/* Include standard headers: */ +#include +#include +#include +#include + +/* Include modules header we directly invoke here: */ +#include "Euler.h" +#include "Files.h" + +/*Constants*/ +const double g = 9.81; + +/*Tentativo*/ +//start=clock (); +//