miércoles, 28 de septiembre de 2011

CODIGO EN JAVA PARA EL METODO DE BISECCIÓN (Java code for the bisection method)

ULTIMA NOTICIA:Conoce mi libro de lenguaje C, más informes en la siguiente liga
http://bit.ly/2wh12g1






Este programa esta compuesto por un par de clases la clase bisección y la clase demoBisección, en mi otro blog podrás encontrar los códigos para ser descargados en formato java.

BLOG: Programafacilmente/método de bisección


1. CLASE BISECCION

 public class biseccion
{
public float a,xm,b;

public biseccion(float va, float vb)
{
a=va;
b=vb;
}

public float f(float x)
{
float y;
y=(x*x)-5;
return(y);
}

public float prom(float a, float b)
{
xm=(a+b)/2;
return(xm);
}


}


2. CLASE DEMOBISECCION 


public class demoBiseccion
{
public static void main(String args[])

{

int i,it;
i=0;
it=30;
float a=0,b=3,fa,fb,r,fr;
System.out.println("Demostración de la bisección");
biseccion raiz=new biseccion(a,b);
r=raiz.prom(a,b);
while(i<it)
{
fa=raiz.f(a);
fb=raiz.f(b);
fr=raiz.f(r);
if((fa*fr)<0)
raiz.b=r;
else
if((fb*fr)<0)
raiz.a=r;
r=raiz.prom(raiz.a,raiz.b);

System.out.println("Nueva raiz Xm= "+r+"\tf(x)= "+raiz.f(r));
i++;

}
System.out.println("Solucion r="+r);

}



Actualización: El siguiente código te muestra una mejora en el programa, ya que se encuentra totalmente orientado a objetos: Ir al blog

Codificación, Equipo, Usuario De La Computadora, Pc
The next blog will help you understand the basic programming of a better way (in English )

http://programeasilyare.blogspot.mx/

miércoles, 7 de septiembre de 2011

APPLET DE JAVA PARA GRAFICOS

import java.applet.Applet;
import java.awt.Graphics;
public class applet1 extends Applet
{
public void paint (Graphics gDC)
{

float x,y;
int ox,oy;
int i;
ox=250;
oy=150;
for(i=0;i<180;i++)
{

ox=250;
oy=150;
gDC.drawString(".",ox+i,oy-i);
}

}
}


PAGINA WEB PARA EL APPLET

<html>
<head>
</head>
<body bgcolor="0000aa">
<center>
<applet
code = "applet1.class"
width = "500"
height = "300"
>
</applet>
</center>
</body>
</html>