I wrote up this code sample to test out the math here:
public void testUnit() {
// define two points on a function from t -> %
// the rate of change between these two points
// should have unit %/t
Measure<Double, Dimensionless> p0 = Measure.valueOf(50.0, NonSI.PERCENT);
Measure<Double, Dimensionless> p1 = Measure.valueOf(20.0, NonSI.PERCENT);
Measure<Double, Duration> timeDifference = Measure.valueOf(10.0, SI.SECOND);
// JSR-275 has no Amount, so have to convert and do math ourselves
// these doubles are percents
double p0Raw = p0.doubleValue(NonSI.PERCENT);
double p1Raw = p1.doubleValue(NonSI.PERCENT);
// this duration is in seconds
double timeDifferenceRaw = timeDifference.doubleValue(SI.SECOND);
// this is the slope of the secant between the two points
// so it should be the %/s we want
double rateSecant = (p1Raw - p0Raw) / timeDifferenceRaw;
// let's see what we get
Measure<Double, ?> answer = Measure.valueOf(rateSecant,
NonSI.PERCENT.divide(SI.SECOND));
System.out.println(answer);
}
If your original function has time as the independent variable (e.g. as seconds) and a ratio as the independent variable (e.g. as a percent), then the derivative of this function with regard to time will still have time as the independent variable, but will have 'ratio per time' as the dependent.
Yes, ratios are dimensionless, so this is a little bit odd, but you could imagine a graph of the percent change day over day in a stock price and then a graph of the change in the percent change in a stock price day over day day over day.
So what does this print out?
-3.0 %/s
Which is what we expect the rate of change to be for a change from 50 to 20 percent over 10 seconds.
So your unit construction should look like:
Unit<?> magicUnit = NonSI.PERCENT.divide(SI.SECOND);
Dimension magicDimension = Dimension.NONE.divide(Dimension.TIME);
System.out.println(magicUnit + " measures " + magicDimension + " ("
+ magicUnit.getDimension() + ")");
Indeed this prints %/s measures 1/[T] (1/[T])
, as we expect.
So we have a Unit and Dimension and can make Measures. What is the Quantity we are measuring? The docs say this about Quantity:
Distinct quantities have usually
different physical dimensions;
although it is not required nor
necessary, for example Torque and
Energy have same dimension but are of
different nature (vector for torque,
scalar for energy).
So while Frequency would seem to be the correct Quantity, it doesn't really express the semantic quantity we seem to be discussing.
In closing, your first line of code doesn't work because in the included model 1/[T] measures the quantity Freqency, not the quantity Dimensionless. So if you don't want to make your own Quantity, use Unit. The Dimension you are looking for is None/Time, or %/second if you want the correct scalar multipliers in there. Finally, it's up to you whether you want to make your own Quantity, but it might be worthwhile if you're using this in a lot of places.
It would also be worthwhile to check out the latest developments in the JScience space since it seems like they decided Amount (with add, subtract, multiply, divide, pow, etc. methods) was needed. It would be really easy to do all this dimensional analysis with Amount. Just do a Percent Amount minus a Percent Amount and divide by a Seconds amount and it should do the units for you.