Commit ad1a2ada authored by Taddeüs Kroes's avatar Taddeüs Kroes

Modsim ass3: Started work on question 1 (harmonic oscillator).

parent a23b3172
......@@ -2,10 +2,13 @@ CC=gcc
CFLAGS=-Wall -Wextra -pedantic -std=c99 -D_GNU_SOURCE -g -O0
LFLAGS=-lm
all: test
all: test harm_osc
test: test.o methods.o
$(CC) $(CFLAGS) $(LFLAGS) -o $@ $^
harm_osc: harm_osc.o methods.o
$(CC) $(CFLAGS) $(LFLAGS) -o $@ $^
clean:
rm *.o test
rm *.o test harm_osc
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "methods.h"
#define DT .001
#define INTEGRATE(method, t0, t1) { \
if( method(t0, t1, DT, y0, y1, 2, &f_osc, &k) ) \
puts("FAIL"); \
else \
printf("y1 using %-12s s:%.10f\n", #method ":", *y1); \
}
#define COMPARE(t0, t1) { \
INTEGRATE(Euler, t0, t1); \
INTEGRATE(RungeKutta2, t0, t1); \
INTEGRATE(RungeKutta4, t0, t1); \
}
/*
void log(double t, double *y) {
printf("%f,%f,%f\n", t, y[0], y[1]);
}
*/
int f_osc(double t, double *y, double *dy, void *params) {
dy[0] = y[1];
dy[1] = -*(double *)(params) * y[0];
return 0;
}
int main(void) {
double k = .5, y0[2] = {.0, 5.0}, y1[2] = {.0, .0};
COMPARE(.0, 10.0)
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment