Se va a usar el mismo programa que para Vectores 3D
Main. ClaseMatriz
public class Matriz {
public int numerofilas;
public int numerocolumnas;
public double [][]matriz;
public Matriz(){
}
public Matriz(int nf, int nc){
numerofilas = nf;
numerofolumnas = 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 las 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,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;
}
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;
}
}
Main.ClaseVector
public class Vector3D extends Matriz{
double coorX;
double coorY;
double coorZ;
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 double magnitud1(){
double resultado;
resultado = this.coorX*this.coorX+this.coorY*this.coorY+this.coorZ*this.coorZ;
resultado = Math.sqrt(resultado);
return resultado;
}
//Otra forma de calcular la magnitud
public double magnitud2(){
double resultado;
resultado = Math.pow(this.coorX, 2)+Math.pow(this.coorY, 2)+Math.pow(this.coorZ, 2);
resultado = Math.sqrt(resultado);
return resultado;
}
//Calculo del unitario
public Vector3D uni(){
Vector3D uni = new Vector3D();
for(int i=0; i < 3; i++)
uni.matriz[0][i] = this.matriz[0][i]/this.magnitud2();
return uni;
}
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] = 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(3,2,-1);
Vector3D v2 = new Vector3D(1,2,2);
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("\nLa magnitud del vector es: "+v1.magnitud1());
System.out.println("\nLa magnitud del vector es: "+v1.magnitud2());
System.out.println("\nEl vector unitario es: "+v1.unitario());
System.out.println("\nEl producto escalar entre los vectores es: "+v1.productoEscalar(v2));
System.out.println("\nEl producto cruz entre los vectores es: "+v1.productoCruz(v2));
}
}
Main.ClaseMRUV
public class MRUV extends Vector3D{
Matriz posicion;
Matriz velocidad;
Matriz aceleracion;
Matriz desplazamiento;
Matriz velocidad2;
public MRUV(){
}
public MRUV (Vector3D pos, Vector3D veli, Vector3D ace, Vector3D des){
posicion = pos;
velocidad = veli;
aceleracion = ace;
desplazamiento = des;
}
public void calcularPosicion(Vector3D ri, Vector3D veli, Vector3D ace, double t){
posicion = ri.suma((vel0.productoEscalarVector(t)).suma((ace.productoEscalarVector(Math.pow(t,2))).productoEscalarVector(1/2)));
}
public void calcularVelocidad(Vector3D veli, double t, Vector3D ace){
velocidad = veli.suma(ace.productoEscalarVector(t));
}
public void calcularDesplazamiento(Vector3D veli, double t, Vector3D ace){
desplazamiento = (veli.productoEscalarVector(t)).suma((ace.productoEscalarVector(Math.pow(t, 2))).productoEscalarVector(1/2));
}
/*public void calcularVelocidad2(Vector3D veli, Vector3D ace, Vector3D des){
velocidad2 = (Math.pow(vel0, 2)).suma((ace.productoCruz(desplazamiento)).productoEscalarVectorial(2));
}*/
public static void main(String args[]){
MRUV m = new MRUV();
Vector3D ri = new Vector3D (2,1,-1);
Vector3D veli = new Vector3D (0,1,6);
Vector3D ace = new Vector3D (3,-10,4);
double t = 3;
System.out.println("La posicion cuando: t = 3s; ri = 2i+j-k; vi = j+6k; a = 3i-10j+4k es: \n" +m.calcularPosicion(ri, veli, ace, t));
System.out.println("La velocidad cuando: t = 3s; vi = j+6k; a = 3i-10j+4k; es: \n" +m.calcularVelocidad(veli, t, ace));
System.out.println("El desplazamiento cuando: t = 3s; vi = j+6k; a = 3i-10j+4k es: \n" +m.calcularDesplazamiento(veli, t, ace));
}
}
domingo, 29 de noviembre de 2009
martes, 24 de noviembre de 2009
Applet
Un applet es un componente de una aplicación que se ejecuta en el contexto de otro programa, por ejemplo un navegador web. El applet debe ejecutarse en un contenedor, que lo proporciona un programa anfitrión, mediante un plugin, o en aplicaciones como teléfonos móviles que soportan el modelo de programación por applets.
A diferencia de un programa, un applet no puede ejecutarse de manera independiente, ofrece información gráfica y a veces interactúa con el usuario, típicamente carece de sesión y tiene privilegios de seguridad restringidos. Un applet normalmente lleva a cabo una función muy específica que carece de uso independiente.
Ejemplos comunes de applets son las Java applets y las animaciones Flash. Otro ejemplo es el Windows Media Player utilizado para desplegar archivos de video incrustados en los navegadores como el Internet Explorer. Otros plugins permiten mostrar modelos 3D que funcionan con una applet.
Un Java applet es un código JAVA que carece de un método main, por eso se utiliza principalmente para el trabajo de páginas web, ya que es un pequeño programa que es utilizado en una página HTML y representado por una pequeña pantalla gráfica dentro de ésta.
Applet Java
Un applet Java es un applet escrito en el lenguaje de programación Java. Los applets de Java pueden correr en un navegador web utilizando la Java Virtual Machine (JVM), o en el AppletViewer de Sun.
Entre sus características podemos mencionar un esquema de seguridad que permite que los applets que se ejecutan en el equipo no tengan acceso a partes sensibles (por ej. no pueden escribir archivos), a menos que uno mismo le dé los permisos necesarios en el sistema; la desventaja de este enfoque es que la entrega de permisos es engorrosa para el usuario común, lo cual juega en contra de uno de los objetivos de los Java applets: proporcionar una forma fácil de ejecutar aplicaciones desde el navegador web.
En Java un applet (Subprograma), es un programa que puede incrustarse en un documento HTML; es decir en una página Web. Cuando un Navegador carga una página Web que contiene un Applet, éste se descarga en el navegador Web y comienza a ejecutarse. Esto nos permite crear programas que cualquier usuario puede ejecutar con tan solo cargar la página Web en su navegador.
El Navegador que carga y ejecuta el applet se conoce en términos genéricos como el contenedor de Applets. El kit de desarrollo de Software para java 2 (J2SDK) 1.4.1 incluye el contenedor de Applets, llamado appletviewer, para probar los applets antes de incrustarlos en una página Web.
Bibliografia
http://es.wikipedia.org/wiki/Applet_Java
http://es.wikipedia.org/wiki/Applet
A diferencia de un programa, un applet no puede ejecutarse de manera independiente, ofrece información gráfica y a veces interactúa con el usuario, típicamente carece de sesión y tiene privilegios de seguridad restringidos. Un applet normalmente lleva a cabo una función muy específica que carece de uso independiente.
Ejemplos comunes de applets son las Java applets y las animaciones Flash. Otro ejemplo es el Windows Media Player utilizado para desplegar archivos de video incrustados en los navegadores como el Internet Explorer. Otros plugins permiten mostrar modelos 3D que funcionan con una applet.
Un Java applet es un código JAVA que carece de un método main, por eso se utiliza principalmente para el trabajo de páginas web, ya que es un pequeño programa que es utilizado en una página HTML y representado por una pequeña pantalla gráfica dentro de ésta.
Applet Java
Un applet Java es un applet escrito en el lenguaje de programación Java. Los applets de Java pueden correr en un navegador web utilizando la Java Virtual Machine (JVM), o en el AppletViewer de Sun.
Entre sus características podemos mencionar un esquema de seguridad que permite que los applets que se ejecutan en el equipo no tengan acceso a partes sensibles (por ej. no pueden escribir archivos), a menos que uno mismo le dé los permisos necesarios en el sistema; la desventaja de este enfoque es que la entrega de permisos es engorrosa para el usuario común, lo cual juega en contra de uno de los objetivos de los Java applets: proporcionar una forma fácil de ejecutar aplicaciones desde el navegador web.
En Java un applet (Subprograma), es un programa que puede incrustarse en un documento HTML; es decir en una página Web. Cuando un Navegador carga una página Web que contiene un Applet, éste se descarga en el navegador Web y comienza a ejecutarse. Esto nos permite crear programas que cualquier usuario puede ejecutar con tan solo cargar la página Web en su navegador.
El Navegador que carga y ejecuta el applet se conoce en términos genéricos como el contenedor de Applets. El kit de desarrollo de Software para java 2 (J2SDK) 1.4.1 incluye el contenedor de Applets, llamado appletviewer, para probar los applets antes de incrustarlos en una página Web.
Bibliografia
http://es.wikipedia.org/wiki/Applet_Java
http://es.wikipedia.org/wiki/Applet
sábado, 14 de noviembre de 2009
Vectores en tres dimensiones
Main. ClaseMatriz
public class Matriz {
public int numerofilas;
public int numerocolumnas;
public double [][]matriz;
public Matriz(){
}
public Matriz(int nf, int nc){
numerofilas = nf;
numerofolumnas = 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 las 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,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;
}
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;
}
}
Main.ClaseVector
public class Vector3D extends Matriz{
double coorX;
double coorY;
double coorZ;
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 double magnitud1(){
double resultado;
resultado = this.coorX*this.coorX+this.coorY*this.coorY+this.coorZ*this.coorZ;
resultado = Math.sqrt(resultado);
return resultado;
}
//Otra forma de calcular la magnitud
public double magnitud2(){
double resultado;
resultado = Math.pow(this.coorX, 2)+Math.pow(this.coorY, 2)+Math.pow(this.coorZ, 2);
resultado = Math.sqrt(resultado);
return resultado;
}
//Calculo del unitario
public Vector3D uni(){
Vector3D uni = new Vector3D();
for(int i=0; i < 3; i++)
uni.matriz[0][i] = this.matriz[0][i]/this.magnitud2();
return uni;
}
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] = 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(3,2,-1);
Vector3D v2 = new Vector3D(1,2,2);
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("\nLa magnitud del vector es: "+v1.magnitud1());
System.out.println("\nLa magnitud del vector es: "+v1.magnitud2());
System.out.println("\nEl vector unitario es: "+v1.unitario());
System.out.println("\nEl producto escalar entre los vectores es: "+v1.productoEscalar(v2));
System.out.println("\nEl producto cruz entre los vectores es: "+v1.productoCruz(v2));
}
}
public class Matriz {
public int numerofilas;
public int numerocolumnas;
public double [][]matriz;
public Matriz(){
}
public Matriz(int nf, int nc){
numerofilas = nf;
numerofolumnas = 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 las 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,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;
}
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;
}
}
Main.ClaseVector
public class Vector3D extends Matriz{
double coorX;
double coorY;
double coorZ;
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 double magnitud1(){
double resultado;
resultado = this.coorX*this.coorX+this.coorY*this.coorY+this.coorZ*this.coorZ;
resultado = Math.sqrt(resultado);
return resultado;
}
//Otra forma de calcular la magnitud
public double magnitud2(){
double resultado;
resultado = Math.pow(this.coorX, 2)+Math.pow(this.coorY, 2)+Math.pow(this.coorZ, 2);
resultado = Math.sqrt(resultado);
return resultado;
}
//Calculo del unitario
public Vector3D uni(){
Vector3D uni = new Vector3D();
for(int i=0; i < 3; i++)
uni.matriz[0][i] = this.matriz[0][i]/this.magnitud2();
return uni;
}
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] = 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(3,2,-1);
Vector3D v2 = new Vector3D(1,2,2);
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("\nLa magnitud del vector es: "+v1.magnitud1());
System.out.println("\nLa magnitud del vector es: "+v1.magnitud2());
System.out.println("\nEl vector unitario es: "+v1.unitario());
System.out.println("\nEl producto escalar entre los vectores es: "+v1.productoEscalar(v2));
System.out.println("\nEl producto cruz entre los vectores es: "+v1.productoCruz(v2));
}
}
miércoles, 28 de octubre de 2009
Prueba de programación
Matrices.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Christian Arias
*/
public class Matrices {
public int numeroFilas;
public int numeroColumnas;
public double [][] matriz;
public Matrices(){
}
public Matrices (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 Matrices transpuesta(){
Matrices resultado;
resultado= new Matrices(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 Matrices multiplicacion(Matrices b){
Matrices resultado;
if(this.numeroColumnas == b.numeroFilas){
resultado= new Matrices(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.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="[";
for (int i=0; i < numeroFilas; i++){
for (int j=0; j < numeroColumnas; j++ ){
aux+= matriz[i][j]+" ";
}
aux += "\n";
}
aux+="]";
return aux;
}
}
PruebaMatriz.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Christian Arias
*/
public class PruebaMatriz {
public static void main(String args[]){
Matrices a= new Matrices(1, 5);
a.matriz[0][0]= 1; a.matriz[0][1]=-1; a.matriz[0][2]=0;
a.matriz[0][3]= 1; a.matriz[0][4]=1;
System.out.println(a.toString());
Matrices b= new Matrices(5, 3);
b.matriz[0][0]= 6; b.matriz[0][1]=-2; b.matriz[0][2]=5;
b.matriz[1][0]= 4; b.matriz[1][1]=2; b.matriz[1][2]=-1;
b.matriz[2][0]= 0; b.matriz[2][1]=1; b.matriz[2][2]=1;
b.matriz[3][0]= -2; b.matriz[3][1]=-2; b.matriz[3][2]=0;
b.matriz[4][0]= 1; b.matriz[4][1]=0; b.matriz[4][2]=-1;
System.out.println(b.toString());
Matrices c= new Matrices(2, 3);
c.matriz[0][0]= 2; c.matriz[0][1]=2; c.matriz[0][2]=1;
c.matriz[1][0]= 3; c.matriz[1][1]=-1;c.matriz[1][2]=0;
System.out.println(c.toString());
Matrices e= new Matrices (3,3);
e.matriz[0][0]= -1; e.matriz[0][1]=0; e.matriz[0][2]=-1;
e.matriz[1][0]= 1; e.matriz[1][1]=0; e.matriz[1][2]=1;
e.matriz[2][0]= -1; e.matriz[2][1]=1; e.matriz[2][2]=-1;
System.out.println(e.toString());
Matrices f;
f= b.transpuesta();
System.out.println(f.toString());
Matrices h;
h= a.transpuesta();
System.out.println(h.toString());
Matrices n;
n=a.multiplicacion(b);
System.out.println(n.toString());
Matrices g;
g= c.multiplicacion(e);
System.out.println(g.toString());
Matrices i;
i= e.multiplicacion(f);
System.out.println(i.toString());
Matrices m;
m= c.multiplicacion(e);
System.out.println(m.toString());
Matrices r;
r= g.multiplicacion(f);
System.out.println("Multiplicacion de C*E*Bt=\n"+r.toString());
r= n.multiplicacion(e);
System.out.println("Multiplicacion de A*B*E=\n"+r.toString());
r= i.multiplicacion(h);
System.out.println("Multiplicacion de E*Bt*At=\n"+r.toString());
}
}
Resultados de las operaciones
Multiplicacion de C*E*Bt=
[-13.0 -1.0 0.0 0.0 0.0
-44.0 -12.0 -4.0 8.0 0.0
]
Multiplicacion de A*B*E=
[-12.0 5.0 -12.0
]
Multiplicacion de E*Bt*At=
[-6.0
6.0
-12.0
]
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Christian Arias
*/
public class Matrices {
public int numeroFilas;
public int numeroColumnas;
public double [][] matriz;
public Matrices(){
}
public Matrices (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 Matrices transpuesta(){
Matrices resultado;
resultado= new Matrices(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 Matrices multiplicacion(Matrices b){
Matrices resultado;
if(this.numeroColumnas == b.numeroFilas){
resultado= new Matrices(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.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="[";
for (int i=0; i < numeroFilas; i++){
for (int j=0; j < numeroColumnas; j++ ){
aux+= matriz[i][j]+" ";
}
aux += "\n";
}
aux+="]";
return aux;
}
}
PruebaMatriz.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Christian Arias
*/
public class PruebaMatriz {
public static void main(String args[]){
Matrices a= new Matrices(1, 5);
a.matriz[0][0]= 1; a.matriz[0][1]=-1; a.matriz[0][2]=0;
a.matriz[0][3]= 1; a.matriz[0][4]=1;
System.out.println(a.toString());
Matrices b= new Matrices(5, 3);
b.matriz[0][0]= 6; b.matriz[0][1]=-2; b.matriz[0][2]=5;
b.matriz[1][0]= 4; b.matriz[1][1]=2; b.matriz[1][2]=-1;
b.matriz[2][0]= 0; b.matriz[2][1]=1; b.matriz[2][2]=1;
b.matriz[3][0]= -2; b.matriz[3][1]=-2; b.matriz[3][2]=0;
b.matriz[4][0]= 1; b.matriz[4][1]=0; b.matriz[4][2]=-1;
System.out.println(b.toString());
Matrices c= new Matrices(2, 3);
c.matriz[0][0]= 2; c.matriz[0][1]=2; c.matriz[0][2]=1;
c.matriz[1][0]= 3; c.matriz[1][1]=-1;c.matriz[1][2]=0;
System.out.println(c.toString());
Matrices e= new Matrices (3,3);
e.matriz[0][0]= -1; e.matriz[0][1]=0; e.matriz[0][2]=-1;
e.matriz[1][0]= 1; e.matriz[1][1]=0; e.matriz[1][2]=1;
e.matriz[2][0]= -1; e.matriz[2][1]=1; e.matriz[2][2]=-1;
System.out.println(e.toString());
Matrices f;
f= b.transpuesta();
System.out.println(f.toString());
Matrices h;
h= a.transpuesta();
System.out.println(h.toString());
Matrices n;
n=a.multiplicacion(b);
System.out.println(n.toString());
Matrices g;
g= c.multiplicacion(e);
System.out.println(g.toString());
Matrices i;
i= e.multiplicacion(f);
System.out.println(i.toString());
Matrices m;
m= c.multiplicacion(e);
System.out.println(m.toString());
Matrices r;
r= g.multiplicacion(f);
System.out.println("Multiplicacion de C*E*Bt=\n"+r.toString());
r= n.multiplicacion(e);
System.out.println("Multiplicacion de A*B*E=\n"+r.toString());
r= i.multiplicacion(h);
System.out.println("Multiplicacion de E*Bt*At=\n"+r.toString());
}
}
Resultados de las operaciones
Multiplicacion de C*E*Bt=
[-13.0 -1.0 0.0 0.0 0.0
-44.0 -12.0 -4.0 8.0 0.0
]
Multiplicacion de A*B*E=
[-12.0 5.0 -12.0
]
Multiplicacion de E*Bt*At=
[-6.0
6.0
-12.0
]
sábado, 24 de octubre de 2009
Figuras
Este programa calcula el lado de un cuadrado por medio de sus coordenadas, y la altura de un triangulo por medio de sus coordenadas
Main.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package debercuadrado;
/**
*
* @author usuario
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
}
Cuadrado.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author usuario
*/
public class Cuadrado {
private double CoorX;
private double CoorY;
public Cuadrado(){
setCuadrado (0,0);
}
public Cuadrado(double x, double y){
setCuadrado(x,y);
}
public void setCuadrado(double x, double y){
CoorX = x;
CoorY = y;
}
public double getCoorX(){
return CoorX;
}
public double getCoorY(){
return CoorY;
}
public String toString(){
return "Punto coordenadas: "+"["+CoorX+","+CoorY+"]";
}
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.getCoorX()+5);
System.out.println("Coordenada y = " +p1.getCoorY());
System.out.println(p1.toString());
p1.setCuadrado(p1.getCoorX()+5,p1.getCoorY());
System.out.println(p1.toString());
}
}
Triangulo.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author usuario
*/
public class Triangulo {
private double CoorX;
private double CoorY;
public Triangulo(){
setTriangulo (0,0);
}
public Triangulo(double x, double y){
setTriangulo(x,y);
}
public void setTriangulo(double x, double y){
CoorX = x;
CoorY = y;
}
public double getCoorX(){
return CoorX;
}
public double getCoorY(){
return CoorY;
}
public String toString(){
return "Punto de coordenadas:"+"["+CoorX+","+CoorY+"]";
}
public static void main (String args[] ){
Triangulo p1 = new Triangulo (2,0);
Triangulo p2 = new Triangulo (8,1);
Triangulo p3 = new Triangulo (6.3,9);
System.out.println(p1.toString());
System.out.println(p2.toString());
System.out.println(p3.toString());
System.out.println("Coordenada x " +p1.getCoorX()+5);
System.out.println("Coordenada y " +p1.getCoorY());
System.out.println(p1.toString());
p1.setTriangulo(p1.getCoorX()+5,p1.getCoorY());
System.out.println(p1.toString());
}
}
Figura.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author usuario
*/
public class Figura extends Cuadrado{
private double ld;
public Figura(){
setLd(0);
}
public Figura(double x, double y, double l){
super(x,y);
setLd(l);
}
public void setLd(double l){
ld = l;
}
public double getLd(){
return ld;
}
public String toStrig(){
return this.toStrig()+"\nLado ="+ld;
}
public static void main(String args[]){
Figura c1 = new Figura(6,3,7);
Cuadrado p1 = new Cuadrado(6,3);
System.out.println(p1.toString());
System.out.println(c1.toString());
System.out.println("Lado = "+c1.getLd());
System.out.println("Coordenada x: "+c1.getCoorX());
System.out.println(p1.toString());
}
}
FiguraDos.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author usuario
*/
public class FiguraDos extends Triangulo {
private double Al;
public FiguraDos(){
setAl(0);
}
public FiguraDos(double x, double y, double a){
super(x,y);
setAl(a);
}
public void setAl(double a){
Al = a;
}
public double getAl(){
return Al;
}
public String toStrig(){
return this.toStrig()+"\nAltura ="+Al;
}
public static void main(String args[]){
FiguraDos c1 = new FiguraDos(6,3,7);
Triangulo p1 = new Triangulo(6,3);
System.out.println(p1.toString());
System.out.println(c1.toString());
System.out.println("Altura = "+c1.getAl());
System.out.println("Coordenada x: "+c1.getCoorX());
System.out.println(p1.toString());
}
}
Main.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package debercuadrado;
/**
*
* @author usuario
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
}
Cuadrado.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author usuario
*/
public class Cuadrado {
private double CoorX;
private double CoorY;
public Cuadrado(){
setCuadrado (0,0);
}
public Cuadrado(double x, double y){
setCuadrado(x,y);
}
public void setCuadrado(double x, double y){
CoorX = x;
CoorY = y;
}
public double getCoorX(){
return CoorX;
}
public double getCoorY(){
return CoorY;
}
public String toString(){
return "Punto coordenadas: "+"["+CoorX+","+CoorY+"]";
}
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.getCoorX()+5);
System.out.println("Coordenada y = " +p1.getCoorY());
System.out.println(p1.toString());
p1.setCuadrado(p1.getCoorX()+5,p1.getCoorY());
System.out.println(p1.toString());
}
}
Triangulo.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author usuario
*/
public class Triangulo {
private double CoorX;
private double CoorY;
public Triangulo(){
setTriangulo (0,0);
}
public Triangulo(double x, double y){
setTriangulo(x,y);
}
public void setTriangulo(double x, double y){
CoorX = x;
CoorY = y;
}
public double getCoorX(){
return CoorX;
}
public double getCoorY(){
return CoorY;
}
public String toString(){
return "Punto de coordenadas:"+"["+CoorX+","+CoorY+"]";
}
public static void main (String args[] ){
Triangulo p1 = new Triangulo (2,0);
Triangulo p2 = new Triangulo (8,1);
Triangulo p3 = new Triangulo (6.3,9);
System.out.println(p1.toString());
System.out.println(p2.toString());
System.out.println(p3.toString());
System.out.println("Coordenada x " +p1.getCoorX()+5);
System.out.println("Coordenada y " +p1.getCoorY());
System.out.println(p1.toString());
p1.setTriangulo(p1.getCoorX()+5,p1.getCoorY());
System.out.println(p1.toString());
}
}
Figura.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author usuario
*/
public class Figura extends Cuadrado{
private double ld;
public Figura(){
setLd(0);
}
public Figura(double x, double y, double l){
super(x,y);
setLd(l);
}
public void setLd(double l){
ld = l;
}
public double getLd(){
return ld;
}
public String toStrig(){
return this.toStrig()+"\nLado ="+ld;
}
public static void main(String args[]){
Figura c1 = new Figura(6,3,7);
Cuadrado p1 = new Cuadrado(6,3);
System.out.println(p1.toString());
System.out.println(c1.toString());
System.out.println("Lado = "+c1.getLd());
System.out.println("Coordenada x: "+c1.getCoorX());
System.out.println(p1.toString());
}
}
FiguraDos.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author usuario
*/
public class FiguraDos extends Triangulo {
private double Al;
public FiguraDos(){
setAl(0);
}
public FiguraDos(double x, double y, double a){
super(x,y);
setAl(a);
}
public void setAl(double a){
Al = a;
}
public double getAl(){
return Al;
}
public String toStrig(){
return this.toStrig()+"\nAltura ="+Al;
}
public static void main(String args[]){
FiguraDos c1 = new FiguraDos(6,3,7);
Triangulo p1 = new Triangulo(6,3);
System.out.println(p1.toString());
System.out.println(c1.toString());
System.out.println("Altura = "+c1.getAl());
System.out.println("Coordenada x: "+c1.getCoorX());
System.out.println(p1.toString());
}
}
Seno, Coseno y valor de e
Este programa calcula el seno, coseno y el valor de e
Main.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package deberfunciones;
/**
*
* @author usuario
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
}
TablaFunciones.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author usuario
*/
public class TablaFunciones {
public static void main(String args []) {
double x;
double ep;
double y;
double m=0.0;
while(m < 10){
System.out.println("m = "+m);
m+=0.1;
x = Math.sin(m);
System.out.println(" sin ="+x);
x=Math.cos(m);
System.out.println(" cos ="+x);
ep=2.7183;
for(y = 0; y <= 10;y = y+0.1){
System.out.println((Math.pow(ep,y))*(Math.cos(y)));
}
}
}
}
Main.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package deberfunciones;
/**
*
* @author usuario
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
}
TablaFunciones.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author usuario
*/
public class TablaFunciones {
public static void main(String args []) {
double x;
double ep;
double y;
double m=0.0;
while(m < 10){
System.out.println("m = "+m);
m+=0.1;
x = Math.sin(m);
System.out.println(" sin ="+x);
x=Math.cos(m);
System.out.println(" cos ="+x);
ep=2.7183;
for(y = 0; y <= 10;y = y+0.1){
System.out.println((Math.pow(ep,y))*(Math.cos(y)));
}
}
}
}
Potencia, Raíz y Ecuación en Java
Este programa calcula la potencia, la raíz y la ecuación = x + √x
Main.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package operaciones;
/**
*
* @author usuario
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
}
Potencia.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author usuario
*/
public class Potencia{
public static void main(String args []) {
int x = 25;
double y;
double z;
if (x > 0){
System.out.println("Potencia = "+(x*x));
y= (double) x*x;
}
else{
System.out.println("El valor es incorrecto (debe ser mayor a cero)");
}
if (x >= 0){
y = Math.sqrt(x);
System.out.println("Raiz = "+(y));
}
else{
System.out.println("El valor debe ser menor o igual a cero");
}
if (x>=1){
y = Math.sqrt(x);
z = (double) x;
System.out.println("Ecuacion = "+(y+z));
}
else{
System.out.println("El valor debe ser mayor o igual que uno");
}
}
}
Main.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package operaciones;
/**
*
* @author usuario
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
}
Potencia.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author usuario
*/
public class Potencia{
public static void main(String args []) {
int x = 25;
double y;
double z;
if (x > 0){
System.out.println("Potencia = "+(x*x));
y= (double) x*x;
}
else{
System.out.println("El valor es incorrecto (debe ser mayor a cero)");
}
if (x >= 0){
y = Math.sqrt(x);
System.out.println("Raiz = "+(y));
}
else{
System.out.println("El valor debe ser menor o igual a cero");
}
if (x>=1){
y = Math.sqrt(x);
z = (double) x;
System.out.println("Ecuacion = "+(y+z));
}
else{
System.out.println("El valor debe ser mayor o igual que uno");
}
}
}
Suscribirse a:
Entradas (Atom)