Indexing Procedures inside a loop

I have the following two procedures that I'd like to call in a loop:

proc intg1(x);
   retp((x .* dlnm(x,mu[1],sigma[1])));
endp;

proc intg2(x);
   retp((x .* dlnm(x,mu[2],sigma[2])));
endp;

To do that, I have found this additional procedure :

nms = &intg1 | &intg2 ;
proc intgh(x,h);
local intg;
   intg = nms[h];
   local intg:proc;
   retp(intg(x));
endp;

which should return intgh(x) whenever intg(x,h) is called inside the loop "for h=(1, 2, 1)". The problem is that I use intg with the command intquad1, which does not allow me to specify the argument of intg (x,h).

Any idea on how I could alternatively index the intg procedures inside the loop?

Thanks,

 

1 Answer



0



The current version of GAUSS (starting with version 16), is able to pass additional arbitrary arguments to the integration and optimization procedures. Here is a simple example:

scl = 1;
limits = 1|0;

intquad1(&scaleSin, limits, scl);

proc (1) = scaleSin(x, scl);
    retp(sin(x) .* scl);
endp;

This should resolve your problem unless, the extra variable, 'h' in your case, changes during a single call to intquad. If the variable is changed during the call to intquad, then you would have to make 'h' a global variable. In this case, 'h' would not be passed into your procedure, it would just be referenced, for example:

scl = 1;
limits = 1|0;

intquad1(&scaleSin, limits);

//Using global 'scl'
proc (1) = scaleSin(x);
    retp(sin(x) .* scl);
endp;

aptech

1,773

Your Answer

1 Answer

0

The current version of GAUSS (starting with version 16), is able to pass additional arbitrary arguments to the integration and optimization procedures. Here is a simple example:

scl = 1;
limits = 1|0;

intquad1(&scaleSin, limits, scl);

proc (1) = scaleSin(x, scl);
    retp(sin(x) .* scl);
endp;

This should resolve your problem unless, the extra variable, 'h' in your case, changes during a single call to intquad. If the variable is changed during the call to intquad, then you would have to make 'h' a global variable. In this case, 'h' would not be passed into your procedure, it would just be referenced, for example:

scl = 1;
limits = 1|0;

intquad1(&scaleSin, limits);

//Using global 'scl'
proc (1) = scaleSin(x);
    retp(sin(x) .* scl);
endp;

You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.

Try GAUSS for 14 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy