PDA

View Full Version : Method for calculating K on website tool


AL
February 23rd, 2005, 10:43 AM
I would like to know the method on the website tool for calculating K.

As mentioned in a previous thread, I have a problem with my code in which K does not converge for certain data sets. I have since discovered that the particular data sets are:
1. small, <= 20 observations
2. have an exteme high value, much greater in value then the 2nd highest

The data set below is an example, where 12.2 is the extreme value. If I change this value to something closer to the peak values, or if i add a bunch more values (increasing the # of observations), K will converge. This suggests that the numbers just don't fit well to a Weibull distribution...EXCEPT for the fact that these numbers work in the web tool. This leads me to wonder I am using the same methodology as the web tool. In the header of the code below is the equation i am using:

K = (Sum from i to N of (U(i)^K * lnU(i)) / Sum from i to N of (U(i)^K))
- ( (1/N) * Sum from i to N of (U(i)^K * lnU(i)) )


/**
* calculateShapeFactor
*
* calculates K, the shape factor
* note the Math.log is the natural log (ie, ln) not log base 10
*
* call this method, passing the returned K until K converge
* K s solved iteratively by:
*
* K = (Sum from i to N of (U(i)^K * lnU(i)) / Sum from i to N of
(U(i)^K)) - ( (1/N) * Sum from i to N of (U(i)^K * lnU(i)) )
*
* @param K starting value for the iterative process
* @param vector vector of values
*
* @return Returns the shape factor.
*/
public double calculatecalculateShapeFactorK (double K,
Vector vector)
{
int N = vector.size();
double reciprocal = (double) 1/N;
double numerator = 0.0D;
double denominator = 0.0D;
double lnSum = 0.0D;
double value = 0.0D;

Enumeration enumeration = vector.elements();
while( enumeration.hasMoreElements() )
{
Double temp = new Double(0.0);
temp = (Double) enumeration.nextElement();
value = temp.floatValue(); // get wind speed

numerator += Math.pow (value, K) * Math.log(value);
denominator += Math.pow (value, K);
lnSum += Math.log(value);
}

K = ( 1 / (( numerator / denominator) - ( reciprocal * lnSum)) );

return K;

}


7.5
4.4
5.2
6
2.6
2.9
3.3
12.2
4
5.1
3.9
3.9
6
5.3
7.3
4.2
4.8
4.9
5.8