Confusion in a question!

I am not getting the third point.
3. The resistance of each of the wires 2 through n – 1.
Should I just take resistance from the user because I am not getting this!


Write a C program that reads the following information about an electrical network:
1. n, the number of wires in the network (Edges)
2. The amount of current entering through the first wire and leaving through the nth. You have
only values of wire 1 that has input to network and nth wire current value that is output of
the network.
3. The resistance of each of the wires 2 through n – 1.
4. A set of ordered pairs <i, j> indicating that wire i is connected to wire j and that
electricity flows through wire i to wire j. It will be a directed graph that can be stored either
by using adjacency matrix showing which wire is connected to each other through junction.
(Junction is a place where two wires are connected. In other words, it’s a node)

The program should compute the amount of current flowing through each of wires 2
though n - 1 by applying Kirchhoff's law and Ohm's law.
Kirchhoff's law states that the amount of current flowing into a junction equals the amount leaving
a junction.

In case when the
Ohm's law states that if from one junction there is two output then voltage remain same for both
wires but current changes according to resistance.
V =I * R

Similarly, in case of two paths exist between two junctions, then the sums of the current’s times
the resistances over all wires in the two paths are equal i.e.
Path_1 = ∑ current ∗ resistance j

1 where j is the number of wires in path 1.

Path_2 = ∑ current ∗ resistance j

1 where j is the number of wires in path 2.
If path_1 and path_2 is between same two junctions, then Path_1=Path_2
From the look of things, I'd say you assume each wire segment between any pair of nodes has unit resistance (ie 1 Ohm).

Write a C program that reads the following information about an electrical network


The program obtains the resistances from user input. The resistance of the input and output wires aren't required, hence the comment "2 through n -1".
this is probably not exactly what you're looking for but i was playing around with this, maybe it will give you some ideas. I wasn't about to get into complex pathing and multiple wires intersecting at a particular junction etc. This might not be correct, it might be complete trash but it seems to work for me. I had an issue trying to make too much stuff happen in the initializer list. Like for whatever reason trying to initialize the resistancePerWire variable via resitancePerWire(calcResistancePerWire()) would fail for whatever reason even though everything else seemed to work correctly...

[snip total trash
Last edited on
@lost110
@againtry is right: according to point 3 you would READ those resistances from file.

It's not point 3 that looks odd - it's point 4. Usually your network (electrical or fluid flow) is specified by saying which NODES you connect, not which wires.



You can solve it by varying the voltages at the nodes until you satisfy Kirchoff's laws: net current out of a junction is 0. (In the fluid-flow analogue you can vary the pressure at the nodes until net flow out of each junction is 0).

For each node a,
net signed current out = external source current in
sumb( Va-Vb ) / Rab = Ia

where:
Va is voltage at node a
Rab is resistance in wire a-b
Ia is (signed) external current into node a


Just solve for the {Va} - e.g. by Gauss-Seidel or Gaussian elimination. (Note that voltages are all relative: you can solve only up to a constant. You have to earth your circuit somewhere.)
Recover the currents from Iab = ( Va-Vb ) / Rab


You can do a similar thing for fluid flow in pipe networks, but the resistance law tends to be quadratic, not linear as in Ohm's law.



@markyrocks
Here's a bridge network for you to try. (Input current I=3A into node 0 and out of node 3; resistance R values for wires are in ohms):
 Network:          1                   
                 / | \                 
            R=10/  |  \R=30            
               /   |   \               
              /    |    \              
      I=3    /     |     \     I=3     
   -------- 0  R=50|      3 ---------  
             \     |     /             
              \    |    /              
               \   |   /               
           R=20 \  |  /R=40            
                 \ | /                 
                   2                   


I think the solution is as follows. (Note that I have, arbitrarily, earthed voltages at node 3).
Voltages (node : volts):
0 : 71.831
1 : 53.2394
2 : 49.0141
3 : 0

Currents (node a : node b : amperes):
0 : 1 : 1.85915
0 : 2 : 1.14085
1 : 2 : 0.084507
1 : 3 : 1.77465
2 : 3 : 1.22535

Last edited on
@lastchance i had just assumed that voltage would be more of a constant. Based on your network, i'm having a rough time wrapping my mind around how you are coming to posted answer. like if you eliminate every thing except for


 Network:          1                   
                 /               
            R=10/            
               /             
              /               
      I=3    /     
   -------- 0  
             \              
              \              
               \             
           R=20 \       
                 \               
                   2                   



in my simplistic mind if you have 3 current coming into a 2 way split and resistance is twice as much in one direction as the other so current on 0-1 would be 2, 0-2 = 1. if there was zero resistance it would be 1.5 on each. That and if were calculating the current at the end of the wire your numbers add up to the input number exactly. I was under the impression that resistance not only was representative of "pressure" in a fluid analogy but in electricity represented a type of loss usually as heat. That kinda goes back to me saying im not sure how this is calculated bc in real world scenarios you'd never be able to add up the amps at the end of 2 runs of wire and have it equal the input exactly unless the wire runs were extremely short or there was zero resistance via extremely oversized wires. I feel like i have some decent comprehension of the subject bc i've done some serious electrical work, last year i installed a solar panel array at my house valued at like 60K. Which is working out swimmingly btw. My last months bill was like -44$. And i was kinda pissed that they didn't add the excess to my "bank" but i guess that was the reset month. They subtracted 128$ from the bill bc of the first 1100kwh we generated and then only paid me like 28$ for the other 500kwh or so quite a disparity.
Last edited on
markyrocks wrote:
in my simplistic mind if you have 3 current coming into a 2 way split and resistance is twice as much in one direction as the other so current on 0-1 would be 2, 0-2 = 1.


Sadly, it doesn't work like that. It depends on resistances further down the line.

Imagine that you took out the wire connecting nodes 1 and 2. Then the TOTAL resistance in the upper line is 10+30=40 ohms and that in the lower line is 20+40=60 ohms. Also, since both lines drop the same voltage, and 1/4 of it is dropped by node 1,but 1/3 of it is dropped by node 2 you can tell that for any wire connecting nodes 1 and 2 the current flow is from 1 to 2. However, once this current starts flowing it changes all currents and voltages.



gotcha i kinda thought you were using the whole network as one circuit but wasn't entirely sure. Why i asked lol. That network is mind bending.

Ok i been playing around with this for a good part of the day and I think I have it figured out. I think the last mistake I made was that I used v3 as zero. They never touched on problems like this in high-school...
Last edited on
You need to lookup the math on how to solve a circuit network. Or maybe your prof gave it to you. It's been 35 years, but as I recall, you define the current running through each loop, then develop the equations for each loop and you're left with a set of linear equations.

Any place where you have 1 wire in and 1 wire out, you can collapse it into a single wire whose resistanace is R1 + R2. But like I said, this is going way back.

The key here is to understand the algorithm for how to solve this first. There's no point writing code until you know what code you're going to write.

Oh, one other oddity: why does the input specify the input and output current? Don't they have to be the same?
The 'loop law' is Kirchoff's Second Law and refers to voltages around the loop. Why that hasn't been included in the @OP problem description is anybody's guess at this stage.
Topic archived. No new replies allowed.