0

I have

int a ;
int b ; 
int c ;
range m= 1..a;
range n= 1..b;
range o= 1..c;
int s[m]=[11,1,1,1,1,1,1,1,1,1];
int q[m][o]=[[4,5,0,2],[3,2,1,0],[0,1,4,5],[3,2,0,1],[2,1,3,2],[4,3,2,1],[3,4,2,0],[5,0,3,1],[0,4,3,3],[4,0,4,1]];
a=length(s);
b= sum(i in m) s[i];
c=length(q[m]);
int d[o]
forall(k in o)
   int d[k]= sum(i in m) (s[i]*q[i][k]);

The statements for a,b,c,d are not correct. I dont want to initialise diectly for a,b,c,d, and I need to store a as length of s[m] which is 10, b as sum of s[m] which is 20, c as length of one D element of q[m][o] which is 4, and d[k] for as sumproduct of s and q for each k which is 68,72,22,36 respectively. Help would be appreciated.

1 Answer 1

0
int a=10 ;
 
int c=4 ;
range m= 1..a;

range o= 1..c;
int s[m]=[11,1,1,1,1,1,1,1,1,1];
int q[m][o]=[[4,5,0,2],[3,2,1,0],[0,1,4,5],[3,2,0,1],[2,1,3,2],[4,3,2,1],[3,4,2,0],[5,0,3,1],[0,4,3,3],[4,0,4,1]];
//a=length(s);
int b= sum(i in m) s[i];
//c=length(q[m]);
int d[k in o]=sum(i in m) (s[i]*q[i][k]);
execute
{
  writeln("d=",d);
}

works fine and gives

d= [68 72 22 36]

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.