METODOS NUMERICOS
Enviado por nita94 • 13 de Febrero de 2014 • 889 Palabras (4 Páginas) • 250 Visitas
MÉTODO DE DESCENSO RÁPIDO O GRADIENTE
package metodo_numerico_udo;
import java.util.Scanner;
public class Gradiente {
public void Descenso_Gradiente()
{
double r[] = {1,1};
double u[] = new double[2];
double tol = 0;
int k = 0;
Scanner s = new Scanner (System.in);
System.out.println ("Ingrese Tolerancia");
tol=s.nextDouble();
while(gradiente(u, r) > tol)
{
System.out.println(k + " " + r[0] + " " + r[1] + " " + f(r));
gradiente(u, r);
r[0] -= tol*u[0];
r[1] -= tol*u[1];
k ++;
}
}
public double f(double r[])
{
return r[0]*r[0] +2.0*r[0] + 3.0*r[1]*r[1];
}
public double gradiente(double u[], double r[])
{
double mag;
u[0] = 2.0*r[0] + 2.0;
u[1] = 6.0*r[1];
mag = Math.sqrt(u[0]*u[0] + u[1]*u[1]);
u[0] /= mag;
u[1] /= mag;
System.out.println("La Respuesta es: "+mag);
return mag;
}
}
MÉTODO DE NEWTON
package metodo_numerico_udo;
import java.util.Scanner;
public class Newton{
private Scanner s = new Scanner (System.in);
private double x0, tol;
private int nIter;
Newton(){
System.out.println("Ingrese Aproximacion: ");
x0=s.nextDouble();
System.out.println("Ingrese Tolerancia: ");
tol=s.nextDouble();
System.out.println("Ingrese No Iteraciones: ");
nIter=s.nextInt();
}
private double f(double x){
double y = (0.01*x + 1)*Math.sin(x)- (x - 0.01)/(Math.pow(x,2) + 1) - 0.0096;
return y;
}
public void calculaRaiz(){
double x = x0, xb = x-999;
double n = 0, del_x = 0.01;
while(Math.abs(x-xb)>tol){
n = n+1;
xb = x;
if(n > nIter) break;
double y = f(x);
double y_driv=(f(x+del_x) - y)/del_x;
x = xb - y/y_driv;
System.out.println(" n="+n+" x= "+x+" y = "+y);
// fprintf(' yd = %12.5e \n', y_driv)
}
System.out.println("La Respuesta es= "+ x);
}
}
MÉTODO DEL PUNTO FIJO
package metodo_numerico_udo;
...