Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

define an output array in function with its size as input

define an output array in function with its size as input

Hello,

I have written a function which supposed to calculate bi-nominal coefficients as bellow:

Code:


function binom_coef
  input Integer n;
  output Integer coef[n+1];
algorithm
  for i in 0:n loop
    coef[i + 1] := comb(n, i);
  end for;
end binom_coef;

class test_binom_coef
  parameter Integer n = 3;
  parameter Integer a[:] = binom_coef(n);
end test_binom_coef;

in which comb(n,i) calculates combination of k from n.

my question is regarding to binom_coef function which i get n as input and then i want to define a vector of n+1 elements. when i run this code i get the following error:

[:3:3-3:27] Error: Dimensions must be parameter or constant expression (in 1 + n).

please help me with an alternative for this code.

Thanks,
Arvin

Edited by: arvinmor - Oct-08-14 17:37:41
There are 0 guests and 0 other users also viewing this topic
You are here: