function [A,CN]=svdinvert(B) % % Usage: [A] = svdinvert(B) % This function preforms an SVD decomposition on the matrix B. The % inverse is returned in A. % % [A,CN] = svdinvert(B) % The condition number is also calculated and returned in CN. % % Written by Jeffrey A Bloom disp(' svdinvert') MaxCondNum = 10e10; % largest allowed condition number [U,S,V]=svd(B); % calculate the SVD % B = U*S*V' Where S is a diagonal matrix with diagonal elements s. % A = B^(-1) = V*T*U' Where T is a diagonal matrix with diagonal elements 1/s. maxs = max(diag(S)); % largest eigenvalue mins = min(diag(S)); % smallest eigenvalue minw = maxs/MaxCondNum; % smallest allowed eigenvalue smallw = find(diag(S)