-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEulerMethod.java
More file actions
51 lines (46 loc) · 1.09 KB
/
EulerMethod.java
File metadata and controls
51 lines (46 loc) · 1.09 KB
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
/**
* this will take in an initial x and y values, the delta x
* and the value we are trying to extrapolate
*
* @author adopt
*
*/
public class EulerMethod {
//data
public double initialX;
public double initialY;
public double stepSize;
public double extrapVal;
public EulerMethod(double x, double y, double ss, double e)
{
initialX = x;
initialY = y;
System.out.println("initial X value is: " + initialX);
System.out.println("initial Y value is: " + initialY);
System.out.println("//////////*****///////////");
stepSize = ss;
extrapVal = e;
}
//methods
public double gradientFinder(double x, double y)
{
double gradient = x*y + 2*y;
return gradient;
}
public void newY()
{
while(initialX<extrapVal)
{
initialY = initialY +gradientFinder(initialX, initialY) *stepSize;
initialX += stepSize;
System.out.println("X value is: " + initialX);
System.out.println("Y value is: " + initialY);
System.out.println("//////////*****///////////");
}
}
public static void main(String args[])
{
EulerMethod em = new EulerMethod(0,1,1,3);
em.newY();
}
}