Skip to content
Snippets Groups Projects
Unverified Commit a939958c authored by orestis.malaspin's avatar orestis.malaspin
Browse files

added plplot to test. not sure if it's cool enough though

parent 6d8f1281
No related branches found
No related tags found
No related merge requests found
Pipeline #12203 passed
CC=clang
OPTS=-g -O3 -Wall -Wextra -fsanitize=address -fsanitize=leak -std=c11
LINK=-lm -fsanitize=address -fsanitize=leak
INCLUDE=-I/usr/include/plplot/
LINK=-lm -fsanitize=address -fsanitize=leak -lplplot
# OPTS=-g -O3 -Wall -Wextra -std=c11
# LINK=-lm
......@@ -9,7 +10,7 @@ main: main.o rc.o ode_o1.o
$(CC) $(OPTS) -o $@ $^ $(LINK)
main.o: main.c
$(CC) $(OPTS) -c $^
$(CC) $(OPTS) $(INCLUDE) -c $^
ode_o1.o: ode_o1.c ode_o1.h
$(CC) $(OPTS) -c $^
......
#include "rc.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <plplot.h>
int main() {
#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;
int i = 0;
PLFLT x[NSIZE], y[NSIZE];
PLFLT xmin = 0., xmax = max_t, ymin = 0., ymax = rc.eps;
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);
x[i] = t;
y[i] = v;
v = rc_advance(v, dt, &rc);
i += 1;
}
v = v_ini = 1.0;
double omega = 0.0;
for (double t = 0.0; t < max_t; t += dt) {
rc.eps = sin(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);
v = rc_advance(v, dt, &rc);
}
// 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;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment