hw3
py
keyboard_arrow_up
School
Arizona State University *
*We aren’t endorsed by this school
Course
591PYTHON
Subject
Electrical Engineering
Date
Jan 9, 2024
Type
py
Pages
3
Uploaded by UltraBoulderHare16
################################################################################
# Created on Fri Aug 24 13:36:53 2018 #
# #
# @author: olhartin@asu.edu; updates by sdm #
# Modified by: Rohith Kalyan Kavadapu #
# ASU ID: 1219703966 # #
# Program to solve resister network with voltage and/or current sources #
################################################################################
import numpy as np # needed for arrays
from numpy.linalg import solve # needed for matrices
from read_netlist import read_netlist # supplied function to read the netlist
import comp_constants as COMP # needed for the common constants
# this is the list structure that we'll use to hold components:
# [ Type, Name, i, j, Value ]
################################################################################
# How large a matrix is needed for netlist? This could have been calculated #
# at the same time as the netlist was read in but we'll do it here #
# Input: #
# netlist: list of component lists #
# Outputs: #
# node_cnt: number of nodes in the netlist #
# volt_cnt: number of voltage sources in the netlist #
################################################################################
def get_dimensions(netlist): #returns the bo of nodes and voltage sources volt_cnt = 0 #initializing the node count
i_array = []
j_array = []
for item in netlist:
i_array.append(item[COMP.I])
j_array.append(item[COMP.J])
if (item[0] == 1):
volt_cnt += 1 # incrementing voltage count i_max = max(i_array) # getting the max i value j_max = max(j_array) # getting the max j value
node_cnt = max(i_max,j_max) # getting the max node value which is the node count
# print(' Nodes ', node_cnt, ' Voltage sources ', volt_cnt)
return node_cnt,volt_cnt
################################################################################
# Function to stamp the components into the netlist #
# Input: #
# y_add: the admittance matrix #
# netlist: list of component lists #
# currents: the matrix of currents #
# node_cnt: the number of nodes in the netlist #
# Outputs: #
# node_cnt: the number of rows in the admittance matrix #
################################################################################
def stamper(y_add,netlist,currents,num_nodes):
# return the total number of rows in the matrix for
# error checking purposes
# add 1 for each voltage source...
(node_cnt,volt_cnt) = get_dimensions(netlist)
current_row = node_cnt - 1 # initializing current row so that the # elements corresponding to the voltage source
# can be added after this.
for comp in netlist: # for each component...
#print(' comp ', comp) # which one are we handling...
# extract the i,j and fill in the matrix...
# subtract 1 since node 0 is GND and it isn't included in the matrix
i = comp[COMP.I] - 1
j = comp[COMP.J] - 1
if ( comp[COMP.TYPE] == COMP.R ): # a resistor
if (i >= 0): # add on the diagonal
y_add[i,i] += 1.0/comp[COMP.VAL] # stamping the resistor values
if (j >= 0):
y_add[j,j] += 1.0/comp[COMP.VAL] if (i >=0 and j >=0):
y_add[i,j] -= 1.0/comp[COMP.VAL]
y_add[j,i] -= 1.0/comp[COMP.VAL]
if (comp[COMP.TYPE] == COMP.VS):
current_row += 1 # incrementing the current row so that the # voltage elements can be stamped at the end of
# stamping resistors
currents[current_row] = comp[COMP.VAL]
if (i >= 0):
y_add[current_row,i] = 1 # Stamping voltage elements
y_add[i,current_row] = 1
if (j >= 0):
y_add[current_row,j] = -1
y_add[j,current_row] = -1
if (comp[COMP.TYPE] == COMP.IS):
if (i >= 0):
currents[i,0] = -comp[COMP.VAL] # Stamping current values in
# current array
if (j >= 0):
currents[j,0] = comp[COMP.VAL]
voltage = solve(y_add,currents) # Solving the linear equation
#EXTRA STUFF HERE!
return (voltage) # should be same as number of rows!
################################################################################
# Start the main program now... #
################################################################################
# Read the netlist!
netlist = read_netlist() # Print the netlist so we can verify we've read it correctly
#for index in range(len(netlist)):
# print(netlist[index])
#print("\n")
(node_cnt,volt_cnt) = get_dimensions(netlist) # Get the no of nodes,no of voltage sources
admittance = np.zeros((node_cnt + volt_cnt, node_cnt + volt_cnt)) # initializing admittance
# arrays
currents = np.zeros((node_cnt+volt_cnt,1)) # initializing currents
voltage = stamper(admittance, netlist, currents, node_cnt) print(voltage)
#EXTRA STUFF H6ERE!
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
3. State the number of significant figures in each of the following: (a)
542, (b) 0.65, (c) 27.25, (d) 0.00005, (e) 40 × 10°, (f) 20,000.
arrow_forward
5
arrow_forward
Hi, I need your help on question 9.52
arrow_forward
question 1
arrow_forward
Hello, I am doing some practice and I am getting hung up on my cross product derivation. I know it is supposed to be zero, but I want to prove it with the math. Could you help me out with this?
Thank you for your time and effort, I appreciate the help.
Please see attached for probelm.
arrow_forward
Vdc0
U=12 V
Circuit
#1
Ried
V LED
www
Ried_series
0.05
Vdc0
U = 12 V
0,04
Circuit
0.03
0.02
0.01
RED LED
GREEN LE
Set current to 10 mA
LED voltages
Given the circuit #1 presented above, answer the following
questions:
BLUE_LEC
Red
0.5
1) Determine the value of the V₁ (voltage forward of the LED)
for the LEDS RED, VDRED GREEN, VREEN and BLUE, VOBLUES
when the current through the LEDs is 10mA,
2) Is the LED in Circuit #1, connected in the way that will be
lighting up or not - Justify your answer
Green
3) Calculate the value of the resistance Rled in Circuit #1, to
ensure that a RED LED will have a current of 10 mA
1.5 2 25
Voltage across LED (V)
4) Calculate the value of the resistance Rled in Circuit #1, to
ensure that a GREEN LED will have a current of 10 mA
Blue
5) Calculate the value of the resistance Rled in Circuit #1, to
ensure that a Blue LED will have a current of 10 mA
6) Given three LEDs, connected in series as shown in the Circui
# 2 (below), calculate the value of the…
arrow_forward
Hi, I need your help on question 9.27
arrow_forward
KINDLY ANSWER THESE THREE QUESTIONS. THANK YOU AND PLEASE PROVIDE EXPLANATION
arrow_forward
please update the solution TT
arrow_forward
question #13 need to check my answers
arrow_forward
Hello, I keep getting lost on this problem. Could you help me through it? Thank you
arrow_forward
Help please
arrow_forward
Having a hard time solving and graphing, can you help me please?
arrow_forward
Which statement(s) is(are) true for photomultiplier tubes?I Photomultiplier tubes are very sensitive detectors, amplifying the photoelectron current by approximately 1 million.II Emitted photoelectrons are accelerated toward positively charged electrodes called dynodes.III Electrons strike the dynode with a kinetic energy less than the original emitted kinetic energy.IV For each electron striking a dynode, more than one electron is knocked free. The additional electrons are accelerated toward the next dynode in the detector where amplification is repeated.
Select one:
a. II, III, and IV
b. II
c. I, II, and IV
d. II and III
e. I and IV
arrow_forward
The squaring function, shifted 7 units upward.
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you

EBK ELECTRICAL WIRING RESIDENTIAL
Electrical Engineering
ISBN:9781337516549
Author:Simmons
Publisher:CENGAGE LEARNING - CONSIGNMENT

Electricity for Refrigeration, Heating, and Air C...
Mechanical Engineering
ISBN:9781337399128
Author:Russell E. Smith
Publisher:Cengage Learning
Related Questions
- question 1arrow_forwardHello, I am doing some practice and I am getting hung up on my cross product derivation. I know it is supposed to be zero, but I want to prove it with the math. Could you help me out with this? Thank you for your time and effort, I appreciate the help. Please see attached for probelm.arrow_forwardVdc0 U=12 V Circuit #1 Ried V LED www Ried_series 0.05 Vdc0 U = 12 V 0,04 Circuit 0.03 0.02 0.01 RED LED GREEN LE Set current to 10 mA LED voltages Given the circuit #1 presented above, answer the following questions: BLUE_LEC Red 0.5 1) Determine the value of the V₁ (voltage forward of the LED) for the LEDS RED, VDRED GREEN, VREEN and BLUE, VOBLUES when the current through the LEDs is 10mA, 2) Is the LED in Circuit #1, connected in the way that will be lighting up or not - Justify your answer Green 3) Calculate the value of the resistance Rled in Circuit #1, to ensure that a RED LED will have a current of 10 mA 1.5 2 25 Voltage across LED (V) 4) Calculate the value of the resistance Rled in Circuit #1, to ensure that a GREEN LED will have a current of 10 mA Blue 5) Calculate the value of the resistance Rled in Circuit #1, to ensure that a Blue LED will have a current of 10 mA 6) Given three LEDs, connected in series as shown in the Circui # 2 (below), calculate the value of the…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK ELECTRICAL WIRING RESIDENTIALElectrical EngineeringISBN:9781337516549Author:SimmonsPublisher:CENGAGE LEARNING - CONSIGNMENTElectricity for Refrigeration, Heating, and Air C...Mechanical EngineeringISBN:9781337399128Author:Russell E. SmithPublisher:Cengage Learning

EBK ELECTRICAL WIRING RESIDENTIAL
Electrical Engineering
ISBN:9781337516549
Author:Simmons
Publisher:CENGAGE LEARNING - CONSIGNMENT

Electricity for Refrigeration, Heating, and Air C...
Mechanical Engineering
ISBN:9781337399128
Author:Russell E. Smith
Publisher:Cengage Learning