Programa Gauss Jordan.

Dependencies:   mbed

Committer:
JavierMarcelo98
Date:
Fri Oct 25 14:20:28 2019 +0000
Revision:
15:9199611a074f
Parent:
14:596a61f27f36
Programa Gauss Jordan.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JasperQM 14:596a61f27f36 1 /* ###########################################################################
JasperQM 14:596a61f27f36 2 ** Archivo : main.c
JasperQM 14:596a61f27f36 3 ** Proyecto : STM32-F103C8_Plantilla
JasperQM 14:596a61f27f36 4 ** Procesador : STM32F103C8
JasperQM 14:596a61f27f36 5 ** Herramienta : Mbed
JasperQM 14:596a61f27f36 6 ** Version : Driver 01.01
JasperQM 14:596a61f27f36 7 ** Compilador : GNU C Compiler
JasperQM 14:596a61f27f36 8 ** Fecha/Hora : 14-07-2015, 11:48, # CodeGen: 0
JasperQM 14:596a61f27f36 9 ** Descripción :
JasperQM 14:596a61f27f36 10 ** Este proyecto muestra la configuracion del uso de la terminal serial
JasperQM 14:596a61f27f36 11 ** This module contains user's application code.
JasperQM 14:596a61f27f36 12 ** Componentes : Serial, etc .
JasperQM 14:596a61f27f36 13 ** Configuraciones : Se puede selecionar entre diferentes velocidades de transmision
JasperQM 14:596a61f27f36 14 ** Autores :
JasperQM 14:596a61f27f36 15 ** ATEAM Development Group:
JasperQM 14:596a61f27f36 16 ** - Antulio Morgado Valle
JavierMarcelo98 15:9199611a074f 17 ** - Marcelo Padron Javier
JasperQM 14:596a61f27f36 18 **
JasperQM 14:596a61f27f36 19 ** Versión : Beta
JasperQM 14:596a61f27f36 20 ** Revisión : A
JasperQM 14:596a61f27f36 21 ** Release : 0
JasperQM 14:596a61f27f36 22 ** Bugs & Fixes :
JasperQM 14:596a61f27f36 23 ** Date : 20/10/2019
JasperQM 14:596a61f27f36 24 ** Added support for Led_RGB
JasperQM 14:596a61f27f36 25 ** 22/09/2018
JasperQM 14:596a61f27f36 26 ** Added LCD Menu, Beta version (with bugs)
JasperQM 14:596a61f27f36 27 **
JasperQM 14:596a61f27f36 28 ** ###########################################################################*/
JasperQM 14:596a61f27f36 29 /*
JasperQM 14:596a61f27f36 30 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
JasperQM 14:596a61f27f36 31 : Includes
JasperQM 14:596a61f27f36 32 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
JasperQM 14:596a61f27f36 33 */
hudakz 0:ab218237069e 34 #include "mbed.h"
JasperQM 14:596a61f27f36 35 #include "stm32f103c8t6.h"
JasperQM 14:596a61f27f36 36 #include "PinNames.h"
JasperQM 14:596a61f27f36 37 #include "Serial.h"
JasperQM 14:596a61f27f36 38 #include "stdio.h"
JasperQM 14:596a61f27f36 39 #include "math.h"
hudakz 12:c24d2c99e2b6 40
JasperQM 14:596a61f27f36 41 /*
JasperQM 14:596a61f27f36 42 :...............................................................................
JasperQM 14:596a61f27f36 43 : Definiciones
JasperQM 14:596a61f27f36 44 :...............................................................................
JasperQM 14:596a61f27f36 45 */
JasperQM 14:596a61f27f36 46 #define on 0 // Estado para boton presionado
JasperQM 14:596a61f27f36 47 #define off 1 // Estado para boton sin presionar
JasperQM 14:596a61f27f36 48 #define hold 2 // Estado para boton mantenido
JasperQM 14:596a61f27f36 49 #define release 3 // Estado para boton liberado
JasperQM 14:596a61f27f36 50 #define FALSE 0 // Estado FASLO
JasperQM 14:596a61f27f36 51 #define TRUE 1 // Estado VERDADERO
JavierMarcelo98 15:9199611a074f 52 #define t 100
JasperQM 14:596a61f27f36 53 /*
JasperQM 14:596a61f27f36 54 +-------------------------------------------------------------------------------
JasperQM 14:596a61f27f36 55 | Configuración de Puertos
JasperQM 14:596a61f27f36 56 +-------------------------------------------------------------------------------
JasperQM 14:596a61f27f36 57 */
JasperQM 14:596a61f27f36 58 // Host Pc terminal Comunication channel
JasperQM 14:596a61f27f36 59 Serial terminal (PA_2,PA_3); //Inicioaliza la comunicacion serial a la PC(RX,TX)
JasperQM 14:596a61f27f36 60 //Serial terminal(USBTX,USBRX,1115200);/TX,RX
JasperQM 14:596a61f27f36 61 /*
JasperQM 14:596a61f27f36 62 +-------------------------------------------------------------------------------
JasperQM 14:596a61f27f36 63 | Variables Globales de Usuario
JasperQM 14:596a61f27f36 64 +-------------------------------------------------------------------------------
JasperQM 14:596a61f27f36 65 */
JasperQM 14:596a61f27f36 66 uint32_t Baud_Rate = 115200 ; // Velocidad de transmision
JasperQM 14:596a61f27f36 67 /*
JasperQM 14:596a61f27f36 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
JasperQM 14:596a61f27f36 69 | Definición de Funciones Prototipo y Rutinas de los Vectores de Interrupción
JasperQM 14:596a61f27f36 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
JasperQM 14:596a61f27f36 71 */
JasperQM 14:596a61f27f36 72 void Setup(void); //Function que inicializa la tarjeta;
JavierMarcelo98 15:9199611a074f 73 void Portada();
JavierMarcelo98 15:9199611a074f 74 void pidedatos();
JavierMarcelo98 15:9199611a074f 75 void mat_imp();
JavierMarcelo98 15:9199611a074f 76 void correjir();
JavierMarcelo98 15:9199611a074f 77 void gaussjordan();
JavierMarcelo98 15:9199611a074f 78 void imprime();
JasperQM 14:596a61f27f36 79 /*
JasperQM 14:596a61f27f36 80 END definitions */
JasperQM 14:596a61f27f36 81 /*
JasperQM 14:596a61f27f36 82 #===============================================================================
JasperQM 14:596a61f27f36 83 |
JasperQM 14:596a61f27f36 84 | P R O G R A M A P R I N C I P A L
JasperQM 14:596a61f27f36 85 |
JasperQM 14:596a61f27f36 86 #===============================================================================
JasperQM 14:596a61f27f36 87 */
JasperQM 14:596a61f27f36 88 int main()
JasperQM 14:596a61f27f36 89 {
JavierMarcelo98 15:9199611a074f 90 Setup(); // Inicialización del sistema
JavierMarcelo98 15:9199611a074f 91 Portada(); //Mandar a llamar a la funcion Portada.
JavierMarcelo98 15:9199611a074f 92 int op;
JavierMarcelo98 15:9199611a074f 93 do
JavierMarcelo98 15:9199611a074f 94 {
JavierMarcelo98 15:9199611a074f 95 pidedatos();
JavierMarcelo98 15:9199611a074f 96 mat_imp();
JavierMarcelo98 15:9199611a074f 97 correjir();
JavierMarcelo98 15:9199611a074f 98 gaussjordan();
JavierMarcelo98 15:9199611a074f 99 imprime();
JavierMarcelo98 15:9199611a074f 100 printf("Quieres otro calculo?n1.Sin0.NonR= ");
JavierMarcelo98 15:9199611a074f 101 op =terminal.getc();
JavierMarcelo98 15:9199611a074f 102 }
JavierMarcelo98 15:9199611a074f 103 while(op>=1);
JavierMarcelo98 15:9199611a074f 104 terminal.printf("nn");
JasperQM 14:596a61f27f36 105 }
JasperQM 14:596a61f27f36 106 /* END main */
JasperQM 14:596a61f27f36 107
JasperQM 14:596a61f27f36 108 /*
JasperQM 14:596a61f27f36 109 ................................................................................
JasperQM 14:596a61f27f36 110 : Rutinas de los Vectores de Interrupción
JasperQM 14:596a61f27f36 111 ................................................................................
JasperQM 14:596a61f27f36 112 */
hudakz 10:4b88be251088 113
JasperQM 14:596a61f27f36 114 /*
JasperQM 14:596a61f27f36 115 ______________________________________________________________________________
JasperQM 14:596a61f27f36 116 |
JasperQM 14:596a61f27f36 117 | Funciones Prototipo
JasperQM 14:596a61f27f36 118 |_______________________________________________________________________________
JasperQM 14:596a61f27f36 119 */
JasperQM 14:596a61f27f36 120 // Las Funciones Prototipo van aquí !
JasperQM 14:596a61f27f36 121 void Setup()
JasperQM 14:596a61f27f36 122 {
JavierMarcelo98 15:9199611a074f 123 terminal.baud(115200);
JavierMarcelo98 15:9199611a074f 124 }
JavierMarcelo98 15:9199611a074f 125 void Portada()//Funcion Portada
JavierMarcelo98 15:9199611a074f 126 {
JavierMarcelo98 15:9199611a074f 127 terminal.printf("\n\r\t\e[1;32m0101 0101 010101 01 10 0101 0101 0101 0101 0101 0101 0101 01 10 0101 0101\e[0m");
JavierMarcelo98 15:9199611a074f 128 terminal.printf("\n\r\t\e[1;32m01 01 01 010 010 01 0 0 1 01 0 1 10 01 010 10 01 0 1\e[0m");
JavierMarcelo98 15:9199611a074f 129 terminal.printf("\n\r\t\e[1;32m0101 0101 01 01 1 10 0101 1 0101 01 0101 10 0101 01 1 10 01 0 1\e[0m");
JavierMarcelo98 15:9199611a074f 130 terminal.printf("\n\r\t\e[1;32m01 01 01 01 10 01 0 0 1 01 0 1 10 01 01 010 01 0 1\e[0m");
JavierMarcelo98 15:9199611a074f 131 terminal.printf("\n\r\t\e[1;32m0101 0101 010101 01 10 0101 0101 0 1 0101 0 1 10 0101 01 10 0101 0101\e[0m");
JavierMarcelo98 15:9199611a074f 132 terminal.printf("\n\n\r\t\e[1;32m \'NUESTROS COLORES VERDE \e[0m\e[1;37mY BLANCO, POR QUE EL\e[0m\e[1;31m ROJO LO LLEVAMOS EN LA SANGRE!!!\'\e[0m\n\n");
JavierMarcelo98 15:9199611a074f 133 terminal.printf("\n\r\t\t\e[1;37m ESCUELA SUPERIOR DE INGENIERIA MECANICA Y ELECTRICA\e[0m");
JavierMarcelo98 15:9199611a074f 134 terminal.printf("\n\n\r\t\t\e[1;37m INGENIERIA EN COMUNICACIONES Y ELECTRONICA\e[0m");
JavierMarcelo98 15:9199611a074f 135 terminal.printf("\n\n\r\t\t\e[1;37m ANALISIS NUMERICO\e[0m");
JavierMarcelo98 15:9199611a074f 136 terminal.printf("\n\n\r\t\t\e[1;37m PROGRAMA GAUSS JORDAN\e[0m");
JavierMarcelo98 15:9199611a074f 137 terminal.printf("\n\n\r\t\t\e[1;37m ALUMNO: MARCELO PADRON JAVIER\e[0m");
JavierMarcelo98 15:9199611a074f 138 terminal.printf("\n\n\r\t\t\e[1;37m GRUPO: 4CV2\e[0m\n\n");
JavierMarcelo98 15:9199611a074f 139 wait(3.0);//Retardo de 3 segundos
hudakz 0:ab218237069e 140 }
JavierMarcelo98 15:9199611a074f 141 int i,j,k,n=0,col,fila,op,op1,op2;
JavierMarcelo98 15:9199611a074f 142 float a[t][t+1]={0};
JavierMarcelo98 15:9199611a074f 143 void pidedatos()
JavierMarcelo98 15:9199611a074f 144 { terminal.printf("Programa para resolver sistemas de ecuaciones de hasta 100 incognitas");
JavierMarcelo98 15:9199611a074f 145 terminal.printf("nCuantas incognitas son?: ");
JavierMarcelo98 15:9199611a074f 146 n = terminal.getc();
JavierMarcelo98 15:9199611a074f 147 terminal.printf("n");
JavierMarcelo98 15:9199611a074f 148 for(i=0;i<=n-1;i++)
JavierMarcelo98 15:9199611a074f 149 {
JavierMarcelo98 15:9199611a074f 150 for(j=0;j<=n;j++)
JavierMarcelo98 15:9199611a074f 151 {
JavierMarcelo98 15:9199611a074f 152 terminal.printf("A[%d][%d] = ",i,j);
JavierMarcelo98 15:9199611a074f 153 a[i][j] = terminal.getc();
JavierMarcelo98 15:9199611a074f 154 }
JavierMarcelo98 15:9199611a074f 155 printf("n");
JavierMarcelo98 15:9199611a074f 156 }
JavierMarcelo98 15:9199611a074f 157 }
JavierMarcelo98 15:9199611a074f 158 void gaussjordan()
JavierMarcelo98 15:9199611a074f 159 {
JavierMarcelo98 15:9199611a074f 160 for(i=0;i<=n-1;i++)
JavierMarcelo98 15:9199611a074f 161 {
JavierMarcelo98 15:9199611a074f 162 for(j=n;j>=0;j--)
JavierMarcelo98 15:9199611a074f 163 {
JavierMarcelo98 15:9199611a074f 164 a[i][j]=a[i][j]/a[i][i];
JavierMarcelo98 15:9199611a074f 165 }
JavierMarcelo98 15:9199611a074f 166 for(k=i+1;k<=n-1;k++)
JavierMarcelo98 15:9199611a074f 167 {
JavierMarcelo98 15:9199611a074f 168 for(j=n;j>=0;j--)
JavierMarcelo98 15:9199611a074f 169 {
JavierMarcelo98 15:9199611a074f 170 a[k][j]=a[k][j]-a[k][i]*a[i][j];
JavierMarcelo98 15:9199611a074f 171 }
JavierMarcelo98 15:9199611a074f 172 }
JavierMarcelo98 15:9199611a074f 173 for(k=0;k<=i-1;k++)
JavierMarcelo98 15:9199611a074f 174 {
JavierMarcelo98 15:9199611a074f 175 for(j=n;j>=0;j--)
JavierMarcelo98 15:9199611a074f 176 {
JavierMarcelo98 15:9199611a074f 177 a[k][j]=a[k][j]-a[k][i]*a[i][j];
JavierMarcelo98 15:9199611a074f 178 }
JavierMarcelo98 15:9199611a074f 179 }
JavierMarcelo98 15:9199611a074f 180 }
JavierMarcelo98 15:9199611a074f 181 }
JavierMarcelo98 15:9199611a074f 182 void mat_imp()
JavierMarcelo98 15:9199611a074f 183 {
JavierMarcelo98 15:9199611a074f 184 printf("nSu matriz es: nn");
JavierMarcelo98 15:9199611a074f 185 for(i=0;i<=n-1;i++)
JavierMarcelo98 15:9199611a074f 186 {
JavierMarcelo98 15:9199611a074f 187 for(j=0;j<=n;j++)
JavierMarcelo98 15:9199611a074f 188 {
JavierMarcelo98 15:9199611a074f 189 terminal.printf(" %f ",a[i][j]);
JavierMarcelo98 15:9199611a074f 190 }
JavierMarcelo98 15:9199611a074f 191 terminal.printf("n");
JavierMarcelo98 15:9199611a074f 192 }
JavierMarcelo98 15:9199611a074f 193 terminal.printf("nn");
JavierMarcelo98 15:9199611a074f 194 }
JavierMarcelo98 15:9199611a074f 195 void correjir()
JavierMarcelo98 15:9199611a074f 196 {
JavierMarcelo98 15:9199611a074f 197 do{
JavierMarcelo98 15:9199611a074f 198 terminal.printf("nHay algun error? Si.1tNo.0 ");
JavierMarcelo98 15:9199611a074f 199 op2 = terminal.getc();
JavierMarcelo98 15:9199611a074f 200 if(op2==1)
JavierMarcelo98 15:9199611a074f 201 {
JavierMarcelo98 15:9199611a074f 202 do{
JavierMarcelo98 15:9199611a074f 203 terminal.printf("nSeleccione la posicion ----> ");
JavierMarcelo98 15:9199611a074f 204 terminal.printf(" [i] = ");
JavierMarcelo98 15:9199611a074f 205 fila = terminal.getc();
JavierMarcelo98 15:9199611a074f 206 float i=fila;
JavierMarcelo98 15:9199611a074f 207 terminal.printf("tttt[j] = ");
JavierMarcelo98 15:9199611a074f 208 col = terminal.getc();
JavierMarcelo98 15:9199611a074f 209 float j=col;
JavierMarcelo98 15:9199611a074f 210 terminal.printf("Que valor es? ");
JavierMarcelo98 15:9199611a074f 211 a[i][j]=teminal.getc();
JavierMarcelo98 15:9199611a074f 212 terminal.printf("Tiene otro error? Si.1tNo.0 ");
JavierMarcelo98 15:9199611a074f 213 op = terminal.getc();
JavierMarcelo98 15:9199611a074f 214 }
JavierMarcelo98 15:9199611a074f 215 while(op>=1);
JavierMarcelo98 15:9199611a074f 216 mat_imp();
JavierMarcelo98 15:9199611a074f 217 op1=0;
JavierMarcelo98 15:9199611a074f 218 }
JavierMarcelo98 15:9199611a074f 219 else terminal.printf("nOK!");
JavierMarcelo98 15:9199611a074f 220 op1=0;
JavierMarcelo98 15:9199611a074f 221 }
JavierMarcelo98 15:9199611a074f 222 while(op1>=1);
JavierMarcelo98 15:9199611a074f 223 terminal.printf("nn");
JavierMarcelo98 15:9199611a074f 224 }
JavierMarcelo98 15:9199611a074f 225 void imprime()
JavierMarcelo98 15:9199611a074f 226 {
JavierMarcelo98 15:9199611a074f 227 terminal.printf("Sus resultados son:");
JavierMarcelo98 15:9199611a074f 228 for(i=0;i<=n-1;i++)
JavierMarcelo98 15:9199611a074f 229 {
JavierMarcelo98 15:9199611a074f 230 terminal.printf("nX[%d] = %f",i,a[i][n]);
JavierMarcelo98 15:9199611a074f 231 }
JavierMarcelo98 15:9199611a074f 232 terminal.printf("nn");
JavierMarcelo98 15:9199611a074f 233 }
JavierMarcelo98 15:9199611a074f 234
JavierMarcelo98 15:9199611a074f 235
JasperQM 14:596a61f27f36 236 /* END routines */
JasperQM 14:596a61f27f36 237
JasperQM 14:596a61f27f36 238 /* END program */
JasperQM 14:596a61f27f36 239
JasperQM 14:596a61f27f36 240 /*+-----------------------------------------------------------------------------
JasperQM 14:596a61f27f36 241 *+ Conexión al Led Testigo:
JasperQM 14:596a61f27f36 242 *+
JasperQM 14:596a61f27f36 243 *+ Los leds se pueden conectar a cualquier pin que se declare como DigitalOut.
JasperQM 14:596a61f27f36 244 *+ El dispositivo puede drenar hasta 20ma por todas sus salidas a un voltaje de
JasperQM 14:596a61f27f36 245 *+ 3.3V, pero se recomienda no exceder de 1mA por salida.
JasperQM 14:596a61f27f36 246 *+ Esto se logra poniendo una resistencia limitadora de mínimo 330 Ohms.
JasperQM 14:596a61f27f36 247 *+
JasperQM 14:596a61f27f36 248 *+ 3.3V o 5V
JasperQM 14:596a61f27f36 249 *+ O
JasperQM 14:596a61f27f36 250 *+ |
JasperQM 14:596a61f27f36 251 *+ |
JasperQM 14:596a61f27f36 252 *+ /
JasperQM 14:596a61f27f36 253 *+ \ 1K
JasperQM 14:596a61f27f36 254 *+ /
JasperQM 14:596a61f27f36 255 *+ \ UTILIZANDO LÓGICA NEGATIVA
JasperQM 14:596a61f27f36 256 *+ |
JasperQM 14:596a61f27f36 257 *+ __|__
JasperQM 14:596a61f27f36 258 *+ \ /
JasperQM 14:596a61f27f36 259 *+ \ /
JasperQM 14:596a61f27f36 260 *+ \ /
JasperQM 14:596a61f27f36 261 *+ _\/_
JasperQM 14:596a61f27f36 262 *+ |
JasperQM 14:596a61f27f36 263 *+ |__________________________ PIN (Digital Out)
JasperQM 14:596a61f27f36 264 *+
JasperQM 14:596a61f27f36 265 *+
JasperQM 14:596a61f27f36 266 *+
JasperQM 14:596a61f27f36 267 *+
JasperQM 14:596a61f27f36 268 *+ 1K
JasperQM 14:596a61f27f36 269 *+
JasperQM 14:596a61f27f36 270 *+ ________/\ /\ /\ ____ PIN (Digital Out)
JasperQM 14:596a61f27f36 271 *+ | \/ \/ \/
JasperQM 14:596a61f27f36 272 *+ |
JasperQM 14:596a61f27f36 273 *+ |
JasperQM 14:596a61f27f36 274 *+ __|__
JasperQM 14:596a61f27f36 275 *+ \ /
JasperQM 14:596a61f27f36 276 *+ \ /
JasperQM 14:596a61f27f36 277 *+ \ / UTILIZANDO LÓGICA POSITIVA
JasperQM 14:596a61f27f36 278 *+ _\/_
JasperQM 14:596a61f27f36 279 *+ |
JasperQM 14:596a61f27f36 280 *+ |
JasperQM 14:596a61f27f36 281 *+ |
JasperQM 14:596a61f27f36 282 *+ __|__
JasperQM 14:596a61f27f36 283 *+ ___
JasperQM 14:596a61f27f36 284 *+ _
JasperQM 14:596a61f27f36 285 *+ _
JasperQM 14:596a61f27f36 286 *+
JasperQM 14:596a61f27f36 287 *+ GND
JasperQM 14:596a61f27f36 288 *+
JasperQM 14:596a61f27f36 289 +----------------------------------------------------------------------------
JasperQM 14:596a61f27f36 290 *+
JasperQM 14:596a61f27f36 291 *+ Powered by
JasperQM 14:596a61f27f36 292 *+
JasperQM 14:596a61f27f36 293 *+ T H E A N T U L I U ' S T E A M R&D Unltd
JasperQM 14:596a61f27f36 294 *+
JasperQM 14:596a61f27f36 295 *+ Research, Development, Systems, Equipment, Support & Spare Parts.
JasperQM 14:596a61f27f36 296 *+ (C) Copyright 1989-2019, All Rights Reserved
JasperQM 14:596a61f27f36 297 *+
JasperQM 14:596a61f27f36 298 *+ Welcome to The Beaners Proyect Community!
JasperQM 14:596a61f27f36 299 *+----------------------------------------------------------------------------*/
JasperQM 14:596a61f27f36 300
JasperQM 14:596a61f27f36 301 /* END Mbed */