Sunday, March 9, 2014

Printing a variable using loops - algorithm
















I have 3 for loops here that do what I need them to do an individual basis. But, I can't seem to get them to work together. I need to calculate y=LN(E-k), compute the error and error squared value for y and print the variable when the value for y gives the lowest error squared value. Hope this makes sense.
























Java Code:




















//Calculating y=LN(E-k) and Initializing the Array
for(int x=0; x<LNValues.length; x++)
{
//for(int y=0; y<9; y++)
//{
double i = Math.log(eValues[x][0] - kValue);
if(i > 0)
{
LNValues[x][0] = roundThreeDecimals(i);
}
else
{
LNValues[x][0] = 0;
}
//}
}

//Calculating Error Figures and Error Square

for(int x=0; x<errorValues.length; x++){
//for(int y=0; y<9; y++){
double j = LNValues[x][0] - eventSpecies[x][0];
if(j != 0.0){
errorValues[x][0] = roundThreeDecimals(j);
errorSquared[x][0] = roundThreeDecimals(Math.pow(j, 2));
}else{
errorValues[x][0] = 0;
errorSquared[x][0] = 0;
}

//}
}

//Print Error Squared Values

double errorSquareTotal = 0;
for(int x=0; x<errorSquared.length; x++){
//for(int y=0; y<9; y++){
errorSquareTotal += errorSquared[x][0];
//}
}

































No comments:

Post a Comment