-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheuler_adelante.java
68 lines (58 loc) · 1.88 KB
/
euler_adelante.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import java.util.Random;
public class euler_adelante{
public static double redondear(double valor){
double redondear = 0;
redondear = Math.rint(valor * 100000000)/100000000;
return redondear;
}
public static void main(String[] args) {
int i,
funcion = (int)(Math.random()*3)+1,
calcula = (int)(Math.random()*3)+1;
Random r = new Random();
double max = 3.0,
min = 1.0,
yn = Math.rint((min + r.nextDouble() * (max - min))*10000)/10000,
h = Math.rint((min + r.nextDouble() * (max - min))*10000)/10000,
tn = 0.0,
y = 0;
double resultados[] = new double[2];
System.out.println("\n\t\tEuler Hacia Adelante\n");
switch(funcion){
case 1:
System.out.println("Calcula y1 & y2 con los siguientes datos\n\t3y' - 5yt + 1 = 0\ty0 = "+yn+"\th = "+h+"\tt0 = "+tn+"\n");
for (i=0;i<2;i++){
y = yn + h*(((5*yn*tn)-1)/3);
y = redondear(y);
System.out.println("y"+(i+1)+" = "+y+"\n--------------------");
resultados[i] = y;
yn = y;
tn = tn + h;
}
break;
case 2:
System.out.println("Calcula y1 & y2 con los siguientes datos\n\t1 + y'e^(3t) = 0\ty0 = "+yn+"\th = "+h+"\tt0 = "+tn+"\n");
for (i=0;i<2;i++){
y = yn + h*(-1/redondear(Math.exp(3*tn)));
y = redondear(y);
System.out.println("y"+(i+1)+" = "+y+"\n--------------------");
resultados[i] = y;
yn = y;
tn = tn + h;
}
break;
case 3:
System.out.println("Calcula y1 & y2 con los siguientes datos\n\ty' - t"+(char)178+" - t"+(char)178+"y"+(char)178+" = 0\ty0 = "+yn+"\th = "+h+"\tt0 = "+tn+"\n");
for (i=0;i<2;i++){
y = yn + h*(redondear(Math.pow(tn,2))+redondear(Math.pow(tn,2))*redondear(Math.pow(yn,2)));
y = redondear(y);
System.out.println("y"+(i+1)+" = "+y+"\n--------------------");
resultados[i] = y;
yn = y;
tn = tn + h;
}
break;
default:
}
}
}