Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C program that will calculate the voltage across the capacitor in the fo

ID: 3884808 • Letter: W

Question

Write a C program that will calculate the voltage across the capacitor in the following circuit as time increases from 0 to 1 second in increments of 1/15 second, assuming that the switch is closed at time 0.

The voltage across the capacitor at time t is given by the following equation:

Constants: In this circuit, V = 10 volts, R = 3,000 ohms, and C = 50 x 10-6 farads. The circuit has a

time constant , which depends on the resistance, R, and the capacitance, C, as = R x C = 0.15 second.

1) Name your program voltage.c

2) Use a for loop.

3) Use the math library function exp(x) to compute ex. You will need to include the system header file math.h.

4) On Unix you will need –lm in your command line to tell the Linker to search the math library.

5) Use macro definition for all the constants.

6) Format the output so the output looks like the following. The time and voltage should display two digits after the decimal point.

Switch +10 V battery 3 K 12 Resistor 50 F capacitor

Explanation / Answer

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define V 10
#define R 3000;
#define C 50*10^-6

int main()
{ int i;
float t[16]= {0.00,0.07,0.13,0.20,0.27,0.33,0.40,0.47,0.53,0.60,0.67,0.73,0.80,0.87,0.93,1.00};
float v[16];
float T= 0.15; //T = R*C

for(i=0;i<16;i++)
{
v[i] = V * (1 - exp(-t[i]/T)); //v(t)= V * (1 - e^(-t/T))

}
printf(" time(sec) voltage "); // to display the output
for(i=0;i<16;i++)
printf(" %.2f %.2f ",t[i],v[i]);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote