Task 6 and 7 are done
This commit is contained in:
parent
67a26248b1
commit
7393b9b49a
13 changed files with 539 additions and 1 deletions
35
2025.05.09/06Ex/solve.c
Normal file
35
2025.05.09/06Ex/solve.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include "solve.h"
|
||||
#include "comp.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
double t6_solve (
|
||||
double (*f) (double),
|
||||
double a, double b,
|
||||
int n
|
||||
) {
|
||||
const double h = (b - a) / n;
|
||||
double x = a;
|
||||
double sum;
|
||||
|
||||
if (is_null(a) || is_null(b))
|
||||
return DBL_MAX;
|
||||
|
||||
f_global = f;
|
||||
sum = (wf(a) + wf(b)) * 0.5;
|
||||
|
||||
if (h < NUM_FPE)
|
||||
return DBL_MAX;
|
||||
|
||||
for (int i = 1; i < (n - 1); ++i)
|
||||
{
|
||||
x += h;
|
||||
if (is_null(x))
|
||||
return DBL_MAX;
|
||||
sum += wf(x);
|
||||
}
|
||||
|
||||
return h * sum;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue