Contents - Index


DUPLICATE

 

Duplicate is not a function but rather an EES command.  The Duplicate command is used in Modules, Subprograms and the EES main program to automate operations with array variables.  

 

Within Modules, Subprograms and the EES main program, the Duplicate command provides a shorthand way of entering equations into EES.  The equations that are to be duplicated are enclosed between the Duplicate and End commands.  The lower and upper limits specified for the Duplicate command must be integer number or a variable set to an integer constant ahead of the Duplicate command.  In this application, the Duplicate command  is only useful when used with array variables, e.g., X[j].  For example, the following statements in a Module, Subprogram or EES main program:

 

 N=5

  Duplicate j=1,5

         A[j]=h[j]-T*s[j]

  End

 

are equivalent to:

 

  A[1]=h[1]-T*s[1]

  A[2]=h[2]-T*s[2]

  A[3]=h[3]-T*s[3]

  A[4]=h[4]-T*s[4]

  A[5]=h[5]-T*s[5]

 

The lower and upper loop limits can be any of the following:

  i)   a numerical quantity or expression

  ii)  an EES variable that has been set to a value ahead of the Duplicate statement.

  iii) an EES variable that is set to a value in the Parametric table

 

EES compiles the equations before execution occurs.  It uses a double-pass compiler so it is not strictly required the index limits be defined before the Duplicate statement is processed, but this equation order is recommend.  

 

Note that EES does not allow more than one Duplicate clause to appear within the range of an outer Duplicate clause.  The following code, for example, would result in a compilation error.

 

duplicate i=1,5

 duplicate j=1,6

  x[i,j]=i*j

 end

 duplicate k=1,5 "this will not work"

  y[i,k]=i+k

 end

end

 

However, the intent of these equations can be entered by placing each inner Duplicate clause within its own other clause, as shown below.  These equations will compile with no problems.

 

duplicate i=1,5

 duplicate j=1,6

  x[i,j]=i*j

 end

end

duplicate i=1,5

 duplicate k=1,5

  y[i,k]=i+k

 end

end

 

In the main program or in Subprograms, the statements within Duplicate - End blocks are literally duplicated to generate additional equations.  This is not necessary within an internal Function or Procedure as assignment statements, rather than equalities, are employed.  Duplicate - End blocks within Functions and Procedures are internally rewritten as Repeat-Until blocks, which are more efficient and allow the limits of the Duplicate command to be passed as arguments to the Function or Procedure.  In effect, the following equations:

 

  Duplicate j=1,N

         A[j]:=h[j]-T*s[j]

  End

 

are internally written as:

 

  j:=0

 repeat

      j:=j+1;

      A[j]:=h[j]-T*s[j]

 until (j>=N)

 

You may prefer to explicitly enter the equations in this manner.

 

 

(Note:  use a semicolon instead of a comma as the list separator when using the European numerical format)