Inactive Tutor answered 01/16/24
Tutor
New to Wyzant
To implement a first order transfer in C, you can use different methods. Let's use the Euler method for this specific example.
In C, you can use static variables, which retain their value between function invocations. This means the y_prev will always remember the previous y value.
double output(double input, double t) {
static double y_prev = 0.0
double K = 3.0;
double tau = 1.0 / 3.0;
// Discrete-time approximation using Euler method
double y = y_prev + (K * input * t) / (tau + t);
y_prev = y;
return y;
}