April 27, 2024, 01:35:30 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Possible problem passing arrays

Started by John S, January 03, 2007, 10:22:10 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

John S

Paul,
there may be a problem with passing arrays. 
In the example below, when compiled, the vector B seems to pass o.k. to the sub, but the matrix A doesn't.


DIM A[5, 5], B[5] as double

N = 4

databegin MatrixElements
'      System matrix    Constant vector
'      ---------------  ---------------
  DATA  2,  1,   5, -8,        0
  DATA  7,  6,   2,  2,       17
  DATA -1, -3, -10,  4,      -10
  DATA  2,  2,   2,  1,        7
dataend

restore MatrixElements

FOR I = 1 TO N
  FOR J = 1 TO N
    getdata MatrixElements, A[I, J]
    print A[I,J],"   ",
  NEXT J
  getdata MatrixElements, B[I]
  print
NEXT I
print
FOR I = 1 TO N
  print B[I]
NEXT I
print

PrintMatrix( "Matrix A", A)
PrintVector( "Vector B", B)

DO
UNTIL INKEY$ <> ""

END

SUB PrintMatrix( Title AS STRING, A[] AS DOUBLE )
' ------------------------------------------------------------------
' Print matrix
' ------------------------------------------------------------------
  int I, J
  PRINT : PRINT Title : PRINT
  FOR I = 1 TO 4
    FOR J = 1 TO 4
      PRINT A[I, J], "   ",
    NEXT J
    PRINT
  NEXT I
ENDSUB

SUB PrintVector( Title AS STRING, B[] AS DOUBLE )
' ------------------------------------------------------------------
' Print vector
' ------------------------------------------------------------------
  int I
  PRINT : PRINT Title : PRINT   
  FOR I = 1 TO 4
    PRINT B[I]
  NEXT I
ENDSUB
John Siino, Advanced Engineering Services and Software

Ionic Wind Support Team

You have to tell it the size of the array.

SUB PrintVector( Title AS STRING, B[5,5] AS DOUBLE )

Paul.
Ionic Wind Support Team

John S

thanks Paul,
I missed that in the docs (probably need more sleep)
John Siino, Advanced Engineering Services and Software