0

I have an array of length:

int lengthOfArray = 5;
lengthOfArray = ((lengthOfArray * (lengthOfArray - 1)) / 2);
System.out.println(lengthOfArray);

With an array of length 5, this will return that there are ten possible outcomes for a similar operator being used on all of the numbers, with no two numbers being paired again.

I need to come up with an efficient algorithm to calculate all of the sums of the numbers, throw them into an array, add them together, and divide by the number of entries to get the average y-axis change for the day.
After that, I plan to develop a pseudo-intelligent prediction method for guessing the next values.

Has anyone ever done anything like this before? I'm working on a Weather Analysis software based on logs generated by a program I wrote, using JSoup, to parse and interpret into a log file. Goal is to have it running the analysis as it's working on the download of new weather information.

Nick
  • 191
  • 1
  • 2
  • 9
  • 3
    Please, consider providing sample input and output for an algorithm. Also, show us what have you tried to implement and what exactly you want to improve in your implementation. – default locale Sep 26 '13 at 07:52

2 Answers2

1

I need to come up with an efficient algorithm to calculate all of the sums of the numbers, throw them into an array, add them together, and divide by the number of entries to get the average y-axis change for the day.

When you add together the pair-wise sums of a set of numbers, each number will appear in the sum as many times as there are pairs with that number. Therefore the result will be the total sum of the set of numbers times the number of numbers minus one. The pseudocode for an "efficient" way of computing the sum could look something like this:

n = count(numbers)
sumsAddedTogether = sum(numbers)*(n-1)

Then you can just divide by the "number of entries" (is that the number of numbers you are processing, the number of pairs, or something else?) but I have no idea what you mean by "average y-axis change for the day."

Joni
  • 108,737
  • 14
  • 143
  • 193
  • You've given me an easy way to compute the data I need. The number of entries is the number of pairs. – Nick Sep 28 '13 at 21:46
  • In that case the result is the average of the pair wise sums, which is just twice the average of the numbers. – Joni Sep 29 '13 at 09:55
0

Start with points interpolation and Aitken interpolation. This will give you a head start. Learn how a Bezier curve can be generated using a couple of points(it has a weight version too). I remember that Java supports Bezier curve, however, I did it myself years ago without any difficulties.

Silviu Burcea
  • 5,103
  • 1
  • 29
  • 43