KVL and KCL Equations - Page 1
Forum section: electronics / beginners

author: cjuried
author_rank: Contributor
timestamp: October 28, 2019, 01:40:54 am
content: Hello,I have a basic circuit (I have attached a screenshot of the circuit) in which I am trying to enter both my KCL and KVL equations into my TI Nspire calculator using the "systems of equations" option. I keep getting a "False" for the answer. I am trying to solve for the three variables: is, ia, ib.The equations are:Equation#1 KCL at Top Node: -is+ia+ib=0Equation#2 KVL @ Left Node: -200+is(4)+ia(20)=0Equation#3 KVL @ Right Loop: ib(80)-ia(20)=0Thank you for your help.

author: Nominal Animal
author_rank: Super Contributor
timestamp: October 28, 2019, 02:51:09 am
content: I don't know what goes wrong for you, but when I tellMaxima(free/open source, available for all OSes)solve([ ia + ib - is = 0, 4*is + 20*ia - 200 = 0, 80*ib - 20*ia = 0 ], [ia, ib, is]);it tells me there is exactly one answer,[[ ia = 8, ib = 2, is = 10 ]]Maple agrees, too.

author: rstofer
author_rank: Super Contributor
timestamp: October 28, 2019, 03:11:39 pm
content: I like working on these problem with Maxima so I'll embed the code here. I highly recommend wxMaxima (the windowing version of Maxima). Of course, I also recommend MATLABCode:/* Kirchhoff's Current Law */KCL1 : Is=(200-Vn)/4$KCL2 : Ia=(Vn-0)/20$KCL3 : Ib=(Vn-0)/80$KCL4 : Is-Ia-Ib=0$res : solve([KCL1,KCL2,KCL3,KCL4])$ /* we could skip the 'res : ' part, replace the $ *//* with a ; and skip the pretty print stuff *//* like this: *//* solve([KCL1,KCL2,KCL3,KCL4]); *//* but I like pretty print */results : float(res)$ /* this stuff is the pretty print of sorted results */lngth : length(results)$sorted : sort(results)$print("KCL")$for i:1 thru lngth doprint(sorted)$print("")$/* Kirchhoff's Voltage Law */KVL1 : 200 - (Ia+Ib)*4 - Ia*20 = 0$KVL2 : 200 - (Ia+Ib)*4 - Ib*80 = 0$KVL3 : Is = Ia + Ib$ /* KVL3 and KVL4 are not required for a solution */KVL4 : Vn = Ia*20$ /* but they provide the other values for the circuit*/res : solve([KVL1,KVL2,KVL3,KVL4])$ /* pretty print stuff again */results : float(res)$lngth : length(results)$sorted : sort(results)$print("KVL")$for i:1 thru lngth doprint(sorted)$Code:KCLIa=8.0Ib=2.0Is=10.0Vn=160.0KVLIa=8.0Ib=2.0Is=10.0Vn=160.0The upper code block is the actual wxMaxima code while the lower code block is the output.You will notice that we disagree on the sign convention for KVL. That's ok, it doesn't matter. However, if I go through a device from (-) to (+), I treat that as a voltage gain. If I go through a device from (+) to (-), I treat that as a loss. In this circuit, all of the resistors are losses and the only gain is the battery because both of my loops are clockwise. One through the inner loop on the left and the other around the outside. That's MY sign convention and it isn't required as long as you are consistent.

author: cjuried
author_rank: Contributor
timestamp: October 29, 2019, 02:01:46 am
content: Thanks for your answers. I changed my syntax and things came to life. I have attached a screenshot of the slight modifications in which TI Nspire calculators seem to be accustom to.

author: Tom45
author_rank: Frequent Contributor
timestamp: October 29, 2019, 04:09:25 am
content: And for us fossils from the slide rule era:Didn't even need to use a slide rule for this one.

author: rstofer
author_rank: Super Contributor
timestamp: October 29, 2019, 05:45:08 am
content: Or, 80 in parallel with 20 => 16 Ohms16 in series with 4 => 20 Ohms200V / 20 Ohms => 10 Amps for Is10 Amps through 4 Ohms => 40V drop200V - 40V => 160V output160V / 20 Ohms => 8 Amps (Ia)160V / 80 Ohms => 2 Amps (Ib)Of course, the real solution has to use the proper technique. All this approach does is verify what has been verified several times above. Still, the problem is simple enough to do these shortcuts in just a moment or two. Just a check...In my view, the take-away is that there is a standardized approach to these equations using something like wxMaxima. Install the software, rip the code and save it away for a day when you get a really difficult circuit. Perhaps in AC theory when there will be inductors and capacitors and you would have to use complex numbers and deal with magnitude and phase.I like Nominal Animal's solution better than mine because it is short, sweet, and right to the point. Very clean! OTOH, I like my solution because it scales well and, with comments, it is more like telling a story. One of the goals of Maxima is to create documents with text, equations and graphs suitable for publication. I have no particular interest in the text or publication features but it sure does a nice job with equations and graphs.

