function integrate(tuples){
	var sum = 0;
	console.log(tuples);
	var boundB = tuples[tuples.length - 1].x;
	var boundA = tuples[0].x;
	for(var i=0;i<(tuples.length-1);i++){
		sum += ((tuples[i+1].x - tuples[i].x)*(tuples[i+1].y + tuples[i].y));
	}
	return (.5 * sum);
}
function xQuad(){
	var tempArr = [];
//	var boundA = $("#boundb").val();
//	var boundB = $("#bounda").val();
	var boundA_String = document.getElementById("bounda").innerHTML;
	var boundA_Int = parseInt(boundA_String);
	var boundB_String = document.getElementById("boundb").innerHTML;
	var boundB_Int = parseInt(boundB_String);

//	for(var i=boundA;i<=boundB;i++){
	for(var i=boundA_Int;i<=boundB_Int;i++){
		var tuple = {};
		tuple.x = i;
		tuple.y = Math.pow(i,2);
		tempArr.push(tuple);
	}
	return tempArr;
}
function xLin(){
	var tempArr = [];
//	var boundA = $("#boundb").val();
//	var boundB = $("#bounda").val();
	var boundA_String = document.getElementById("bounda").innerHTML;
	var boundA_Int = parseInt(boundA_String);
	var boundB_String = document.getElementById("boundb").innerHTML;
	var boundB_Int = parseInt(boundB_String);

	
//	for(var i=boundA;i<=boundB;i++){
	for(var i=boundA_Int;i<=boundB_Int;i++){
		var tuple = {};
		tuple.x = i;
		tuple.y = i;
		tempArr.push(tuple);
	}
	return tempArr;
}
//for testing, runs integrate() with xLin() as input
function integrateXLin(){
	document.getElementById("integral").innerHTML = integrate(xLin());
}
//for testing, runs integrate() with xQuad() as input
function integrateXQuad(){
	document.getElementById("integral").innerHTML = integrate(xQuad());
}
//final onpress function to run with parameters
function integrateFunc(){
	var func = document.getElementById("screen").innerHTML;
	console.log(func);
	//var boundA = $("#bounda").val(); //left
	//var boundB = $("#boundb").val(); //right
	var boundA_String = document.getElementById("bounda").innerHTML;
	var boundA_Int = parseInt(boundA_String);
	var boundB_String = document.getElementById("boundb").innerHTML;
	var boundB_Int = parseInt(boundB_String);
	
	//document.getElementById("integral").innerHTML = integrate(mapper(0,10,1));
	document.getElementById("integral").innerHTML = integrate(mapper(boundA_Int,boundB_Int,1));
}
//onpress function for integrating under function on screen
function drawIntegral(){
	refresh();
	var c = document.getElementById("graph");
	var ctext = c.getContext("2d");
	var tuples = mapper(-256,255,1);
	if(tuples.length < 1){
		tuples = deepCopy(defaultGraph);
	}
	scaleXCoords(tuples, xScaling);
	scaleYCoords(tuples, yScaling);
	//loops for each x
	for(var i=0;i<tuples.length;i++){
		//draws a rectangle with height y and width x at (x,y)
		ctext.fillRect((256+tuples[i].x),(256-tuples[i].y),(1*xScaling),tuples[i].y);
	}
	ctext.closePath();
	drawBorder();
}

@@ -378,32 +378,96 @@
 ounda%22).val();%0D%0A
+%09//takes in the current left bound and converts it to type int%0D%0A
 %09var boundA_Stri
@@ -553,32 +553,97 @@
 oundA_String);%0D%0A
+%09//takes in the current right bound and converts it to type int%0D%0A
 %09var boundB_Stri
@@ -1039,24 +1039,88 @@
 a%22).val();%0D%0A
+%09//takes in the current left bound and converts it to type int%0D%0A
 %09var boundA_
@@ -1210,32 +1210,97 @@
 oundA_String);%0D%0A
+%09//takes in the current right bound and converts it to type int%0D%0A
 %09var boundB_Stri
@@ -2132,16 +2132,80 @@
 /right%0D%0A
+%09//takes in the current left bound and converts it to type int%0D%0A
 %09var bou
@@ -2303,24 +2303,89 @@
 A_String);%0D%0A
+%09//takes in the current right bound and converts it to type int%0D%0A
 %09var boundB_
@@ -2565,16 +2565,126 @@
 0,1));%0D%0A
+%09//passes in the bounds and step size into mapper which is passed into integrate and passes it to the screen%0D%0A
 %09documen

Add comments