' compute relative difference between two matrices
' version 4 beta
' 9/19/2000 h

' mat1 = (input) name of matrix
' mat2 = (input) name of matrix
' rdiff = (output) max relative difference between mat1 and mat2 computed as
' max_{r,c}( |mat1(r,c)-mat2(r,c)|/max(|mat1(r,c)|,1) )

subroutine local sub_rmaxdiff(matrix mat1, matrix mat2, scalar rdiff)

if @rows(mat1)=@rows(mat2) and @columns(mat1)=@columns(mat2) then
	rdiff = -1	
	matrix mtmp = mat1 - mat2
	for !r=1 to @rows(mtmp)
		for !c=1 to @columns(mtmp)
			!dtmp = @abs(mtmp(!r,!c))
			if (@abs(mat1(!r,!c)) > 1) then
				!dtmp = !dtmp/@abs(mat1(!r,!c))
			endif
			if (!dtmp > rdiff) then
				rdiff = !dtmp
			endif
		next
	next
else
	rdiff = NA
endif

endsub

