Commit 50bdf230 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Added assignment 6.

parent df971358
...@@ -2,7 +2,7 @@ CC=clang ...@@ -2,7 +2,7 @@ CC=clang
CFLAGS=-Wall -Wextra -pedantic -std=c99 -D_GNU_SOURCE -g CFLAGS=-Wall -Wextra -pedantic -std=c99 -D_GNU_SOURCE -g
LFLAGS=-lm LFLAGS=-lm
all: q1 q2 q3 q4 q5 q7 report.pdf all: q1 q2 q3 q4 q5 q6 q7 report.pdf
q%: q%.o q%: q%.o
$(CC) $(CFLAGS) $(LFLAGS) -o $@ $^ $(CC) $(CFLAGS) $(LFLAGS) -o $@ $^
...@@ -11,6 +11,7 @@ q2: bisection.o ...@@ -11,6 +11,7 @@ q2: bisection.o
q3: bisection.o regula_falsi.o newton_raphson.o q3: bisection.o regula_falsi.o newton_raphson.o
q4: newton_raphson.o q4: newton_raphson.o
q5: integral.o q5: integral.o
q6: integral.o
%.pdf: %.tex %.pdf: %.tex
pdflatex $^ pdflatex $^
......
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "func_ptr.h"
#include "integral.h"
#define STRIDE 10000
double accurate_integral(func_ptr f, method_ptr method, double a,
double b, double accuracy, unsigned int stride) {
unsigned int steps = 0;
double result, old;
do {
steps += stride;
old = result;
result = integral(f, method, a, b, steps);
} while( fabs(old - result) >= accuracy );
return result;
}
double f1(double x) {
return x * pow(M_E, -x);
}
#define PRINT_INTEGRAL(func, method, a, b, acc) (printf(#func " from " #a " to " \
#b " using %-19s %.11e", accurate_itegral(&func, &method, a, b, acc, STRIDE), \
#method " method:"))
int main(void) {
PRINT_INTEGRAL(f1, gauss, 0, 2, 1e-5);
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