author: Nominal Animal
author_rank: Super Contributor
timestamp: October 29, 2019, 06:07:28 am
content: Oh yeah, mine was only the straightforward math part, I didn't even look at the circuit itself; I kept it as simple as possible, and just wanted to show that the given equations do have a single real solution.When I work on a problem, I create a directory for it, and put the "story" part in aREADME.txtfile.That is because I don't want to have to open wxMaxima to see it; I'm very, very lazy. (And "paranoid", I don't like being beholden to any single application; I much prefer copy-pasting the code, than using Maxima/Maple workbooks for long-term storage.)Even my scripts and example programs show "usage" (summary of the "story") when run without parameters, or with -h or --help. That way I only need to run the likeliest executable in the problem/solution directory, to see what it is about. I have a few hundred of these, and if they're on the same machine (I recently archived most of them), I can find a specific one based on a vague memory in seconds.The story, the context and background for the math, is invaluable in the long term. It takes only a few minutes to write down the context with the solution method. Even if you never end up needing the solution again, writing it up in a concise way (but descriptively enough so you'll re-understand it even after a long interval), also helps most people to better understand the problem at hand. It is not rare to realize the answer when one constructs an efficient way to ask the question.When I have a complete solution on a math problem, I usually write it up in LibreOffice Writer, and save both that and a PDF "print" version (that I'll consult when necessary). I really should move to LaTeX, though.

author: rstofer
author_rank: Super Contributor
timestamp: October 29, 2019, 02:54:53 pm
content: You spend a lot more time on this kind of thing than I do. I'll comment the code and that's about it. OTOH, these are just brain exercises for an old man who is long retired.I like Tom45's solution as well. I remember solving these problems in exactly that way back in the very early '70s. 3x3 was ok, 4x4 was doable, 10x10 for the Statics class was not as much fun even though the matrix was quite sparse. Sloppy handwriting probably came up about here...

author: Tom45
author_rank: Frequent Contributor
timestamp: October 29, 2019, 04:32:45 pm
content: This is obviously an artificial class problem. To build it you would need a 200 volt, 10 amp supply (2KW), a 4 ohm 400 Watt resistor, 20 ohm 1280 watt resistor (!), and an 80 ohm 320 watt resistor.So what is the point of the exercise? First it seems to be testing knowledge and application of Kirchoff's laws. As a class problem, that might be all that is needed.However, cranking through the equations is needed in real life. So in engineering classes that step would usually be tested too.The solution I gave reflects what I would have had to do in the 60's. Others here used a specialized calculator, or some math software packages.So I wonder what would be general practice in a modern circuits class. And also, what would be general practice in the industry, assuming you had to solve a problem like this. Would anyone even think of starting with Kirchoff's laws, or just build it up in Spice or equivalent and click the button?

author: rstofer
author_rank: Super Contributor
timestamp: October 29, 2019, 05:00:07 pm
content: Quote from: Tom45 on October 29, 2019, 04:32:45 pmMy guess is there would be a hybrid solution. Do it by hand, back it up with MATLAB. Print the MATLAB output to .pdf and submit the homework electronically. Actually, this isn't a guess. This is the process used at the local university and there is a required MATLAB course at the beginning of the engineering curriculum.In the specialized area of electronics engineering, LTspice might be an option. I can't imagine anyone doing complex filters by hand. Even way back in the early '70s, I had access to the IBM Electronic Circuit Analysis Program (ECAP) and an IBM1130 computer. Filter calculations weren't nearly as dreadful and, if I did solve the problem by hand, I had a reference solution. ECAP would produce punched card output but it didn't know about the plotter. I wrote a bit of FORTRAN to solve that problem. My Bode' Plots look pretty good on log-log paper.Remember that awful Differential Equations course? "Assume the solution if of the form ..." was popular at the time. My grandson's DE course revolves around the ODE45 solver in MATLAB. They're missing out on all of the fun! Actually, some of the homework is done by hand but, as that is too hard to grade, the vast majority of it is interactive.In industry, I doubt that anyone is doing hand calculations. There's just too much risk of slipping a digit. It was pretty common with slide rules and I don't suspect things have changed. Besides, almost every solution needs a graph and more points is better than less.That MATLAB is a required course is pretty telling. Still, a bit of hand-waving is useful in the learning process. How variations in components will affect the solution. Wait! ECAP would do that! You could iterate over component variations. Clear back in the very early '70s.I would expect today's EE student to have to create the mesh and node equations. How they solved them might vary. I doubt anybody is doing row elimination when they can just plop the equations in a solver (calculator, wxMaxima, MATLAB/Octave). Maybe they see a problem or two solved this way but I doubt that it is common practice.

author: RoGeorge
author_rank: Super Contributor
timestamp: October 29, 2019, 05:25:37 pm
content: The circuit and the values are obviously made for mental calculations.No need for KVL, programs or computers: There are 2 resistors in parallel, then connected with a 3rd one in series.R|| = 20 || 80 = 20*80/(20+80) = 1600/100 = 16R total = 16 + 4 = 20I source = 200/20 = 10 AIa is 4 times bigger than Ib, and together are 10 A, soIa = 8AIb = 2AVo = 2*80 = 160V

author: GerryR
author_rank: Frequent Contributor
timestamp: October 29, 2019, 05:58:23 pm
content: Yeah, back in my fossil days, they would say that the solution(s) were "intuitively obvious," and then after two or three pages of calculations later, maybe it was somewhat obvious.In this case, I agree with RoGeorge that the values were made for quick mental calculations and to give the student some training in recognizing different component combinations to simplify analysis.

author: rstofer
author_rank: Super Contributor
timestamp: October 29, 2019, 06:59:15 pm
content: I agree, the point is building the equations. There are at least 3 ways of writing the mesh equations (and I don't think there are more) and just 1 way to write the node equation. In school, we seemed to focus on KVL but in many cases KCL is easier and may involve fewer equations.The numbers were neat but the magnitudes were gross. We simply don't work in Amps and Ohms, it's more likely mA and kOhms. Volts aren't in hundreds, they're down around 5 or 3.3. It doesn't matter, it's the process of writing the equations that matters.I can hardly wait for the AC circuits!"Intuitively obvious to the most casual observer!"

author: Tom45
author_rank: Frequent Contributor
timestamp: October 30, 2019, 06:35:31 pm
content: My college years far predates Matlab or equivalent. So I've never had any experience with what seems to be a common tool now.However ECAP is very familiar to me. In 1966 I ported ECAP from IBM 1620 FORTRAN II to CDC 3300 FORTRAN IV. Source was 4 boxes of punched cards. Once ported, I wrote an introductory user manual for it. Needless to say, I remember nothing about the details of using it. But I do remember many of the general features such as sensitivity analysis. 4 boxes of punched cards was somewhat less than 8000 lines of source code. Amazing what ECAP could do in what today would be a tiny program.I later ported MIMIC, an analog computer emulation that ran on digital computers. I don't remember the source computer, but the target was again the CDC 3300. The last job of that trilogy was to port CIRCUS, a more advanced program that ran on an IBM 7094. It used quite a bit of 7094 assembly language which made the task a lot harder. I never finished it as I was reassigned to something else. I doubt anyone else ever attempted to finish it either.

author: rstofer
author_rank: Super Contributor
timestamp: October 30, 2019, 07:14:14 pm
content: I'm a little behind you, I started college (again) in 1969. I was playing with the IBM1130 by 1970 and I well remember carrying a box of cards from my office to the computer lab about 1/4 mile away. Did it all the time. Came in on weekends to work on homework. I spent so much time there the manager was beginning to think he should just hire me.I also had the source to ECAP and I think I still do. It's been a couple of years but I think I have it running on my FPGA version of the 1130. I also have CSMP, the Continuous Systems Modelling Program.I also had some restricted access to the CDC 6400 but the cost per minute was so high I didn't use it much.The IBM1130 was my first computer and is still my favorite. It was amazing what you could do 8k words of core when you go clever with overlays.I graduated in '73 and did grad school in '75-'76, right at the very beginning of the microcomputer era. It's been an amazing ride!

author: SiliconWizard
author_rank: Super Contributor
timestamp: November 05, 2019, 09:33:01 pm
content: KVL is for the birds anyway.