-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.10
62 lines (47 loc) · 1.75 KB
/
2.10
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
//2.9
//The width of interval: half the difference of the lower and upper bounds
//The width of the result combining two intervals is a function only of the widths of the argument intervals
//Show that the width of the sum of 2 intervals is a function only of the widths of the intervals being added
//add two intervals
//get the width of combined intervals
//demonstrate that the width of the indivdual intervals effects the combined result of the combined interval
function upper_bound(interval){
return Math.max(interval);
}
function lower_bound(interval){
return Math.min(interval);
}
function width_interval(x) {
return (upper_bound(x) - lower_bound(x)) * .5;
}
function add_interval(x,y) {
return make_interval(lower_bound(x) + lower_bound(y),
upper_bound(x) + upper_bound(y));
}
function sub_interval(x,y) {
return make_interval(lower_bound(x) - upper_bound(y),
lower_bound(x) - upper_bound(y));
}
function div_interval(x,y) {
if(y === 0){
console.log('cannot divide interval by 0');
break;
} else {
mult_interval(x, (make_interval(1.0 / upper-bound(y), 1.0 / lower-bound(y)) ));
}
}
function mult_interval(x,y) {//intervals the same width, mult is then different
return make_interval(lower_bound(x) * upper_bound(y)
lower_bound(x) * upper_bound(y));
}
function make_interval(a,b) {
return pair(a,b);
}
function multDivisionCheck(a,b){
if(a !== b){
console.log('two intervals are not a function only of the widths of the intervals being divided/multiplied');
}
}
multDivisionCheck(a,b);
var a = width_interval(mult_interval(make_interval(0,10),make_interval(0,2)));
var b = width_interval(mult_interval(make_interval(-5,5),make_interval(-1,1)));