miércoles, 2 de diciembre de 2009

SUMA BOTON

MATRIZ
import javax.swing.JOptionPane;

public class Matriz {
public int numeroFilas;
public int numeroColumnas;
public double [][]matriz;

public Matriz(){
}

public Matriz(int nF, int nC){

numeroFilas=nF;
numeroColumnas=nC;
matriz=new double[numeroFilas][numeroColumnas];//construyo un sitio para almacenar ceros
for(int i=0;i < numeroFilas;i++)
for(int j=0; j < numeroColumnas; j++)
matriz [i][j]=0;
}

public Matriz suma(Matriz b){
Matriz resultado;
if((this.numeroFilas == b.numeroFilas)&& (this.numeroColumnas == b.numeroColumnas)){
resultado = new Matriz(this.numeroFilas, this.numeroColumnas);
for(int i=0; i < this.numeroFilas; i++)
for(int j=0; j < this.numeroColumnas; j++)
resultado.matriz[i][j] = this.matriz[i][j]+ b.matriz[i][j];
return resultado;
}
else
System.out.println("ERROR EN DIMENSIONES DE LAS MATRICES");
resultado=null;
return resultado;
}

public void leer(){
String aux;
for(int i=0; i < this.numeroFilas; i++){
for(int j=0; j < this.numeroColumnas; j++){
aux = JOptionPane.showInputDialog(null,"INGRESO DE VALORES","INGRESE EL VALOR: "+(i+1)+","+(j+1),JOptionPane.DEFAULT_OPTION);
this.matriz[i][j]=Double.parseDouble(aux);
}
}
}

public String toString(){
String aux="\n\n";
for(int i=0; i < numeroFilas; i++){
for(int j=0; j < numeroColumnas; j++){
aux+=matriz[i][j]+" ";
}
aux+="\n";
}
aux+=" ";
return aux;
}

}

