Upcoming SlideShare
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Standard text messaging rates apply

# Codigo en java pdf

5,015

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total Views
5,015
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
197
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Transcript

• 1. 2010 CODE IN JAVA FOR SIMPLE GAUSS BY:DUBAN CASTRO FLOREZ NUMERICS METHODS IN ENGINEERING PETROLEUM ENGINEERING
• 2. ANEXOS 1 CODIGO DEL METODO EN JAVA package gauss; import javax.swing.JOptionPane; public class gauss { public static void main(String[] args) { JOptionPane.showMessageDialog(null,"SOLUCION DE ECUACIONES LINEALES POR EL METODO DE GAUSS"); int i,j,s,k,h,n; double d; double m[][]; double r[]; double x[]; //RECUERDE QUE EL NUMERO DE INCOGNITAS Y DE ECUACIONES DEBEN SER IGUALES n=Integer.parseInt(JOptionPane.showInputDialog("ingrese el numero de incognitas")); m= new double [n][n]; r= new double [n]; x= new double [n]; //RECUERDE QUE LA DIAGONAL PRINCIPAL DE LA MATRIZ DE COEFICIENTES NO PUEDE TENER CEROS for(i=0;i&lt;=n-1;i++){ k=i+1;
• 3. r[i]=Double.parseDouble(JOptionPane.showInputDialog("ingrese el elemento "+k+" del vector de soluciones")); x[i]=0; for(j=0;j&lt;=n-1;j++){ h=j+1; m[i][j]=Double.parseDouble(JOptionPane.showInputDialog("ingrese el elemento "+k+h+" de la matriz de coeficientes")); } } //ESTE CICLO CONVIERTE LA TRIANGULAR INFERIOR EN CEROS for(i=0;i&lt;n;i++){ for(j=i;j&lt;n;j++){ if(i==j){ d=m[i][j]; for(s=0;s&lt;n;s++){ m[i][s]=((m[i][s])/d); } r[i]=((r[i])/d); } else{ d=m[j][i]; for(s=0;s&lt;n;s++){ m[j][s]=m[j][s]-(d*m[i][s]);
• 4. } r[j]=r[j]-(d*r[i]); } } } //A CONTINUACION SE CALCULA EL VALOR DE LAS INCOGNITAS for(i=n-1;i&gt;=0;i--){ double y=r[i]; for(j=n-1;j&gt;=i;j--){ y=y-x[j]*m[i][j]; } x[i]=y; } for(i=0;i&lt;n;i++){ k=i+1; JOptionPane.showMessageDialog(null,"el valor de la incognita x"+k+" es "+x[i]); } } }