JSR 275 - Units, Percent Per Second

I need to represent the unit of interest per second using the universes and measures of JScience.org JSR 275 . I am trying to do the following:

Unit<Dimensionless> PERCENT_PER_SECOND = NonSI.PERCENT.divide(Si.SECOND).asType(Dimensionless.class) 

but I get a ClassCastException when I try to do this.

The following works, but I'm not sure if there is a better way:

 public interface PercentOverTime extends Quantity {} public static Unit<PercentOverTime> PERCENT_PER_SECOND = new BaseUnit<PercentOverTime>("%/s"); 

Any thoughts? The closest I could find was the question about “Culinary Measurements” (this is how I saw how to define my own units).

+4
source share
3 answers

I wrote this sample code to check 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 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 an independent variable (for example, as seconds) and a relation as an independent variable (for example, in percent), then the time derivative of this function will have time as an independent variable, but will have a “time ratio” like dependent.

Yes, the relationship is dimensionless, so it’s a bit strange, but you could imagine a graph of the percentage change in the day per day at the price of stocks, and then a graph of the percentage change in the day of the stock price day after day.

So what does this print?

 -3.0 %/s 

This is what we expect the rate of change to change from 50 to 20 percent in 10 seconds.

So, your device design should look like this:

  Unit<?> magicUnit = NonSI.PERCENT.divide(SI.SECOND); Dimension magicDimension = Dimension.NONE.divide(Dimension.TIME); System.out.println(magicUnit + " measures " + magicDimension + " (" + magicUnit.getDimension() + ")"); 

Indeed, it prints %/s measures 1/[T] (1/[T]) , as we expect.

So, we have the Unit and Dimension, and we can do the Measures. How much do we measure? The docs say this:

Individual quantities are usually different physical sizes; although this is not required, it is necessary, for example, to have a torque and the Energy is of the same size, but has a different nature (vector for torque, scalar for energy).

So, while the frequency will appear to be the correct quantity, it does not actually express the semantic quantity, which we seem to be discussing.

In conclusion, your first line of code does not work, because in the included 1 / [T] model, the Freqency value is measured, not the Dimensionless value. Therefore, if you do not want to create your own quantity, use Unit. The size you are looking for is None / Time, or% / second if you want the correct scalar factors to be there. Finally, you decide whether you want to create your own quantity, but it can be useful if you use it in many places.

It would also be useful to get acquainted with the latest events in JScience , as it seems that they decided to Amount (with addition, subtract, multiply, divide, pow, etc.). It would be very easy to do all this dimensional analysis using sums. Just produce a percentage value minus a percentage amount and divide by the sum of a second, and it should make units for you.

+4
source

It has units of measure s^-1 or Hz ( SI.HERTZ in JScience).

Or Unit<Frequency> .

+3
source

Percentage is not a unit, but a scalar - so a percentage per second - is just a scalar value per unit of time, which makes no sense. It's like saying "3 per second." 3 what?

If you include a block of what you are measuring per unit of time that will deliver you the correct unit.

0
source

Source: https://habr.com/ru/post/1310739/


All Articles