APPLET
public class NewJApplet extends javax.swing.JApplet {

/** Initializes the applet NewJApplet */
public void init() {
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
initComponents();
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}

/** This method is called from within the init() method to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// //GEN-BEGIN:initComponents
private void initComponents() {

jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jLabel4 = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();

jLabel1.setBackground(new java.awt.Color(204, 255, 0));
jLabel1.setFont(new java.awt.Font("Bradley Hand ITC", 3, 24)); // NOI18N
jLabel1.setForeground(new java.awt.Color(0, 0, 255));
jLabel1.setText("SUMA DE MATRICES");

jLabel2.setBackground(new java.awt.Color(255, 51, 51));
jLabel2.setText("numero de filas");

jLabel3.setText("numero de columnas");

jButton1.setText("leer matriz 1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});

jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);

jLabel4.setText("resultados");

jButton2.setText("imprimir");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

jButton3.setText("leer matriz 2");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});

jButton4.setText("sumar");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(23, 23, 23)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1)
.addComponent(jButton4)
.addComponent(jButton3)
.addComponent(jButton2))
.addGap(53, 53, 53)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jTextField2, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE))
.addComponent(jLabel4))
.addContainerGap(77, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(108, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 264, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(48, 48, 48))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(14, 14, 14)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel2)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addGap(21, 21, 21)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jButton1)
.addComponent(jLabel4))
.addGap(11, 11, 11)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton2)))
.addContainerGap(31, Short.MAX_VALUE))
);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
}//
//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
//metodo esucha al dar click en el botton leer
String aux = jTextField1.getText();
nF = Integer.parseInt(aux);
aux = jTextField2.getText();
nC = Integer.parseInt(aux);//metodo para cambiar de string a entero
m = new Matriz(nF,nC);//matriz llena de ceros
m.leer();
}//GEN-LAST:event_jButton1ActionPerformed

private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jTextField1ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
jTextArea1.setText(m.toString());
jTextArea1.setText(n.toString());
jTextArea1.setText(r.toString());
}//GEN-LAST:event_jButton2ActionPerformed

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO add your handling code here:
String aux = jTextField1.getText();
nF = Integer.parseInt(aux);
aux = jTextField2.getText();
nC = Integer.parseInt(aux);//metodo para cambiar de string a entero
n = new Matriz(nF,nC);//matriz llena de ceros
n.leer();
}//GEN-LAST:event_jButton3ActionPerformed

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
// TODO add your handling code here:
r = new Matriz(nF,nC);
r = m.suma(n);
}//GEN-LAST:event_jButton4ActionPerformed


// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
// End of variables declaration//GEN-END:variables
public int nF;
public int nC;
public Matriz m;
public Matriz n;
public Matriz r;
}

movimiento rectilineo uniformemente variado

MATRIZ
public class Matriz {
public int numeroFilas;
public int numeroColumnas;
public double [][]matriz;

public Matriz(){
}

public Matriz(int nF, int nC){
numeroFilas = nF;
numeroColumnas = nC;
matriz = new double [numeroFilas][numeroColumnas];
for(int i=0; i < numeroFilas; i++)
for(int j=0; j < numeroColumnas; j++)
matriz[i][j]=0;
}

public Matriz suma(Matriz b){
Matriz resultado;
if((this.numeroFilas == b.numeroFilas)&& (this.numeroColumnas == b.numeroColumnas)){
resultado = new Matriz(this.numeroFilas, this.numeroColumnas);
for(int i=0; i < this.numeroFilas; i++)
for(int j=0; j < this.numeroColumnas; j++)
resultado.matriz[i][j] = this.matriz[i][j]+ b.matriz[i][j];
return resultado;
}
else
System.out.println("ERROR EN DIMENSIONES DE LAS MATRICES");
resultado=null;
return resultado;
}

public Matriz multiplicacion(Matriz b){
Matriz resultado;
if((this.numeroFilas == b.numeroColumnas)){
resultado = new Matriz(this.numeroFilas, this.numeroColumnas);
for(int i=0; i < this.numeroFilas; i++){
for(int j=0; j < b.numeroColumnas; j++){
for(int k=0; k < this.numeroColumnas; k++)
resultado.matriz[i][j]+=this.matriz[i][k]*b.matriz[k][j];
}
}
return resultado;
}
else
System.out.println("ERROR EN DIMENSIONES DE LAS MATRICES");
resultado=null;
return resultado;
}

public String toString(){
String aux="\n[\n";
for(int i=0; i < numeroFilas; i++){
for(int j=0; j < numeroColumnas; j++){
aux += matriz[i][j]+" ";
}
aux+="\n";
}
aux+= "]";
return aux;
}
}

VECTOR
public class Vector3D extends Matriz {
double coordenadaX;
double coordenadaY;
double coordenadaZ;

public Vector3D(){
super(1,3);
}

public Vector3D(double x, double y, double z){
super(1,3);
this.matriz[0][0] = x;
this.matriz[0][1] = y;
this.matriz[0][2] = z;
coordenadaX = x;
coordenadaY = y;
coordenadaZ = z;
}

public double magnitud(){
double resultado = 0;
for(int i=0; i < 3; i++){
resultado += this.matriz[0][i]*this.matriz[0][i];
}
resultado = Math.sqrt(resultado);
return resultado;
}

public Vector3D unitario(){
Vector3D unitario = new Vector3D();
for(int i=0; i < 3; i++)
unitario.matriz[0][i] = this.matriz[0][i]/this.magnitud();
return unitario;
}

public double productoEscalar(Vector3D v){
double resultado = 0;
for(int i=0; i < 3; i++)
resultado += this.matriz[0][i]*v.matriz[0][i];
return resultado;
}

public Vector3D productoEscalarVector(double a){
Vector3D resultado = new Vector3D();
for(int i=0; i < 3; i++)
resultado.matriz[0][i] = this.matriz[0][i]*a;
return resultado;
}

public Vector3D productoCruz(Vector3D v){
Vector3D resultado;
resultado = new Vector3D();
resultado.matriz[0][0] = this.matriz[0][1]*v.matriz[0][2]-this.matriz[0][2]*v.matriz[0][1];
resultado.matriz[0][1] = this.matriz[0][2]*v.matriz[0][0]-this.matriz[0][0]*v.matriz[0][2];
resultado.matriz[0][2] = this.matriz[0][0]*v.matriz[0][1]-this.matriz[0][1]*v.matriz[0][0];
return resultado;
}

public static void main(String args[]){
Vector3D v1 = new Vector3D(-1,1,-1);
Vector3D v2 = new Vector3D(0,2,0);
System.out.println(v1+"\n"+v2);
System.out.println("LA COORDENADA EN X ES: "+v1.coordenadaX);
System.out.println("\nLA SUMA DE LOS VECTORES ES: "+(v1.suma(v2)));
System.out.println("\nLA MAGNITUD DEL VECTOR ES: "+v1.magnitud());
System.out.println("\nEL VECTOR UNITARIO ES: "+v1.unitario());
System.out.println("\nEL PRODUCTO ESCALAR ENTRE LOS DOS VECTORES ES: "+v1.productoEscalar(v2));
System.out.println("\nEL PRODUCTO CRUZ ENTRE LOS DOS VECTORES ES: "+v1.productoCruz(v2));
}
}

MRUV
public class MRUV extends Vector3D{
Matriz posicion;
Matriz velocidad;
Matriz aceleracion;
Matriz desplazamiento;
Matriz velocidad2;

public MRUV(){
}

public MRUV (Vector3D pos, Vector3D vel0, Vector3D ace, Vector3D des){
posicion = pos;
velocidad = vel0;
aceleracion = ace;
desplazamiento = des;
}

public void calcularPosicion(Vector3D ro, Vector3D vel0, Vector3D ace, double t){
posicion = ro.suma((vel0.productoEscalarVector(t)).suma((ace.productoEscalarVector(Math.pow(t,2))).productoEscalarVector(1/2)));
}

public void calcularVelocidad(Vector3D vel0, double t, Vector3D ace){
velocidad = vel0.suma(ace.productoEscalarVector(t));
}

public static void main(String args[]){
MRUV m = new MRUV();
Vector3D r0 = new Vector3D (1,0,-1);
Vector3D vel0 = new Vector3D (0,5,0);
Vector3D ace = new Vector3D (-4,0,9);
double t = 2;
m.calcularPosicion(r0, vel0, ace, t);
m.calcularVelocidad(vel0, t, ace);
System.out.println("LA POSICION A t = 2s rO = i-k v0 = 5j a = -4i+9k ES: \n" +m.posicion);
System.out.println("LA VELOCIDAD A t = 2s v0 = 5j a = -4i+9k ES: \n" +m.velocidad);
}
}

martes, 24 de noviembre de 2009

Que es un Applet

*VENTAJAS DE UN APPLET

Es un componente de una aplicación que se ejecuta en el contexto de otro programa, debe ejecutarse en un contenedor, proporciona un programa anfitrión, mediante un plugin. Un applet no pùede ejecutarse de manera independiente, son mucho menos dependientes del navegador e incluso independientes del sistema operativo del ordenador donde se ejecutan.

*PARA QUE SIRVE UN APPLET

Se puede conseguir efectos visuales y sonoros(incluso ambos a la vez), textos un movimiento utiliddades, pequeños programas interactivos, juegos interactivos, presentaciones multimedia , etc.


*DESVENTAJAS DE UN APPLET

Un applet no puede escribir o leer de un disco duro del cliente
La descarga de applet consume tiempo

BIBLIOGRAFIA
http://www.proactiva-calidad.com/java/intro_applet/que_es_un_applet.html
es.wikipedia.org/wiki/Applet
http://www.ldc.usb.ve/~vtheok/webmaestro/docs/cap20.html

domingo, 15 de noviembre de 2009

vector

Clase matriz
package matrices;

public class Matriz {
public int numeroFilas;
public int numeroColumnas;
public double [][]matriz;

//crea una matriz sin dimensiones
public Matriz(){
}

//constructor con parametros
//nF es el numero de filas
//nc es el numero de columnas
public Matriz(int nF, int nC){
numeroFilas = nF;
numeroColumnas = nC;
matriz = new double [numeroFilas][numeroColumnas];

for(int i=0; i < numeroFilas; i++)
for(int j=0; j < numeroColumnas; j++)
matriz[i][j]=0;
}


//metodo de suma de matrices
//b es el primer sumando
//retorna una matriz resultado de suma
public Matriz suma(Matriz b){
Matriz resultado;
//primero revisamos que las filas y las columnas sean iguales
//this referencia a un objeto que au no esta creado pero que alguien algun momento lo va a crear
if((this.numeroFilas == b.numeroFilas)&& (this.numeroColumnas == b.numeroColumnas)){
resultado = new Matriz(this.numeroFilas, this.numeroColumnas);
for(int i=0; i < this.numeroFilas; i++)
for(int j=0; j < this.numeroColumnas; j++)
resultado.matriz[i][j] = this.matriz[i][j]+ b.matriz[i][j];
return resultado;
}
else
System.out.println("ERROR EN DIMENSIONES DE LAS MATRICES");
resultado=null;
return resultado;
}

//metodo de multiplicacion de matrices
//retorna una matriz resultado resta
public Matriz multiplicacion(Matriz b){
Matriz resultado;
if(this.numeroFilas == b.numeroColumnas){
resultado=new Matriz(this.numeroFilas,b.numeroColumnas);
for(int i=0; i < this.numeroFilas; i++){
for(int j=0; j < b.numeroColumnas; j++){
for(int k=0; k < this.numeroFilas; k++)
resultado.matriz[i][j] += (this.matriz[i][k]*b.matriz[k][j]);
}
}
return resultado;
}
else
System.out.println("error en dimensiones de las matrices");
resultado = null;
return resultado;
}
//devuelve el objeto matriz en texto para poderlo imprimir
public String toString(){
String aux="\n[\n";
for(int i=0; i < numeroFilas; i++){
for(int j=0; j < numeroColumnas; j++){
aux += matriz[i][j]+" ";
}
aux+="\n";
}
aux+= "]";
return aux;
}
}

Clase vector3D

package matrices;


public class Vector3D extends Matriz {

double coordenadaX;
double coordenadaY;
double coordenadaZ;
double a;
double b;
double c;




public Vector3D(){
super(1,3);
}

public Vector3D(double x, double y, double z){
super(1,3);
this.matriz[0][0] = x;
this.matriz[0][1] = y;
this.matriz[0][2] = z;
coordenadaX = x;
coordenadaY = y;
coordenadaZ = z;
a = matriz[0][0];
b = matriz[0][1];
c = matriz[0][2];

}

public double magnitud(){
double resultado = 0;
for(int i=0; i < 3; i++){
resultado += this.matriz[0][i]*this.matriz[0][i];
}
resultado = Math.sqrt(resultado);
return resultado;
}

//segunda forma de hacer la magnitud
public double magnitud1(){
double resultado;
resultado = this.coordenadaX*this.coordenadaX+this.coordenadaY*this.coordenadaY+this.coordenadaZ*this.coordenadaZ;
resultado = Math.sqrt(resultado);
return resultado;
}

//tercera forma de hacer la magnitud
public double magnitud2(){
double resultado;
resultado = Math.pow(this.coordenadaX, 2)+Math.pow(this.coordenadaY, 2)+Math.pow(this.coordenadaZ, 2);
resultado = Math.sqrt(resultado);
return resultado;
}

public Vector3D unitario(){
Vector3D unitario = new Vector3D();
for(int i=0; i < 3; i++)
unitario.matriz[0][i] = this.matriz[0][i]/this.magnitud2();
return unitario;
}

public double productoEscalar(Vector3D v){
double resultado = 0;
for(int i=0; i < 3; i++)
resultado += this.matriz[0][i]*v.matriz[0][i];
return resultado;
}

public Vector3D productoCruz(Vector3D v){
Vector3D resultado;
resultado = new Vector3D();
resultado.matriz[0][0] = b *v.c-c*v.b;
resultado.matriz[0][1] = c*v.a-a*v.c;
resultado.matriz[0][2] = a*v.b-b*v.a;
return resultado;
}

public static void main(String args[]){
Vector3D v1 = new Vector3D(-1,1,-1);
Vector3D v2 = new Vector3D(0,2,0);
System.out.println(v1+"\n"+v2);
System.out.println("COORDENADA EN X : "+v1.coordenadaX);
System.out.println("\nLA SUMA DE LOS VECTORES: "+(v1.suma(v2)));
System.out.println("\nLA MAGNITUD DEL VECTOR: "+v1.magnitud());
System.out.println("\nLA MAGNITUD DEL VECTOR: "+v1.magnitud1());
System.out.println("\nLA MAGNITUD DEL VECTOR: "+v1.magnitud2());
System.out.println("\nVECTOR UNITARIO: "+v1.unitario());
System.out.println("\nPRODUCTO ESCALAR ENTRE LOS DOS VECTORES: "+v1.productoEscalar(v2));
System.out.println("\nPRODUCTO CRUZ ENTRE LOS DOS VECTORES: "+v1.productoCruz(v2));
}
}

miércoles, 28 de octubre de 2009

Andres Chiriboga Prueba

/*ANDRES CHIRIBOGA

package Matriz;

import javax.swing.JOptionPane;


public class Matriz {
public int numeroFilas;
public int numeroColumnas;
public double [][]matriz;

public Matriz(int nF, int nC){
numeroFilas=nF;
numeroColumnas=nC;
matriz=new double [numeroFilas][numeroColumnas];

for(int i=0; i for(int j=0; j matriz[i][j]=0;
}

public void leer(){
int i;
for(i = 0; i < this.numeroFilas; i++ ){
for(int j = 0;j < this.numeroColumnas; j++){
String aux;
aux = JOptionPane.showInputDialog(null,"Ingrese el Valor "+"["+(i+1)+","+(j+1)+"]","Ingreso de Valores",
JOptionPane.DEFAULT_OPTION);
this.matriz[i][j] = Double.parseDouble(aux);
}
}
}


public Matriz transpuesta(){
Matriz resultado;
resultado= new Matriz(this.numeroColumnas,this.numeroFilas);
for(int i=0; i< this.numeroFilas;i++)
for(int j=0; j< this.numeroColumnas;j++ )
resultado.matriz[j][i]= this.matriz[i][j];
return resultado;

}

public Matriz multiplicacion(Matriz b){
Matriz resultado;

if(this.numeroColumnas == b.numeroFilas){
resultado=new Matriz(this.numeroFilas,b.numeroColumnas);
for(int i=0; i for(int j=0; j for(int k=0; k resultado.matriz[i][j] += (this.matriz[i][k]*b.matriz[k][j]);
}
}
return resultado;
}
else
System.out.println("ERROR EN DIMENSIONES DE LAS MATRICES");
resultado=null;
return resultado;
}

public String toString(){
String aux = "[";
for(int i=0; i for(int j=0; j aux+=matriz[i][j]+" ";
}
aux+="\n";
}
aux+= "]";
return aux;
}



}
package Matriz;

import javax.swing.JOptionPane;


public class PruebaMatriz {
public static void main(String args[]){
Matriz c = new Matriz(2,3);
c.leer();
Matriz b = new Matriz(5,3);
b.leer();
Matriz a = new Matriz(1,5);
a.leer();
Matriz e = new Matriz(3,3);
e.leer();


System.out.println((a.multiplicacion(b).multiplicacion(e)));
JOptionPane.showMessageDialog(null,(a.multiplicacion(b).multiplicacion(e)).toString(),"Resultado 1",JOptionPane.DEFAULT_OPTION );

System.out.println(c.multiplicacion(e).multiplicacion(transpuesta (b)));
JOptionPane.showMessageDialog(null,(c.multiplicacion(e).multiplicacion(transpuesta (b))).toString(),"Resultado 2",JOptionPane.DEFAULT_OPTION );

System.out.println(c.multiplicacion(e).multiplicacion(transpuesta (b)).multiplicacion(transpuesta (a)));
JOptionPane.showMessageDialog(null,(c.multiplicacion(e).multiplicacion(transpuesta (b)).multiplicacion(transpuesta (a))).toString(),"Resultado 3",JOptionPane.DEFAULT_OPTION );

}


domingo, 18 de octubre de 2009

Multiplicacion de matrices

Andrés Chiriboga
public class PruebaMatriz {

public static void main(String args[]){

Matriz a = new Matriz(2,2);
a.matriz[0][0] = 1; a.matriz[0][1]=2;
a.matriz[1][0] = 3; a.matriz[1][1]=4;

System.out.println(a.toString());

Matriz b = new Matriz(2,2);
b.matriz[0][0] = 5; b.matriz[0][1]=6;
b.matriz[1][0] = 7; b.matriz[1][1]=8;

System.out.println(b.toString());

Matriz c;
c= a.suma(b);
System.out.println(c.toString());

c= a.transpuesta();
System.out.println("Transpuesta de a\n"+c.toString());


c= a.multiplicacion(b);
System.out.println(c.toString());
}

}

public class Matriz {

public int numeroFilas;
public int numeroColumnas;
public double [][]matriz;
/**
* Constructor sin parametros
*/

public Matriz (){

}

/**
* Constructor con parametros
* @param nF numero de Filas
* @param nC numero de Columnas
*/

public Matriz(int nF, int nC){
numeroFilas =nF;
numeroColumnas =nC;
matriz = new double[numeroFilas][numeroColumnas];

for (int i = 0; i < numeroFilas; i++)
for (int j = 0; j< numeroColumnas; j++)
matriz[1][j] = 0;
}
/**
* Metodo de suma matrices
* @param B primer sumando
* @return MAtriz resultado de la suma
*/

public Matriz suma(Matriz B){
Matriz resultado;
if((this.numeroFilas == B.numeroFilas)&(this.numeroColumnas == B.numeroColumnas)){
resultado = new Matriz(this.numeroFilas,this.numeroFilas);
for(int i =0; i for(int j=0; j< this.numeroColumnas; j++)
resultado.matriz[i][j] = this.matriz[i][j] +B.matriz[i][j];
return resultado;
}
else{
System.out.println("Error en dimenciones de la matriz");
resultado = null;
return resultado;
}
}
/**
* Metodo de multiplicacion de matrrices
* @param B primera multioplicacion
* @return MAtriz resulatado de la multiplicacion
*/
public Matriz multiplicacion(Matriz B){
Matriz resultado;
if((this.numeroFilas == B.numeroFilas)&(this.numeroColumnas == B.numeroColumnas)){
resultado = new Matriz(this.numeroFilas,this.numeroFilas);
for(int i =0; i for(int j=0; j< this.numeroColumnas; j++)
resultado.matriz[i][j] = this.matriz[i][j] *B.matriz[i][j];
return resultado;
}
else{
System.out.println("Error en dimenciones de la matriz");
resultado = null;
return resultado;
}
}


/**
* Metodo para transponer matrices
* @return Matriz transpuesta
*/
public Matriz transpuesta(){
Matriz resultado;
resultado = new Matriz (this.numeroColumnas,this.numeroFilas);
for(int i =0; i for(int j=0; j< this.numeroColumnas; j++)
resultado.matriz[j][i] = this.matriz[i][j];
return resultado;

}
/**
* DEvuelve el objeto matriz en texto
* @return
*/

public String toString(){
String aux = "[ ";
for(int i = 0; i< numeroFilas; i++){
for (int j = 0; j< numeroFilas; j++){
aux += matriz [i][j]+" ";

}
aux += "\n";
}
aux += " ]";
return aux;
}
}

martes, 13 de octubre de 2009

progra

public class Cuadrado {
private double CoordenadaX;
private double CoordenadaY;

public Cuadrado(){
setCuadrado (0,0);
}

public Cuadrado(double x, double y){
setCuadrado(x,y);
}

public void setCuadrado(double x, double y){
CoordenadaX = x;
CoordenadaY = y;
}

public double getCoordenadaX(){
return CoordenadaX;
}
public double getCoordenadaY(){
return CoordenadaY;
}

public String toString(){
return "Punto de coordenadas:"+"["+CoordenadaX+","+
CoordenadaY+"]";
}
public static void main (String args[] ){
Cuadrado p1 = new Cuadrado (0,0);
Cuadrado p2 = new Cuadrado (1,0);
Cuadrado p3 = new Cuadrado (1,1);
Cuadrado p4 = new Cuadrado (0,1);

System.out.println(p1.toString());
System.out.println(p2.toString());
System.out.println(p3.toString());
System.out.println(p4.toString());

System.out.println("Coordenada x " +p1.getCoordenadaX()+5);
System.out.println("Coordenada y " +p1.getCoordenadaY());
System.out.println(p1.toString());
p1.setCuadrado(p1.getCoordenadaX()+5,p1.getCoordenadaY());
System.out.println(p1.toString());
}

}

public class Triangulo {
private double CoordenadaX;
private double CoordenadaY;

public Triangulo(){
setTriangulo (0,0);
}

public Triangulo(double x, double y){
setTriangulo(x,y);
}

public void setTriangulo(double x, double y){
CoordenadaX = x;
CoordenadaY = y;
}

public double getCoordenadaX(){
return CoordenadaX;
}
public double getCoordenadaY(){
return CoordenadaY;
}

public String toString(){
return "Punto de coordenadas:"+"["+CoordenadaX+","+
CoordenadaY+"]";
}
public static void main (String args[] ){
Triangulo p1 = new Triangulo (0,0);
Triangulo p2 = new Triangulo (5,0);
Triangulo p3 = new Triangulo (2.5,7);


System.out.println(p1.toString());
System.out.println(p2.toString());
System.out.println(p3.toString());


System.out.println("Coordenada x " +p1.getCoordenadaX()+5);
System.out.println("Coordenada y " +p1.getCoordenadaY());
System.out.println(p1.toString());
p1.setTriangulo(p1.getCoordenadaX()+5,p1.getCoordenadaY());
System.out.println(p1.toString());
}
}

public class Figuras extends Cuadrado{
private double lado;


public Figuras(){
setLado(0);

}

public Figuras(double x, double y, double l){
super(x,y);
setLado(l);
}
public void setLado(double l){
lado = l;
}
public double getLado(){
return lado;
}

public String toStrig(){
return this.toStrig()+"\nel lado es"+lado;
}
public static void main(String args[]){
Figuras c1 = new Figuras(3,2,5);
Cuadrado p1 = new Cuadrado(3,2);

System.out.println(p1.toString());
System.out.println(c1.toString());
System.out.println("el lado es: "+c1.getLado());
System.out.println("coordenada x: "+c1.getCoordenadaX());
System.out.println(p1.toString());
}

}

public class Figurat extends Triangulo {
private double Altura;


public Figurat(){
setAltura(0);

}

public Figurat(double x, double y, double h){
super(x,y);
setAltura(h);
}
public void setAltura(double h){
Altura = h;
}
public double getAltura(){
return Altura;
}

public String toStrig(){
return this.toStrig()+"\nel Altura es"+Altura;
}
public static void main(String args[]){
Figurat c1 = new Figurat(3,2,5);
Triangulo p1 = new Triangulo(3,2);

System.out.println(p1.toString());
System.out.println(c1.toString());
System.out.println("el Altura es: "+c1.getAltura());
System.out.println("coordenada x: "+c1.getCoordenadaX());
System.out.println(p1.toString());
}

}