Commit 18802f3e authored by Taddeüs Kroes's avatar Taddeüs Kroes

ModSim ass3: Started working on test program.

parent 7bd16a29
CC=gcc
CFLAGS=-Wall -Wextra -pedantic -std=c99 -D_GNU_SOURCE -g -O0
LFLAGS=-lm
all: test
test: test.o methods.o
$(CC) $(CFLAGS) $(LFLAGS) -o $@ $^
%.o: %.c
$(CC) $(CFLAGS) $(LFLAGS) -o $@ $^
clean:
rm *.o test
#include <stdlib.h>
#include <stdio.h>
int main(void) {
return 0;
}
#ifndef FUNC_PTR_H
#define FUNC_PTR_H
typedef double (*func_ptr)(double t);
typedef double (*diff_ptr)(double t, func_ptr y);
#endif
#include <stdlib.h>
#include <stdio.h>
#include "methods.h"
/*
t0 – the start value t0 of t (input)
t1 – the final value of t (input)
dt – the increment in t (input)
y0[N] – the values of the functions y_n(t) at t0 (input)
y1[N] – the values of the functions y_n(t) at t1 (output)
N – the dimension of y (input)
int f(double t, double * y, double * dy, void * params) – computes
the vector of derivatives dy[N] of y[N], given t, y[N] and params
void * params – a pointer to a struct containing any parameters needed
by f (input)
All three functions return an estimate of y(t1) in y1.
All functions return 0 upon success, or -1 when a computational error
occurs (overflow, NaN or such)
*/
int Euler(double t0, double t1, double dt, double *y0, double *y1, int N,
f_ptr f, void *params) {
int i, steps = (int)((t1 - t0) / dt + .5);
for( i = 0; i < N; i++ ) {
}
return 0;
}
int RungeKutta2(double t0, double t1, double dt, double *y0, double *y1, int N,
f_ptr f, void *params) {
return 0;
}
int RungeKutta4(double t0, double t1, double dt, double *y0, double *y1, int N,
f_ptr f, void *params)
return 0;
}
typedef int (*f_ptr)(double t, double *y, double *dy, void *params);
int Euler(double t0, double t1, double dt, double *y0, double *y1, int N,
f_ptr f, void *params);
int RungeKutta2(double t0, double t1, double dt, double *y0, double *y1, int N,
f_ptr f, void *params);
int RungeKutta4(double t0, double t1, double dt, double *y0, double *y1, int N,
f_ptr f, void *params);
#include <stdlib.h>
#include <stdio.h>
#include "methods.h"
int f_test_1(double t, double *y, double *dy, void *params) {
*dy = 1.0;
return 1;
}
int f_test_2(double t, double *y, double *dy, void *params) {
double result = *y;
if( isnan(result) ) {
return -1;
} else {
*dy = result;
return 0;
}
}
int f_test_3(double t, double *y, double *dy, void *params) {
double result = *y * *y;
if( isnan(result) ) {
return -1;
} else {
*dy = result;
return 0;
}
}
int main(void) {
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