Commit 316aecce authored by Sander Mathijs van Veen's avatar Sander Mathijs van Veen

Merged simmod/modsim directories.

parents fc8dde85 3459d63b
*.log *.log
*.aux *.aux
*.o
*.pdf
*.swp *.swp
*.swo *.swo
*.toc *.toc
*.o *.gz
ass*.tar.gz
compilerbouw/ compilerbouw/
robotica/ robotica/
...@@ -4,31 +4,29 @@ SPEED_TYPES=float double LD ...@@ -4,31 +4,29 @@ SPEED_TYPES=float double LD
SUM_TYPES=float double SUM_TYPES=float double
OPS=ADD DIV MULT SQRT OPS=ADD DIV MULT SQRT
all: fp speed sum kahan pr all: fp speed highlight report.pdf sum kahan pr
#all: fp speed highlight report.pdf sum kahan pr highlight: floating_point.tex extra_precision.tex \
# speed.tex sum.tex kahan_sum.tex Makefile.tex
#highlight: floating_point.tex extra_precision.tex \
# speed.tex sum.tex kahan_sum.tex Makefile.tex s%.tex: s%.c
# pygmentize -O style=colorful -o $@ $^
#s%.tex: s%.c
# pygmentize -O style=colorful -o $@ $^ kahan_sum.tex: kahan_sum.c
# pygmentize -O style=colorful -o $@ $^
#kahan_sum.tex: kahan_sum.c
# pygmentize -O style=colorful -o $@ $^ Makefile.tex: Makefile
# pygmentize -O style=colorful -o $@ $^
#Makefile.tex: Makefile
# pygmentize -O style=colorful -o $@ $^ extra_precision.tex: extra_precision.c
# pygmentize -O style=colorful -o $@ $^
#extra_precision.tex: extra_precision.c
# pygmentize -O style=colorful -o $@ $^ floating_point.tex: floating_point.c
# pygmentize -O style=colorful -o $@ $^
#floating_point.tex: floating_point.c
# pygmentize -O style=colorful -o $@ $^ %.pdf: %.tex
# pdflatex $^
#%.pdf: %.tex pdflatex $^
# pdflatex $^
# pdflatex $^
speed: speed.c speed: speed.c
for t in $(SPEED_TYPES); do \ for t in $(SPEED_TYPES); do \
......
q1
q2
q3
q4
q5
*.o
CC=clang
CFLAGS=-Wall -Wextra -pedantic -std=c99 -D_GNU_SOURCE
LFLAGS=-lm
all: q1 q2 q3
q1: q1.o
$(CC) $(CFLAGS) $(LFLAGS) -o $@ $^
q2: q2.o
$(CC) $(CFLAGS) $(LFLAGS) -o $@ $^
%.o: %.c
$(CC) $(CFLAGS) $(LFLAGS) -o $@ -c $^
clean:
for i in `seq 5`; do \
rm -vf q$$i; \
done;
rm -vf *.o
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define H 1e-3
#define TABLE_LINE(func, x) (printf("%-24s%.12f\t%.12f\n", #x, \
slope_right(func, x, H), slope_central(func, x, H)))
typedef double (*func_ptr)(double x);
double slope_right(func_ptr func, double x, double h) {
return (func(x + h) - func(x)) / h;
}
double slope_central(func_ptr func, double x, double h) {
return (func(x + h) - func(x - h)) / (2 * h);
}
int main(void) {
puts("x\t\t\tright\t\tcentral");
TABLE_LINE(&sin, M_PI / 3);
TABLE_LINE(&sin, 100 * M_PI + M_PI / 3);
TABLE_LINE(&sin, 1e12 * M_PI + M_PI / 3);
return 0;
}
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define EPSILON 1e-11
typedef double (*func_ptr)(double x);
double bisec(func_ptr f, double left, double right, int *steps) {
int i;
double mid;
for( i = 1; fabs(right - left) > 2 * EPSILON; i++ ) {
mid = (right + left) / 2;
if( f(left) * f(mid) < 0 )
right = mid;
else if( f(right) * f(mid) < 0 )
left = mid;
else
break;
}
*steps = i;
return mid;
}
double func(double x) {
return x * sin(x) - 1;
}
int main(void) {
int steps;
printf("zero point: %.20f\n", bisec(&func, 0, 2, &steps));
printf("Steps: %d\n", steps);
return 0;
}
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define EPSILON 1e-11
typedef double (*func_ptr)(double x);
double bisec(func_ptr f, double left, double right, int *steps) {
int i;
double mid;
for( i = 1; fabs(right - left) > 2 * EPSILON; i++ ) {
mid = (right + left) / 2;
if( f(left) * f(mid) < 0 )
right = mid;
else if( f(right) * f(mid) < 0 )
left = mid;
else
break;
}
*steps = i;
return mid;
}
double func(double x) {
return x * sin(x) - 1;
}
int main(void) {
int steps;
printf("zero point: %.20f\n", bisec(&func, 0, 2, &steps));
printf("Steps: %d\n", steps);
return 0;
}
*.log
*.toc
*.aux
report.pdf
report-dot2tex*
dot2tex.cache
all:
pdflatex report.tex
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