*! 1.1.2 18Jun1997 Jeroen Weesie/ICS STB-39 dm49 * code was modelled after -cond- in Matlab 4.0 program define matcond version 5.0 * scratch tempname A U w V maxw minw cc * parse input parse "`*'", parse(",") local A0 "`1'" capt mat `A' = `A0' if _rc { di in red "`A0' is undefined or an illegal matrix expression" exit 198 } local nrA = rowsof(`A') local ncA = colsof(`A') mac shift local options "Cond(str) Display Format(str)" parse "`*'" * Stata's "mat svd" requires #rows >= #cols !!!! if rowsof(`A') < colsof(`A') { mat `A' = `A'' } mat svd `U' `w' `V' = `A' * condition number is ratio of largest to smallest singular value local nw = colsof(`w') scalar `maxw' = 0 scalar `minw' = 1E32 local i 1 while `i' <= `nw' { scalar `maxw' = max(`maxw', `w'[1,`i']) scalar `minw' = min(`minw', `w'[1,`i']) local i = `i'+1 } scalar `cc' = . if (`minw' > 0) { scalar `cc' = `maxw' / `minw' } * output if "`display'" != "" | "`cond'" == "" { if "`format'" == "" { local format "%10.2g" } di in gr "condition number of `A0'[`nrA',`ncA'] = " /* */ in ye `format' scalar(`cc') } else { scalar `cond' = `cc' } end