Solves the set of n linearequations Ax = b. (LUBKSB must be used with the procedure LUDCMP to do this.)
index A vector, created by LUDCMP, containing the row permutations effected by the partial pivoting.
b On input, b contains the vector on the right-hand side of the equation. Must be of data type FLOAT; other data types will cause incorrect output.
Function INNER_PROD, v1, v2 IF N_ELEMENTS(v1) NE 3 THEN goto, error1 IF N_ELEMENTS(v2) NE 3 THEN goto, error1 sum = 0.0 FOR i=0, 2 DO BEGIN
sum = sum + v1(i) * v2(i)
END RETURN, sum error1:
PRINT, 'vectors not 3d'
RETURN, 0
END arr = FINDGEN(3, 3) arr(*, 0) = [1.0, -1.0, 3.0] arr(*, 1) = [2.0, 1.0, 3.0] arr(*, 2) = [3.0, 3.0, 1.0]
rightvec = [3.0, 0.0, 6.0] PRINT, ' ' PRINT, 'solving system ' PRINT, arr, ' * [x,y,z] = ', rightvec PRINT, ' ' PRINT, ' ' tarr = arr rvec = rightvec LUDCMP, tarr, index, b LUBKSB, tarr, index, rvec PRINT, '... solution for ', rightvec,' $ is ', rvec s1 = rvec PRINT, ' ' PRINT, ' ' PRINT, INNER_PROD(arr(0,*), s1) PRINT, INNER_PROD(arr(1,*), s1) PRINT, INNER_PROD(arr(2,*), s1) PRINT, ' ' PRINT, ' ' END