# # Simple calculator for an R-2R Resistor Ladder with any R/R2 ratio # # Copyright (C) 2010 Clifford Wolf # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # function ulist = r2rcalc(u, r1, r2, n) # Circuit Topology: # # GND --[R2]--*--[R1]--*--[R1]--*--[R1]--*-- ..... --*-- OUTPUT # | | | | | # [R2] [R2] [R2] [R2] [R2] # | | | | | # U1 U2 U3 U4 Un Mr1 = zeros(n); for i = 1:n for j = 1:n Mr1(i,j) = min(i,j)-1; endfor endfor Mr2 = ones(n) + eye(n); M = Mr1*r1 + Mr2*r2; # printf("System Matrix:\n"); # disp(M); ulist = ones(1, 2^n); for i = 0:(2^n-1) Us = bitget(i, 1:n)'*u; Is = M \ Us; U = ((0:n-1)*r1 + ones(1,n)*r2) * Is; ulist(i+1) = U; # printf("\n-- %d --\n", i); # printf("Us:\n"); # disp(Us); # printf("Is:\n"); # disp(Is); # printf("U:\n"); # disp(U); endfor endfunction # Usage example: # plot(r2rcalc(5, 100, 220, 6));