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

updated rc code

parent 6336b792
No related branches found
No related tags found
No related merge requests found
#include "rc.h"
#include <stdio.h>
#include <stdlib.h>
int main() {
rc_state rc = rc_state_create(1.0, 1.0, 1.0);
double v, v_ini;
v = v_ini = 0.0;
double dt = 0.001;
double max_t = 5.0;
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);
}
return EXIT_SUCCESS;
}
\ No newline at end of file
#include <math.h>
#include "rc.h"
#include "ode_o1.h"
rc_state rc_state_create(double r, double c, double eps) {
rc_state rc = {.r = r, .c = c, .eps = eps};
return rc;
}
double rc_g(double v, void *rc) {
rc_state *rcs = (rc_state*)rc;
return 1.0 / (rcs->r * rcs->c) * (rcs->eps - v);
}
double rc_advance(double v0, double dt, rc_state *state) {
return advance(rc_g, v0, dt, state);
}
double exact_solution(double t, double v_ini, rc_state *state) {
return v_ini * exp(-t/(state->c * state->r)) - state->eps * exp(-t/(state->c * state->r)) + state->eps;
}
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