#include <cmath>
const double PI = 3.141592653589793;
struct SystemRLC {
Parameter R;
Parameter L;
Parameter C;
Expression Current1;
Integrator Current2;
Integrator Uout;
SystemRLC(double U0, double R0, double L0, double C0):
R(R0), L(L0), C(C0),
Current1( -Uout/R ),
Current2( Uout/L, 0 ),
Uout( (Current1-Current2)/C, U0 ) {}
double ResFrequency() {
return 1/(2*PI * std::sqrt(L.Value() * C.Value()));
}
double ResPeriod() {
return 1/ResFrequency();
}
};
SystemRLC rlc(1 , 1e3 , 1e-6 , 1e-9 );
void Sample1() {
Print(
"%g %g %g\n",
T.
Value(), rlc.Uout.Value(), rlc.Current2.Value());
}
Sampler s(Sample1, 0.01*rlc.ResPeriod());
Print(
"# RLC circuit simulation output\n");
Print(
"# Fres = %g\n", rlc.ResFrequency());
Init(0, 30 * rlc.ResPeriod());
SetStep(1e-9, 0.1 * rlc.ResPeriod());
}