V sistem takoj po prvem procesu vpeljemo stopni"casto motnjo po"zenemo simulacijo.
/*\ * Simulacije sistemov - vaja 3c * Zaprtozan"cna regulacija nivoja posode z motnjo * $Id: sim3c.c,v 1.1 1994/05/05 09:29:24 $ \*/ #include <stdio.h> #include <math.h> #define KPg 3.8876 /* Parametri */ #define KIg 0.1718 /* glavnega */ #define KDg 30.599 /* regulatorja */ #define TFIN 200.0 /* Kon"cni "cas */ #define DT 0.005 /* delta time */ #define NTHELEM 100 /* izpis n-tega "casa */ static float t, tc, e, p, i, d, x, fiv, z; static float h3ref, fi1d, fi1i, fi1, h3dd, h3d, h3, itae; static short n; static void initialize (void) { tc = 0.1 * KDg / KPg; t = i = x = 0.0; fi1d = fi1i = fi1 = 0.0; h3dd = h3d = h3 = 0.0; e = p = d = itae = 0.0; n = 100; } static void output (void) { printf ("%5.1f %5.3f %5.3f %4.2f\n", t, fi1i, h3, itae); } static void derive (void) { fi1d = fiv / 10.0 - fi1 / 5.0;/* prvi proces */ /* drugi proces */ h3dd = (2.0 * fi1 - 20.0 * h3d - 1.0 * h3) / 100.0; d = (e - x) / tc; /* Diferencialni del glavnega regulatorja */ } static void integrate (void) { h3ref = 0.0; /* referenca je 0 */ z = 1.0; /* motnja v prvem procesu */ do { derive (); if (n++ % NTHELEM == 0) output (); t += DT; /* Glavni regulator */ e = h3ref - h3; p = e; /* proprocionalni del */ i += e * DT; /* integralni del */ x += d * DT; /* diferencialni del */ fiv = KPg * p + KIg * i + KDg * d; /* Prvi proces */ fi1i += fi1d * DT; fi1 = fi1i + z; /* Drugi proces */ h3 += h3d * DT; h3d += h3dd * DT; /* ITAE integralska cenilka */ itae += t * fabs (e) * DT; /* scanf("%*[^\n]"); */ } while (t < TFIN); } int main (int argc, char *argv[]) { initialize (); integrate (); fprintf(stderr, "ITAE = %8.2f\n", itae); return 0; }