View Single Post
  #13  
Old 09-09-2013, 10:53 PM
GB449 GB449 is offline
Member
 
Join Date: Aug 2013
Posts: 20
Default Re: *ANSWER* Stuck on #4

Quote:
Originally Posted by IsidroHidalgo View Post
I think you have a typo, is'n it? For me a=(x_1y_1+x_2y_2)/(x_1^2+x_2^2)
I have simulated 100K points using this formula for slope and taken the average. I have run this a number of times but each time I get a different slope all of which are small numbers like +/- 0.00X

The random points (x1, y1) and (x2, y2) I generated are all between -1 and 1. Is the slope I am getting small because the random numbers are between -1 and 1? After all, I am dividing by 100K.

Here's the code
double slope = ((x1*y1) + (x2*y2)) / ((x1*x1) + (x2*x2));

I sum the slopes for each point and compute average
AverageSlope = SumSlope / (double) NoOfPoints;
Reply With Quote