commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Luke Lindsay <luke.lind...@gmail.com>
Subject [math] DerivativeStructure constants
Date Fri, 03 Oct 2014 11:40:20 GMT
Hello,

I am using the apache math DerivativeStructure framework.  In general
I find it very useful, however sometimes I find having to specify the
number of free parameters and order for what are essentially constants
makes code complex.

I often find myself writing code similar to the following.

 public DerivativeStructure sum(DerivativeStructure[] values){
        DerivativeStructure sum = new
DerivativeStructure(values[0].getFreeParameters(),
values[0].getOrder());
        for (int i = 0; i < values.length; i++) {
            sum = sum.add(values[i]);
        }
        return sum;
    }

Or

 public DerivativeStructure sum(DerivativeStructure[] values, int
params, int order){
        DerivativeStructure sum = new DerivativeStructure(params, order);
        for (int i = 0; i < values.length; i++) {
            sum = sum.add(values[i]);
        }
        return sum;
    }

I would prefer not to have to worry about getting access to the number
of free parameters and order, and to be able to write something like
the following.

 public DerivativeStructure sum(DerivativeStructure[] values){
        DerivativeStructure sum = DerivativeStructure.constant(0);
//Where DerivativeStructure.constant(x) is equivalent to new
DerivativeStructure(0,0,x);
        for (int i = 0; i < values.length; i++) {
            sum = sum.add(values[i]);
        }
        return sum;
    }

But if I use  DerivativeStructure sum = new
DerivativeStructure(0,0,0), a DimensionMismatchException gets thrown.

Is there a way to avoid the complexities of the code in the first two
examples above?

Luke

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message