{"id":1513,"date":"2016-11-30T16:27:00","date_gmt":"2016-11-30T22:27:00","guid":{"rendered":"http:\/\/linuxitos.com\/main\/gaussjordan-en-c\/"},"modified":"2016-11-30T16:27:00","modified_gmt":"2016-11-30T22:27:00","slug":"gaussjordan-en-c","status":"publish","type":"post","link":"https:\/\/linuxitos.com\/main\/gaussjordan-en-c\/","title":{"rendered":"GaussJordan en C"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left;\">\n<div style=\"clear: both; text-align: center;\"><a href=\"https:\/\/1.bp.blogspot.com\/-dbHcF189JyM\/WD9CrBmWgGI\/AAAAAAAAEEk\/eGnaUJ0VYwcn_Qv9cFxJVRG-Hp0y7FcOQCLcB\/s1600\/Captura%2Bde%2Bpantalla%2Bde%2B2016-11-30%2B15-19-59.png\" style=\"margin-left: 1em; margin-right: 1em;\"><img decoding=\"async\" border=\"0\" src=\"https:\/\/1.bp.blogspot.com\/-dbHcF189JyM\/WD9CrBmWgGI\/AAAAAAAAEEk\/eGnaUJ0VYwcn_Qv9cFxJVRG-Hp0y7FcOQCLcB\/s1600\/Captura%2Bde%2Bpantalla%2Bde%2B2016-11-30%2B15-19-59.png\" \/><\/a><\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: large;\">Cuando estudias programaci\u00f3n, posiblemente uno de los programas b\u00e1sicos que te pedir\u00e1n es el de GaussJordan, o tal vez no, pero como sea, aqu\u00ed les comparto uno que desarroll\u00e9 cuando lo necesit\u00e9.<\/span><\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: large;\"><br \/><\/span><\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: large;\">Es bastante simple, utiliza memoria din\u00e1mica para todo el c\u00e1lculo y adem\u00e1s si no encuentra soluci\u00f3n pues env\u00eda un mensaje que no lo hay.<\/span><\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: large;\"><br \/><\/span><\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: large;\">Hay muchas cosas que se necesitan pulir, por ejemplo, si ingresan m\u00e1s 20 ecuaciones, a veces se cicla. Claro, hay programas mucho m\u00e1s complejos que ya resuelven este problema, pero cuando a uno se lo piden, pues no es tan simple desarrollarlo.<\/span><\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: large;\"><br \/><\/span><\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: large;\">El c\u00f3digo es el siguiente, el cual solo se copia, se pega a un documento de texto y se compila con c, en mi caso utilizo geany para eso:<\/span><\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: large;\"><br \/><\/span><\/div>\n<pre style=\"background: url(&quot;assets\/shadow.png&quot;) 50% 100% repeat-x rgb(245, 245, 245); border-radius: 4px; border: 1px solid rgb(204, 204, 204); box-shadow: rgb(204, 204, 204) 0px 0px 3px; box-sizing: border-box; font-stretch: normal; line-height: 1.6; margin-bottom: 10px; max-width: 100%; outline: 0px; overflow: auto; padding: 9.5px; tab-size: 4; text-shadow: rgb(255, 255, 255) 0px 1px 0px; vertical-align: baseline; word-break: break-all; word-wrap: break-word;\"><span style=\"color: #333333; font-family: menlo, monaco, consolas, courier new, monospace;\"><span style=\"font-size: 15px; white-space: pre-wrap;\">\/* Autor: Fernando Merino<br \/> * Programa: M\u00e9todo de Gauss-Jordan<br \/> * Descripci\u00f3n: El m\u00e9todo de Gauss-Jordan soluciona sistemas de ecuaciones<br \/> * simult\u00e1neas.<br \/> * *\/<br \/><br \/>#include &lt;stdio.h&gt;<br \/>#include &lt;stdlib.h&gt;<br \/><br \/>void gausJordan(float **matriz,int n,float *raices);<br \/>void imprimirMatriz(float *raices,int n);<br \/>void leerValores(float **matriz,int n);<br \/><br \/>int main(){<br \/> int n;<br \/> float **matriz,*raices;<br \/> printf(\"Ingrese el n\u00famero de ecuaciones (n): \");<br \/> scanf(\"%d\",&amp;n);<br \/> getchar();<br \/> matriz=(float**) malloc (sizeof (float*)*n);<br \/> raices=(float*) malloc (sizeof (float*)*n);<br \/> leerValores(matriz,n);<br \/> gausJordan(matriz,n,raices);<br \/> printf(\"Soluci\u00f3n nn\");<br \/> imprimirMatriz(raices,n);<br \/> getchar();<br \/> return 0;<br \/>}<br \/>void imprimirMatriz(float *raices,int n){<br \/> int i;<br \/> for(i=0;i&lt;n;i++){<br \/>  printf(\"X%d = %fn\",i+1,raices[i]);<br \/> }<br \/>}<br \/>void gausJordan(float **matriz,int n,float *raices){<br \/> int i,j,k;<br \/> float termino;<br \/> for(i=0;i&lt;n;i++){<br \/>  if(matriz[i][i]==0.0){<br \/>   fprintf(stderr,\"Error: Divisi\u00f3n entre 0:: No hay soluci\u00f3n!!!nn\");<br \/>   system(\"pause\");<br \/>   return ;<br \/>  }<br \/>  for(k=0;k&lt;n;k++){<br \/>   if(k!=i){<br \/>    termino=matriz[k][i]\/matriz[i][i];<br \/>    for(j=0;j&lt;=n;j++){<br \/>     matriz[k][j]-=termino*matriz[i][j];<br \/>    }<br \/>   }<br \/>  }<br \/> }<br \/> for(i=0;i&lt;n;i++){<br \/>  termino=matriz[i][n]\/matriz[i][i];<br \/>  raices[i]=termino;<br \/> } <br \/>}<br \/>void leerValores(float **matriz,int n){<br \/> int i,j;<br \/> for(i=0;i&lt;n;i++){<br \/>  matriz[i]=(float*) malloc (sizeof(float)*(n+1));<br \/>  for(j=0;j&lt;n;j++){<br \/>   printf(\"Ingrese coeficiente de 'X%d' de la ecuaci\u00f3n %d: \",j+1,i+1);<br \/>   scanf(\"%f\",&amp;matriz[i][j]);<br \/>  }<br \/>  printf(\"Ingrese el resultado de la ecuaci\u00f3n %d \",i+1);<br \/>  scanf(\"%f\",&amp;matriz[i][n]);<br \/> }<br \/>}<\/span><\/span><span style=\"color: #262626; font-family: &quot;Courier 10 Pitch&quot;, Courier, monospace; font-size: 1.5rem;\"><br \/><\/span><\/pre>\n<div><\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: large;\"><br \/><\/span><\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: large;\">Ahora, lo que le trato de implementar, es muestre los resultados en fracciones, todo el proceso, es decir, que se le ingrese algo as\u00ed 1\/4, y que as\u00ed se lo lleve en todo el proceso, y que al final de un resultado en fracciones. Si alguien ya lo tiene por ah\u00ed y que sea en C, y quiera compartirlo, me parecer\u00eda perfecto, esto m\u00e1s por hobbie. Gracias y espero que les sirva.<\/span><\/div>\n<p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Cuando estudias programaci\u00f3n, posiblemente uno de los programas b\u00e1sicos que te pedir\u00e1n es el de GaussJordan, o tal vez no, pero como sea, aqu\u00ed les comparto uno que desarroll\u00e9 cuando lo necesit\u00e9. Es bastante simple, utiliza memoria din\u00e1mica para todo el c\u00e1lculo y adem\u00e1s si no encuentra soluci\u00f3n pues env\u00eda un mensaje que no lo [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[76,285,286,287,288],"tags":[],"class_list":["post-1513","post","type-post","status-publish","format-standard","hentry","category-c","category-ecuaciones-simultaneas","category-gauss","category-jordan","category-sistema-de-ecuaciones"],"_links":{"self":[{"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/posts\/1513","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/comments?post=1513"}],"version-history":[{"count":0,"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/posts\/1513\/revisions"}],"wp:attachment":[{"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/media?parent=1513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/categories?post=1513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/tags?post=1513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}