-
Notifications
You must be signed in to change notification settings - Fork 0
/
Integrator.java
54 lines (38 loc) · 1.19 KB
/
Integrator.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
/**************************************
Lab 1, Part A, task 1
28 January 2019
Fei Alm, Shamoun Mourad, MT1a
**************************************/
package integrator;
public class Integrator {
public static void main(String[] args) {
double integral = 0.0;
int N = 4;
double base = 2.0/N;
double error = 0.0;
double F2= 8.0/3.0; //kontroll for how big the error is
int intError = 0;
for (int i=1; i < N+1; i++)
{
double height = Math.pow(i*base,2);
//import function from Math-library
double area = height * base;
integral += area;
error = (integral - F2)/F2;
error = Math.round(100.0*error);
intError = (int)error;
// gör om error till int, lagrar i ny variabel
}
System.out.println(integral);
System.out.println(intError);
if(integral > 10.00)
{
System.out.println(String.format("The result is: %4.2f units of length and the error is %-2d%% " , integral , intError));
}
else
{
System.out.println(String.format("The result is: 0%4.2f units of length and the error is %-2d%% " , integral , intError));
}
// When increasing value of N, error value decrease
}
}