View Single Post
  #15   Spotlight this post!  
Unread 26-01-2013, 17:12
stingray27's Avatar
stingray27 stingray27 is offline
Registered User
AKA: Michael Ray
FRC #0027 (Team RUSH)
Team Role: Alumni
 
Join Date: Mar 2011
Rookie Year: 2010
Location: Clarkston, MI
Posts: 209
stingray27 is a name known to allstingray27 is a name known to allstingray27 is a name known to allstingray27 is a name known to allstingray27 is a name known to allstingray27 is a name known to all
Re: Can you call and calculate OPR using vb.net

Quote:
Originally Posted by Michael Hill View Post
If you want to calculate OPR, especially on large sets of data, I STRONGLY suggest not trying to invert the matrix. It's an extremely computationally intensive operation. However, SOLVING, the matrix is much less so. You can do so by getting your matrix into reduced row echelon form. Here's the MATLAB code for it, I'm not entirely sure how one would do it in VB, but presumably, you would use the same algorithm:

Code:
function [A,jb] = rref(A,tol)
%RREF   Reduced row echelon form.
%   R = RREF(A) produces the reduced row echelon form of A.
%
%   [R,jb] = RREF(A) also returns a vector, jb, so that:
%       r = length(jb) is this algorithm's idea of the rank of A,
%       x(jb) are the bound variables in a linear system, Ax = b,
%       A(:,jb) is a basis for the range of A,
%       R(1:r,jb) is the r-by-r identity matrix.
%
%   [R,jb] = RREF(A,TOL) uses the given tolerance in the rank tests.
%
%   Roundoff errors may cause this algorithm to compute a different
%   value for the rank than RANK, ORTH and NULL.
%
%   Class support for input A:
%      float: double, single
%
%   See also RANK, ORTH, NULL, QR, SVD.

%   Copyright 1984-2005 The MathWorks, Inc. 
%   $Revision: 5.9.4.3 $  $Date: 2006/01/18 21:58:54 $

[m,n] = size(A);

% Does it appear that elements of A are ratios of small integers?
[num, den] = rat(A);
rats = isequal(A,num./den);

% Compute the default tolerance if none was provided.
if (nargin < 2), tol = max(m,n)*eps(class(A))*norm(A,'inf'); end

% Loop over the entire matrix.
i = 1;
j = 1;
jb = [];
while (i <= m) && (j <= n)
   % Find value and index of largest element in the remainder of column j.
   [p,k] = max(abs(A(i:m,j))); k = k+i-1;
   if (p <= tol)
      % The column is negligible, zero it out.
      A(i:m,j) = zeros(m-i+1,1);
      j = j + 1;
   else
      % Remember column index
      jb = [jb j];
      % Swap i-th and k-th rows.
      A([i k],j:n) = A([k i],j:n);
      % Divide the pivot row by the pivot element.
      A(i,j:n) = A(i,j:n)/A(i,j);
      % Subtract multiples of the pivot row from all the other rows.
      for k = [1:i-1 i+1:m]
         A(k,j:n) = A(k,j:n) - A(k,j)*A(i,j:n);
      end
      i = i + 1;
      j = j + 1;
   end
end

% Return "rational" numbers if appropriate.
if rats
    [num,den] = rat(A);
    A=num./den;
end
I definitely agree. Just at the time I didn't know a lot about matrices because I was a junior in high school. When I wrote my java code for it, I actually calculated the matrix.
__________________
Michael Ray
Team RUSH 27

Driving Record: 93-64-0 Best Finish: Finalist (x4 FiM Districts)
Coaching Record: 16-7-0 Best Finish: Winner (Kettering Invitationa)l