# Multidimensional input to a function

Hi.

I am trying to define a simple function using scripting:

* Inputs: a list of elements, for instance item:id[first]..item:id[last]

* Output: any function of the whole elements (sum for instance)

How should I declare the input in the script of the function?

Under Java, I would have declared as input of my method “test” an array of doubles (“input”) containing the values “item:id[first]..item:id[last]” and written:

double test( double[] input ){

int numberItems = input.length;

double result = 0;

for( int i=0 ; i<numberItems ; i++){

result = result + input[i];

}

return result;

}

Thank you.

Julien

Hi Julien,

Your are doing the most right.

Just write a function like this (a very simple example):

[code:1myxkbs2]

double my_sum(double[] numbers)

{

double sum = 0

for(double number : numbers)

sum += number

return sum

}

[/code:1myxkbs2]

Then you can use this function formulas like these:

[list:1myxkbs2]

‘Sum Values (items 4 to 8)’ = my_sum(Matrix1::Values:Item4 .. Values:Item8)

[/list:u:1myxkbs2]

[list:1myxkbs2]

Sum all = my_sum(Matrix1::Values)

[/list:u:1myxkbs2]

The clue is that you can define the range (or dimension) of the input in a Quantrix formula.

Take the attached model and play around with it.

Is this what you are looking for?

Regards,

Dominik