Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

155 changes: 155 additions & 0 deletions src/evaluation1/evaluation1-secant-newton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package evaluation1;
import java.util.*;
import java.text.DecimalFormat;

public class evaluation1-secant-newton {
static DecimalFormat f = new DecimalFormat("#0.0000");
static Scanner input = new Scanner(System.in);

public static void main(String[] args) {
String pregunta;
int metodo;

imprimirPantallaInicio("de su eleccion");
System.out.println("Ingrese la pregunta: ");
pregunta = input.nextLine();

System.out.print("Selecione el metodo para realizar el problema: "
+ "\n(1)->Metodo Newton-Raphson"
+ "\n(2)->Metodo Secante"
+ "\n(10)->Salir"
+ "\nOpcion-> ");
metodo = input.nextInt();

while(true) {
switch(metodo) {
case 1:
System.out.println("Se ha seleccionado Metodo de Newton-Raphson, ingrese los siguientes datos: ");
System.out.println(f.format(metodoNewton(pregunta)));
break;
case 2:
System.out.println("Se ha seleccionado Metodo de la Secante, ingrese los siguientes datos: ");
System.out.println(f.format(metodoSecante(pregunta)));
break;
case 10:
System.out.println("Saliendo...");
return;
default:
System.out.println("Seleccione un metodo valido (1,2,10)...");
}

System.out.println("Selecione el metodo para realizar el problema: "
+ "\n(1)->Metodo Newton-Raphson"
+ "\n(2)->Metodo Secante"
+ "\n(10)->Salir");
metodo = input.nextInt();

}




}

static void imprimirPantallaInicio(String tipo) {
System.out.println("\n\n\t\tInstituto Tecnológico de Culiacán\n"
+ "\t\tIng. En Sistemas Computacionales\n"
+ "Audelo Salas Diego Alejandro\n"
+ "Brandon Gael Uriarte Lopez\n"
+ "Raices de una Ecuación. Método de " + tipo + "\n"
+ "Métodos númericos\n"
+ "De 13:00 a 14:00 horas. " + "\n"
+ "\nEste programa ejecuta el proceso de cálculo de Racies de una ecuación utilizando el método de "
+tipo+"\n");
}

static double metodoNewton(String pregunta) {
int contador = 1, tCalculos;
double x1,fx1,fx2,dfx1,x2, error;
System.out.print("Ingrese x1 -> ");
x1 = input.nextDouble();
System.out.print("\nIngrese el error -> ");
error = input.nextDouble();
System.out.print("\nIngrese el total de calculos -> ");
tCalculos = input.nextInt();

imprimirPantallaInicio("Newton-Raphson");

fx1=(-0.000234)*(Math.pow((x1-80),2))+1.5;
dfx1 = -0.000468*x1 + 0.03744;
System.out.println("PREGUNTA: " + pregunta);
System.out.println("| Nc\t|\tx1\t|\tf(x1)\t|\tf'(x1)\t|\tx2\t|\tf(x2)\t|");

do{

x2 = x1 - (fx1/dfx1);
fx2 = ((-0.000234)*(Math.pow((x2-80),2)))+1.5;
System.out.println("| "+ contador +"\t| "+f.format(x1)+"\t| "+f.format(fx1)+"\t| "+f.format(dfx1)+"\t| "+f.format(x2)+"\t| "+f.format(fx2)+"\t|");
if(Math.abs(fx2) > error) {
contador ++;
x1=x2;
fx1=fx2;
dfx1 = -0.000468*x2 + 0.03744;
}else if (contador > tCalculos){
System.out.println("Se han superado la cantidad de cálculos necesarios...");
return -1;
}else {
System.out.println("La Raíz de la Ecuación = " + x2);
return x2;
}

}while(Math.abs(fx2) > error && contador < tCalculos);



return 0;
}
static double metodoSecante(String pregunta) {

int contador = 1, tCalculos;
double x1, x2 , x3, error;
double fx1, fx2,fx3;

System.out.print("\nIngrese x1 -> ");
x1 = input.nextDouble();
System.out.print("\nIngrese x2 -> ");
x2 = input.nextDouble();
System.out.print("\nIngrese el error -> ");
error = input.nextDouble();
System.out.print("\nIngrese el total de calculos -> ");
tCalculos = input.nextInt();
imprimirPantallaInicio("la Secante");


fx1=((-0.000234)*(Math.pow((x1-80),2)))+1.5;
fx2=((-0.000234)*(Math.pow((x2-80),2)))+1.5;

System.out.println("PREGUNTA: " + pregunta);

System.out.println("| Nc\t|\tx1\t|\tx2\t|\tf(x1)\t|\tf(x2)\t|\tx3\t|\tf(x3)\t|");

do {

x3=x1-((x1-x2)*fx1)/(fx1-fx2);
fx3=((-0.000234)*(Math.pow((x3-80),2)))+1.5;
System.out.println("| "+ contador +"\t| "+f.format(x1)+"\t| "+f.format(x2)+"\t| "+f.format(fx1)+"\t| "+f.format(fx2)+"\t| "+f.format(x3)+"\t| "+f.format(fx3)+"\t|");
if(Math.abs(fx3) > error && contador <= tCalculos) {
contador++;
x1=x2;
x2=x3;
fx1=fx2;
fx2=fx3;
}else if (contador > tCalculos){
System.out.println("Se han superado la cantidad de cálculos necesarios...");
return -1;
}else {
System.out.println("La Raíz de la Ecuación = " + x3);
return x3;
}
}while(Math.abs(fx2) > error && contador <= tCalculos);

System.out.println("No se ha encontrado la raíz en el rango proupuesto (" + x1+ " - " + x2 + ")");

return -1;
}
}
Loading