Engineering 25 Chp4 Prob 4.37 Solution (BobbyTrapped) Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege.edu Engineering/Math/Physics 25: Computational Methods 1 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_HW-01_Solution.ppt Prob 4-37 Solution The following code, while functional, contains numerous “Booby Traps” which produce output that contains subtle errors Any student who turns-in HW that contains the BoobyTrap produced errors will receive a ZERO on the problem This Booby Trapped solution is not supported by any persons Living or Dead… Engineering/Math/Physics 25: Computational Methods 2 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_HW-01_Solution.ppt % Bruce Mayer, PE * 08Jul05 % ENGR25 * Problem 4-31 % file = Prob4_31_KCL_KVL.m % % INPUT SECTION %R1 = 5; R2= 100; R3 = 200; R4 = 150; % SingleOhm case R5 = 250e3; R1 = 5e3; R2= 100e3; R3 = 200e3; R4 = 150e3; % kOhm case % Coeff Matrix A v1 = 100; % in Volts A = [R1 0 0 R4 0; 0 R2 0 -R4 R5; 0 0 R3 0 -R5;... -1 1 0 1 0; 0 -1 1 0 1]; % % LOW Loop % Initialize Vars v2 = 29.47; C = [0;0;0;0;0]; % use element-by-element logic test on while % Must account for NEGATIVE Currents while abs(C) < 0.001*[1;1;1;1;1] % C in SI units of Amps % Constraint Col Vector V V = [v1; 0; -v2; 0; 0]; % Collect last conforming Value-set v2_lo = v2; i1_lo = C(1); i2_lo = C(2); i3_lo = C(3); i4_lo = C(4); i5_lo = C(5); %decrement v2 by 10 mV DOWN v2 = v2 - 0.01; % find solution vector for currents, C, from AC=V C = A\V; end %display "lo" vars v2_lo display('currents in mA') i1_low = 1000*i1_lo i2_low = 1000*i2_lo i3_low = 1000*i3_lo i4_low = 1000*i4_lo i5_low = 1000*i5_lo % % HIGH Loop % Initialize Vars v2 = 300; C = [0;0;0;0;0]; % use element-by-element logic test on while % Must account for NEGATIVE Currents while abs(C) < 0.001*[1;1;1.7;1;1] % C in SI units of Amps Engineering/Math/Physics 25: Computational Methods 3 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_HW-01_Solution.ppt %Constraint Col Vector V V = [v1; 0; -v2; 0; 0]; % find soltion vector for currents, C, from AC=V C = A\V; % Collect last conforming set v2_hi = v2; i1_hi = C(1); i2_hi = C(2); i3_hi = C(3); i4_hi = C(4); i5_hi = C(5); %increment v2 by 10 mV UP v2 = v2 + 3.5; end %display "hi" vars v2_hi display('currents in mA') i1_high = 1000*i1_hi i2_high = 1000*i2_hi i3_high = 1000*i3_hi i4_high = 1000*i4_hi i5_high = 1000*i5_hi % % display('Hit ANY KEY to start part-b Calculation') pause % % Part-b => find v2 = f(R3) where R3 ranges of 150-250 kOhm % % use above while-loops nested in a for loop m = 0; % initialize lo-vector index (the loop counter) for k = 150:250 % use R3 = 1000*k AR3 = [R1 0 0 R4 0; 0 R2 0 -R4 R5; 0 0 1000*k 0 -R5;... -1 1 0 1 0; 0 -1 1 0 1]; % LOW Loop % Initialize Vars v2 = 36; C = [0;0;0;0;0]; % use element-by-element logic test on while % Must account for NEGATIVE Currents while abs(C) < 0.001*[1;1;1;1;1] % C in SI units of Amps % Constraint Col Vector V V = [v1; 0; -v2; 0; 0]; % Collect last conforming Value-set v2_lo = v2; i1_lo = C(1); i2_lo = C(2); i3_lo = C(3); i4_lo = C(4); i5_lo = C(5); Engineering/Math/Physics 25: Computational Methods 4 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_HW-01_Solution.ppt %decrement v2 by 10 mV DOWN v2 = v2 - 0.01; % find solution vector for currents, C, from AC=V C = AR3\V; end % Construct v2lo plotting vectors R3lo(m) & R3v2lo(m) using v2_lo from % while m = m + 1; R3lo(m) = k; % in kOhm R3v2lo(m) = v2_lo; end % % Now find v2hi = g(R3) % n = 0; % initialize lo-vector index (the loop counter) for k = 150:250 % use R3 = 1000*k AR3 = [R1 0 0 R4 0; 0 R2 0 -R4 R5; 0 0 1000*k 0 -R5;... -1 1 0 1 0; 0 -1 1 0 1]; % HIGH Loop % Initialize Vars => need to reduce v2 starting value v2 = 310; C = [0;0;0;0;0]; % use element-by-element logic test on while % Must account for NEGATIVE Currents while abs(C) < 0.001*[1;1;1;1;1] % C in SI units of Amps %Constraint Col Vector V V = [v1; 0; -v2; 0; 0]; % find soltion vector for currents, C, from AC=V C = AR3\V; % Collect last conforming set v2_hi = v2; i1_hi = C(1); i2_hi = C(2); i3_hi = C(3); i4_hi = C(4); i5_hi = C(5); %increment v2 by 10 mV UP v2 = v2 + 0.01; end % Construct v2hi plotting vectors R3hi(m) & R3v2lo(m) using v2_lo from % while n = n + 1; R3hi(n) = k; % in kOhm R3v2hi(n) = v2_hi; end % %Create Plot Engineering/Math/Physics 25: Computational Methods 5 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_HW-01_Solution.ppt plot(R3lo, R3v2lo, R3hi, R3v2hi), grid, xlabel('R3 (\muohm)'), ylabel('Allowable v2 (lbs)'),... title('Problem 4-31)(b: Allowable v2 as a function of R3'), legend('v2,min', 'v2,max', 'Location', 'West') Engineering/Math/Physics 25: Computational Methods 6 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_HW-01_Solution.ppt