Introduction to programming – C Exercise – Circuit


Consider the following circuit;

circuit Introduction to programming - C Exercise - Circuit beginner c / c++ programming languages

circuit

The step response of this circuit may be expressed as follows;

circuit-formula Introduction to programming - C Exercise - Circuit beginner c / c++ programming languages

circuit formula

where t=time (in seconds)

Write a function to calculate and return the value of Vout when given; the input voltage, the resistor values, capacitor value and time.

1
2
3
4
5
#include<math.h>
double circuit(double vin, double r1, double r2, double c, double t) {
    double r1_r2 = r1 + r2;
    return vin * r2 / (r1_r2) * (1 - exp(-t * (r1_r2 / (c * r1 * r2))));
}
#include<math.h>
double circuit(double vin, double r1, double r2, double c, double t) {
    double r1_r2 = r1 + r2;
    return vin * r2 / (r1_r2) * (1 - exp(-t * (r1_r2 / (c * r1 * r2))));
}

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
197 words
Last Post: How to Ban and Make a User Unlike Your Facebook Page?
Next Post: Algorithm to Compute the Pascal Triangle's values

The Permanent URL is: Introduction to programming – C Exercise – Circuit

Leave a Reply