Beispiel #1
0
def q1d():
    """
    Question 1(d): Write a program that reads from a file a list of network branches (Jk, Rk, Ek) and a reduced
    incidence matrix, and finds the voltages at the nodes of the network. Use the code from part (a) to solve the
    matrix problem.
    """
    print('\n=== Question 1(d) ===')
    for i in range(1, 7):
        A = Matrix.csv_to_matrix('{}/incidence_matrix_{}.csv'.format(
            NETWORK_DIRECTORY, i))
        Y, J, E = csv_to_network_branch_matrices(
            '{}/network_branches_{}.csv'.format(NETWORK_DIRECTORY, i))
        # print('Y: {}'.format(Y))
        # print('J: {}'.format(J))
        # print('E: {}'.format(E))
        x = solve_linear_network(A, Y, J, E)
        print('Solved for x in network {}:'.format(
            i))  # TODO: Create my own test circuits here
        node_numbers = []
        voltage_values = []
        for j in range(len(x)):
            print('V{} = {:.3f} V'.format(j + 1, x[j][0]))
            node_numbers.append(j + 1)
            voltage_values.append('{:.3f}'.format(x[j][0]))
        save_rows_to_csv('report/csv/q1_circuit_{}.csv'.format(i),
                         zip(node_numbers, voltage_values),
                         header=('Node', 'Voltage (V)'))
Beispiel #2
0
def q2c():
    print('\n=== Question 2(c) ===')
    S = Matrix.csv_to_matrix('report/csv/S.txt')
    voltage = 15
    capacitance = find_capacitance(S, voltage, MESH_SIZE)
    print('Capacitance per unit length: {} F/m'.format(capacitance))