Created
March 24, 2014 22:53
-
-
Save JamesEarle/9751077 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Date: March 21st, 2014 | |
* Author: James Earle, 5017843 | |
* Email: je11zi@brocku.ca | |
* | |
* COSC 2P91 - Procedural Programming | |
* Assign. 2, Section 2: Modelling Electronic Circuits | |
* | |
* The program below will read from file and simulate | |
* the effects of a Wheatstone Bridge, outputting the | |
* results of it's arithmetic. | |
* | |
* NOTE: To run this program, the executable must be | |
* associated with the example input file, bridge.txt | |
* This should be done via command line in the following | |
* manner, | |
* Linux/Unix: ./circuit < bridge.txt | |
* Windows: circuit.exe < bridge.txt | |
* | |
* See example output in circuit_output.txt | |
* | |
*/ | |
#include <stdio.h> | |
int main( void ) | |
{ | |
char c; | |
float v,r1,r2,r3,r4,r5,i1,i2,i3,i4,i5, | |
v1,v2,v3,v4,v5,p1,p2,p3,p4,p5; | |
do { | |
if ( scanf("%f",&v) != 1 ) { | |
scanf("%c",&c); | |
} else { | |
scanf("%f %f %f %f %f",&r1, &r2, &r3, &r4, &r5); | |
printf("\nV: %f\nR1: %f\nR2: %f\nR3: %f\nR4: %f\nR5: %f",v,r1,r2,r3,r4,r5); | |
v1 = v / (1+(r4/r1)); | |
v2 = v / (1+(r3/r2)); | |
i1 = v1 / r1; | |
i2 = v2 / r2; | |
v5 = v * ((r3/(r3+r2))-(r4/(r4+r1))); | |
i5 = v5 / r5; | |
i3 = i2 - i5; | |
v3 = i3 * r3; | |
i4 = i1 + i5; | |
v4 = i4 * r4; | |
p1 = i1 * v1; | |
p2 = i2 * v2; | |
p3 = i3 * v3; | |
p4 = i4 * v4; | |
p5 = i5 * v5; | |
printf("\n\nWheatstone Bridge Data Set \n"); | |
printf("\nVoltage Applied:\t\t\t\t\t%.4f\tV",v); | |
printf("\nTotal current flowing through bridge:\t\t\t%.4f\tA",i5); | |
printf("\nTotal power dissipated in the bridge:\t\t\t%.4f\tW",p5); | |
printf("\nPercentage of power dissipated by the meter:\t\t%.2f\t%%\n",100 * (p5/(p1+p2+p3+p4+p5))); | |
printf("\n\t\t\tR1\tR2\tR3\tR4\tR5"); | |
printf("\nResistance[Ohm]\t\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f",r1,r2,r3,r4,r5); | |
printf("\nVoltage[V]\t\t%.4f\t%.4f\t%.4f\t%.4f\t%.4f",v1,v2,v3,v4,v5); | |
printf("\nCurrent[A]\t\t%.4f\t%.4f\t%.4f\t%.4f\t%.4f",i1,i2,i3,i4,i5); | |
printf("\nPower[W]\t\t%.4f\t%.4f\t%.4f\t%.4f\t%.4f\n",p1,p2,p3,p4,p5); | |
} | |
} while ( scanf("%c",&c) == 1 ); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
james@james-Lenovo-G500:~/Desktop/School/Winter/COSC_2P91/Assign_2$ ./circuit < bridge.txt | |
V: 1.000000 | |
R1: 120.000000 | |
R2: 1200.000000 | |
R3: 200.000000 | |
R4: 360.000000 | |
R5: 100.000000 | |
Wheatstone Wheatstone Bridge Data Set | |
Voltage Applied: 1.0000 V | |
Total current flowing through bridge: -0.0061 A | |
Total power dissipated in the bridge: 0.0037 W | |
Percentage of power dissipated by the meter: 18.66 % | |
R1 R2 R3 R4 R5 | |
Resistance[Ohm] 120.00 1200.00 200.00 360.00 100.00 | |
Voltage[V] 0.2500 0.8571 1.3571 -1.4357 -0.6071 | |
Current[A] 0.0021 0.0007 0.0068 -0.0040 -0.0061 | |
Power[W] 0.0005 0.0006 0.0092 0.0057 0.0037 | |
V: 2.000000 | |
R1: 900.000000 | |
R2: 400.000000 | |
R3: 1000.000000 | |
R4: 360.000000 | |
R5: 500.000000 | |
Wheatstone Wheatstone Bridge Data Set | |
Voltage Applied: 2.0000 V | |
Total current flowing through bridge: 0.0017 A | |
Total power dissipated in the bridge: 0.0015 W | |
Percentage of power dissipated by the meter: 17.17 % | |
R1 R2 R3 R4 R5 | |
Resistance[Ohm] 900.00 400.00 1000.00 360.00 500.00 | |
Voltage[V] 1.4286 0.5714 -0.2857 1.1886 0.8571 | |
Current[A] 0.0016 0.0014 -0.0003 0.0033 0.0017 | |
Power[W] 0.0023 0.0008 0.0001 0.0039 0.0015 | |
V: 3.000000 | |
R1: 12.000000 | |
R2: 2.000000 | |
R3: 3.000000 | |
R4: 5.000000 | |
R5: 8.000000 | |
Wheatstone Wheatstone Bridge Data Set | |
Voltage Applied: 3.0000 V | |
Total current flowing through bridge: 0.1147 A | |
Total power dissipated in the bridge: 0.1053 W | |
Percentage of power dissipated by the meter: 4.52 % | |
R1 R2 R3 R4 R5 | |
Resistance[Ohm] 12.00 2.00 3.00 5.00 8.00 | |
Voltage[V] 2.1176 1.2000 1.4559 1.4559 0.9176 | |
Current[A] 0.1765 0.6000 0.4853 0.2912 0.1147 | |
Power[W] 0.3737 0.7200 0.7065 0.4239 0.1053 | |
V: 4.000000 | |
R1: 300.000000 | |
R2: 2000.000000 | |
R3: 600.000000 | |
R4: 1000.000000 | |
R5: 500.000000 | |
Wheatstone Wheatstone Bridge Data Set | |
Voltage Applied: 4.0000 V | |
Total current flowing through bridge: -0.0043 A | |
Total power dissipated in the bridge: 0.0093 W | |
Percentage of power dissipated by the meter: 23.87 % | |
R1 R2 R3 R4 R5 | |
Resistance[Ohm] 300.00 2000.00 600.00 1000.00 500.00 | |
Voltage[V] 0.9231 3.0769 3.5077 -1.2308 -2.1538 | |
Current[A] 0.0031 0.0015 0.0058 -0.0012 -0.0043 | |
Power[W] 0.0028 0.0047 0.0205 0.0015 0.0093 | |
V: 5.000000 | |
R1: 18.000000 | |
R2: 7.000000 | |
R3: 14.000000 | |
R4: 9.000000 | |
R5: 10.000000 | |
Wheatstone Wheatstone Bridge Data Set | |
Voltage Applied: 5.0000 V | |
Total current flowing through bridge: 0.1667 A | |
Total power dissipated in the bridge: 0.2778 W | |
Percentage of power dissipated by the meter: 11.21 % | |
R1 R2 R3 R4 R5 | |
Resistance[Ohm] 18.00 7.00 14.00 9.00 10.00 | |
Voltage[V] 3.3333 1.6667 1.0000 3.1667 1.6667 | |
Current[A] 0.1852 0.2381 0.0714 0.3519 0.1667 | |
Power[W] 0.6173 0.3968 0.0714 1.1142 0.2778 | |
james@james-Lenovo-G500:~/Desktop/School/Winter/COSC_2P91/Assign_2$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment