Trabajo Progra Matrices.docx

  • Uploaded by: Alessandro Flores Palomino
  • 0
  • 0
  • April 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Trabajo Progra Matrices.docx as PDF for free.

More details

  • Words: 945
  • Pages: 10
UNIVERSIDAD NACIONAL DE INGENIERIA FACULTAD DE INGENIERIA ELECTRICA Y ELECTRONICA

2017 2017

-I

EJERCICIOS MATRICES CURSO

: PROGRAMACIÓN DIGITAL

SECCION

: N (realizado en la sección P)

PROFESOR

:

-TRINI SANDRO

ALUMNO

:

-FLORES PALOMINO ALESSANDRO

20142639F

LIMA - PERÚ

01/06/2017 01/06/2017

1

UNIVERSIDAD NACIONAL DE INGENIERÍA FACULTAD DE INGENIERIA ELÉCTRICA Y ELECTRÓNICA MATRIZ ALEATORIA 1 2 public class MA713NP { 3 static double [][] matrixaleatoria () 4 { 5 double [][] matrix = new double [4][4]; 6 for(int i=0;i<matrix.length;i++) 7 { 8 for(int j=0;j<matrix[i].length;j++) 9 { 10 matrix[i][j]=(double) (Math.random()*10); 11 } 12 } 13 return matrix; 14 } 15 static void imprimir (double [][] matrix) 16 { 17 for(int i=0;i<matrix.length;i++) 18 { 19 for(int j=0;j<matrix[i].length;j++) 20 { 21 //System.out.print( " "+ matrix[i][j]+" "); 22 System.out.print(" "); 23 System.out.printf("%2f",matrix[i][j]); 24 System.out.print(" "); 25 } 26 System.out.println(" "); 27 } 28 } 29 public static void main(String[] args) 30 { 31 32 double [][] A; 33 A= MA713NP.matrixaleatoria(); 34 MA713NP.imprimir(A); 35 }

2

UNIVERSIDAD NACIONAL DE INGENIERÍA FACULTAD DE INGENIERIA ELÉCTRICA Y ELECTRÓNICA DIAGONAL PRINCIPAL 1 2 public class MA713NP { 3 static void diagonalp(double [][]matrix) 4 { 5 //int [][] matrix=new int [4][4]; 6 for(int i=0;i<matrix.length;i++) 7 { 8 for (int j=0;j<matrix[i].length;j++) 9 { 10 if(i==j) 11 12 { 13 matrix[i][j]=(double)(Math.random()*21); 14 //System.out.print(" "+matrix[i][j]+" "); 15 System.out.print(" "); 16 System.out.printf("%2f",matrix[i][j]); 17 System.out.print(" "); 18 19 } 20 else 21 22 { 23 System.out.print(" "); 24 } 25 26 27 } 28 System.out.println(""); 29 } 30 } 31 public static void main(String[] args) 32 { 33 double [][] A=new double [4][4]; 34 MA713NP.diagonalp(A); 35 } 36 37 }

3

UNIVERSIDAD NACIONAL DE INGENIERÍA FACULTAD DE INGENIERIA ELÉCTRICA Y ELECTRÓNICA

DIAGONAL SECUNDARIA 1 2 public class MA713NP { 3 static void diagonals (double [][]matrix) 4 { 5 //int [][] matrix=new int [4][4]; 6 for(int i=0;i<matrix.length;i++) 7 { 8 for (int j=0;j<matrix[i].length;j++) 9 { 10 if(matrix.length-1==i+j) 11 12 { 13 matrix[i][j]=(double)(Math.random()*10); 14 //System.out.print(" "+matrix[i][j]+" "); 15 System.out.print(" "); 16 System.out.printf("%2f",matrix[i][j]); 17 System.out.print(" "); 18 19 } 20 else 21 22 { 23 System.out.print(" "); 24 } 25 26 27 } 4

UNIVERSIDAD NACIONAL DE INGENIERÍA FACULTAD DE INGENIERIA ELÉCTRICA Y ELECTRÓNICA 28 System.out.println(""); 29 } 30 } 31 public static void main(String[] args) 32 { 33 double [][] A=new double [4][4]; 34 MA713NP.diagonals(A); 35 } 36 37 }

TRIANGULAR SUPERIOR 1 2 public class MA713NP { 3 static double [][] matrixaleatoria () 4 { 5 double [][] matrix = new double [4][4]; 6 for(int i=0;i<matrix.length;i++) 7 { 8 for(int j=0;j<matrix[i].length;j++) 9 { 10 matrix[i][j]=(double) (Math.random()*10); 11 } 12 } 13 return matrix; 14 } 15 static void imprimir (double [][] matrix) 16 { 17 for(int i=0;i<matrix.length;i++) 18 { 19 for(int j=0;j<matrix[i].length;j++)

5

UNIVERSIDAD NACIONAL DE INGENIERÍA FACULTAD DE INGENIERIA ELÉCTRICA Y ELECTRÓNICA 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 }

{ //System.out.print( " "+ matrix[i][j]+" "); System.out.print(" "); System.out.printf("%2f",matrix[i][j]); System.out.print(" "); } System.out.println(" "); } } static void triangularsuperior (double [][]matrix) { //int [][] matrix=new int [4][4]; for(int i=0;i<matrix.length;i++) { for (int j=0;j<matrix[i].length;j++) { if(i<j) { matrix[i][j]=(double)(Math.random()*10); //System.out.print(" "+matrix[i][j]+" "); System.out.print(" "); System.out.printf("%2f",matrix[i][j]); System.out.print(" "); } else { System.out.print(" }

} System.out.println(""); } } public static void main(String[] args) { double [][] A=new double [4][4]; MA713NP.triangularsuperior(A); }

6

");

UNIVERSIDAD NACIONAL DE INGENIERÍA FACULTAD DE INGENIERIA ELÉCTRICA Y ELECTRÓNICA

TRIANGULAR INFERIOR 1 2 public class MA713NP { 3 static double [][] matrixaleatoria () 4 { 5 double [][] matrix = new double [4][4]; 6 for(int i=0;i<matrix.length;i++) 7 { 8 for(int j=0;j<matrix[i].length;j++) 9 { 10 matrix[i][j]=(double) (Math.random()*10); 11 } 12 } 13 return matrix; 14 } 15 static void imprimir (double [][] matrix) 16 { 17 for(int i=0;i<matrix.length;i++) 18 { 19 for(int j=0;j<matrix[i].length;j++) 20 { 21 //System.out.print( " "+ matrix[i][j]+" "); 22 System.out.print(" "); 23 System.out.printf("%2f",matrix[i][j]); 24 System.out.print(" "); 25 } 26 System.out.println(" "); 7

UNIVERSIDAD NACIONAL DE INGENIERÍA FACULTAD DE INGENIERIA ELÉCTRICA Y ELECTRÓNICA 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 }

} } static void triangularinferior (double [][]matrix) { //int [][] matrix=new int [4][4]; for(int i=0;i<matrix.length;i++) { for (int j=0;j<matrix[i].length;j++) { if(i>j) { matrix[i][j]=(double)(Math.random()*10); //System.out.print(" "+matrix[i][j]+" "); System.out.print(" "); System.out.printf("%2f",matrix[i][j]); System.out.print(" "); } else { System.out.print(" }

} System.out.println(""); } } public static void main(String[] args) { double [][] A=new double [4][4]; MA713NP.triangularinferior(A); }

8

");

UNIVERSIDAD NACIONAL DE INGENIERÍA FACULTAD DE INGENIERIA ELÉCTRICA Y ELECTRÓNICA TRANSPUESTA 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

public class MA713NP { static double[][] transpuesta (double [][]matrix) { double [][] matrix2=new double [matrix.length][matrix.length]; for(int i=0;i<matrix.length;i++) { for (int j=0;j<matrix[i].length;j++) { matrix2[i][j]=matrix[j][i]; } } return matrix2; } static void imprimir (double [][]matrix) { for(int i=0;i<matrix.length;i++) { System.out.print(""); for (int j=0;j<matrix[i].length;j++) { System.out.print(" "); System.out.printf("%4f",matrix[i][j]); System.out.print(" ");

} System.out.println(""); } } static double [][] matrizaleat () { double [][] matrix=new double [4][4]; for(int i=0;i<matrix.length;i++) { for (int j=0;j<matrix[i].length;j++) { 9

UNIVERSIDAD NACIONAL DE INGENIERÍA FACULTAD DE INGENIERIA ELÉCTRICA Y ELECTRÓNICA 44 matrix[i][j]=(double)(Math.random()*10); 45 46 } 47 } 48 return matrix; 49 } 50 51 public static void main(String[] args) { 52 double [][] A; 53 54 A= MA713NP.matrizaleat(); 55 MA713NP.imprimir(A); 56 System.out.println(""); 57 A=MA713NP.transpuesta(A); 58 MA713NP.imprimir(A); 59 } 60 61 }

10

Related Documents

Progra
May 2020 9
Progra 01
October 2019 5
Progra No Lineal
June 2020 5

More Documents from ""

Pa01.validado.as.pdf
October 2019 2
April 2020 11