/* * ========================================================================== * Compute Currents in an Electrical Circuit * ========================================================================== * Copyright (C) 1996 by Mark Austin and David Mazzoni. * * This software is provided "as is" without express or implied warranty. * Permission is granted to use this software on any computer system, * and to redistribute it freely, subject to the following restrictions: * * 1. The authors are not responsible for the consequences of use of * this software, even if they arise from defects in the software. * 2. The origin of this software must not be misrepresented, either * by explicit claim or by omission. * 3. Altered versions must be plainly marked as such, and must not * be misrepresented as being the original software. * 4. This notice is to remain intact. * * Written By: Mark Austin July 1996 * ========================================================================== */ #include #include "matrix.h" #include "miscellaneous.h" int main( void ) { MATRIX *spResist, *spVoltage, *spCurrent; enum { MatSize = 3 }; int ii, ij; /* [a] : Setup matrix for "resistances in circuit loops" */ spResist = matAllocIndirect( "Resistances", DoubleArray, MatSize, MatSize ); spResist->uMatrix.dpp[ 0 ][ 0 ] = 11; spResist->uMatrix.dpp[ 0 ][ 1 ] = -3; spResist->uMatrix.dpp[ 1 ][ 0 ] = -3; spResist->uMatrix.dpp[ 1 ][ 1 ] = 13; spResist->uMatrix.dpp[ 1 ][ 2 ] = -4; spResist->uMatrix.dpp[ 2 ][ 1 ] = -4; spResist->uMatrix.dpp[ 2 ][ 2 ] = 14; /* [b] : Setup matrix for "voltage gains" in circuit loops */ spVoltage = matAllocIndirect( "Voltage", DoubleArray, MatSize, 1); spVoltage->uMatrix.dpp[ 0 ][ 0 ] = 10; /* [c] : Print "resistance" and "voltage" matrices */ matPrint( spResist ); matPrint( spVoltage ); /* [d] : Solve equations and print currents */ spCurrent = matSolve( spResist, spVoltage ); spCurrent->cpName = saveString( "Currents", __FILE__, __LINE__ ); matPrint( spCurrent ); /* [e] : Clean up */ matFree( spResist ); matFree( spVoltage ); matFree( spCurrent ); }