Given the circuit diagram below, write a C program that calculates the following:

  1. The potential difference across x
  2. The charge on z
  3. The energy on y

Exercise 1.9 Circuit

Source Code

Brief explanation is provided after the source code.

#include <stdio.h>
#include <math.h>

int main(void){

     float Cx = 3e-6, Cy = 2e-6, Cz = 4e-6, Cp, Ct, q, Vx, Vz, Wy;
     int v = 6;
     Cp = Cy + Cz; // capacitance in parallel
     Ct = (Cx * Cp) / (Cx + Cp); // total capacitance
     q = Ct * v; // compute charge
     Vx = q / Cx; // p.d across x
     Vz = v - Vx; // p.d across z
     Wy = 0.5 * Cy * pow(Vz, 2); // energy on y

     printf("Potential difference across x: %.1fV\n", Vx);
     printf("Charge on z: %0.1eC\n", Cz * Vz);
     printf("Energy on y: %0.1eJ\n", Wy);

     return 0;

When you compile and execute the above program it produces the following result on Linux:

Potential difference across x: 4.0V
Charge on z: 8.0e-06C
Energy on y: 4.0e-06J

Brief Explanation

  • The program starts by calculating the capacitance of the capacitors in parallel and the total capacitance of the circuit.
  • The charge q is computed by multiplying the total capacitance with the voltage in the circuit.
  • The potential difference across x is computed by dividing the charge q by the capacitance at x.
  • The potential difference at z is computed by subtracting the potential difference at x from the voltage of the circuit.
  • The charge on z is computed by multiplying the capacitance at z with the potential difference at z.
  • The energy on y is computed using the formula, 1/2CyVy2 and Vy = Vz.
  • Using printf function, the results are printed to the stdout.

Add comment

Security code