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

Added ass4 and another header file.

parent 65f2a370
......@@ -2,7 +2,7 @@ CC=clang
CFLAGS=-Wall -Wextra -pedantic -std=c99 -D_GNU_SOURCE
LFLAGS=-lm
all: q1 q2 q3
all: q1 q2 q3 q4
q%: q%.o
$(CC) $(CFLAGS) $(LFLAGS) -o $@ $^
......
#define EPSILON 1e-11
#include "func_ptr.h"
typedef double (*func_ptr)(double x);
#define EPSILON 1e-11
double bisec(func_ptr f, double left, double right, int *steps) {
int i;
......
typedef double (*func_ptr)(double x);
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "func_ptr.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;
}
......
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "func_ptr.h"
double newton(func_ptr f, func_ptr df, double x_start) {
return 0;
}
double f1(double x) {
return x * x - x + 2;
}
double df1(double x) {
return x / 2 - 1;
}
double f2(double x) {
return x * x * x - 3 * x - 2;
}
double df2(double x) {
return (x * x) / 3 - 3;
}
double f3(double x) {
return (x * x + 1) * (x - 4);
}
double df3(double x) {
return (x * x + 1) + (x / 2) * (x - 4);
}
#define TEST(i) (printf("f1: %.11f\n", &f(i), &df(i), 1))
int main(void) {
printf("f1: %.11f\n", newton(&f1, &df1, 1));
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