Forked from
orestis.malaspin / isc_physics
308 commits behind the upstream repository.
-
orestis.malaspin authoredorestis.malaspin authored
main.c 1.59 KiB
#include "rc.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <plplot.h>
#define NSIZE 5000
int main(int argc, char *argv[]) {
rc_state rc = rc_state_create(1.0, 1.0, 1.0);
// ============================================================ //
// RC with constant != 0 tension at input and 0 initial tension //
// ============================================================ //
double v, v_ini;
v = v_ini = 0.0;
double dt = 0.001;
double max_t = 5.0;
PLFLT x[NSIZE], y[NSIZE];
PLFLT xmin = 0., xmax = max_t, ymin = rc.eps-1, ymax = rc.eps+1;
for (double t = 0.0; t < max_t; t += dt) {
double ve = exact_solution(t, v_ini, &rc);
printf("t = %f, v = %f, v_e = %f, diff = %f\n", t, v, ve, ve - v);
v = rc_advance(v, dt, &rc);
}
v = v_ini = 1.0;
double omega = 10.0;
int i = 0;
for (double t = 0.0; t < max_t; t += dt) {
rc.eps = v_ini * (1.0 + cos(omega * t));
double ve = exact_solution(t, v_ini, &rc);
printf("t = %f, v = %f, v_e = %f, diff = %f\n", t, v, ve, ve - v);
x[i] = t;
y[i] = v;
v = rc_advance(v, dt, &rc);
i += 1;
}
// Parse and process command line arguments
plparseopts( &argc, argv, PL_PARSE_FULL );
// Initialize plplot
plinit();
// Create a labelled box to hold the plot.
plenv( xmin, xmax, ymin, ymax, 0, 0 );
pllab( "t", "v", "Simple PLplot demo of of the charge of a capacitor" );
// Plot the data that was prepared above.
plline( NSIZE, x, y );
// Close PLplot library
plend();
return EXIT_SUCCESS;
}