Gareth,
the latter code you posted works just marvellous. However, the problem is in reality more tricky:
I need to avoid a negatively indexed matrix to avoid error message,
but, more importantly I need to set the matrix itself, which yields a negative index, to zero.
In the code's last equation, phi matrices on right hand side act as weights to matrices a1, a2, a3. It is actually very important to distinguish between a "naturally zero index" and a "naturally negative index": Phi0 needs to be defined as indentity matrix. By contrast, the negative indexed phi matrices need to be set to zero.
I thought I could solve the problem by creating two subroutines. The first one is a copy paste of yours, but now it would set the index to 1000 instead of zero.
Code: Select all
subroutine set1000(scalar !x)
if !x<0 then
!x=1000
endif
endsub
A second subroutine should recognize, whether a matrix name is 'phi1000'. If yes, it would set such a matrix to zero, otherwise it would keep the matrix untouched. I never take the chain of phi-s up to more than about 30, so it would be well recognizable.
Code: Select all
subroutine setzero(matrix !mat)
if !mat = 'phi1000'
!mat = 0
endif
endsub
This needs to be corrected as I am getting error message when I call it in this code:
Code: Select all
for !index = 2 to 5
!first = !index - 1
call set1000(!first)
call setzero(phi{!first})
!second = !index - 2
call set1000(!second)
call setzero(phi{!second})
!third = !index - 3
call set1000(!third)
call setzero(phi{!third})
matrix phi{!index} = phi{!first} * a1 + phi{!second} * a2 + phi{!third} * a3
next
Please if possible, I woud be very thankful for feedback to this. Thanks for encouragement today, I almost gave it up. For me programming is no easy.