Question: Programming help (speed up, batch processing, optimizing)

Hi all,

I have been trying to improve my code to speed up a bit.

Here is the toy example:

######################

restart:

myfunc:=proc(phi,p,CH)
 # dummy code
 # dummy code
 # dummy code
 # dummy code
end proc;

a:=myfunc(phi,p1,CH1)
b:=myfunc(phi,p2,CH1)
c:=myfunc(phi,p3,CH1)

ANS1:=w1*a+w2*b+(1-w1-w2)*b

a:=myfunc(phi,p1,CH2)
b:=myfunc(phi,p2,CH2)
c:=myfunc(phi,p3,CH2)

ANS2:=w1*a+w2*b+(1-w1-w2)*b

a:=myfunc(phi,p1,CH3)
b:=myfunc(phi,p2,CH3)
c:=myfunc(phi,p3,CH3)

ANS3:=w1*a+w2*b+(1-w1-w2)*b

a:=myfunc(phi,p1,CH4)
b:=myfunc(phi,p2,CH4)
c:=myfunc(phi,p3,CH4)

ANS4:=w1*a+w2*b+(1-w1-w2)*b

a:=myfunc(phi,p1,CH5)
b:=myfunc(phi,p2,CH5)
c:=myfunc(phi,p3,CH5)

ANS5:=w1*a+w2*b+(1-w1-w2)*b

######################

In this example, I only need ANS1;ANS2;ANS3;ANS4;ANS5;

So eveything that is intermediate can go.

 

I have tried to use something like

map2(myfunc,p1,{CH1,CH2,CH3,CH4,CH5})

But as my 'CH' are in the form of a list, [x,y,z,w,d1,d2,d3]. The procedure my func runs no problem seperately but with map2, I got an error says:

"dimensions must be specified with this type of initializer"

 

Is there a better way to formulate this procedure? I really want to speed up things, avoid loops, use less memory as possible, and fully use QuardCore if possible.

 

Many thanks,

 

Casper

Please Wait...