Task 5 is done
This commit is contained in:
parent
dc3c871ae1
commit
b75291790e
2 changed files with 6 additions and 11 deletions
|
@ -20,7 +20,7 @@ int main(int argc, char *argv[])
|
|||
sscanf(argv[1], "%lf", &x_0) == 1 &&
|
||||
(sscanf(argv[2], "%lf", &eps) == 1 && (eps >= 0)) &&
|
||||
((sscanf(argv[3], "%d", &m) == 1) && (m > 0)) &&
|
||||
((sscanf(argv[4], "%d", &k) == 1) && ((0 <= k) && (k <= len_f))))
|
||||
((sscanf(argv[4], "%d", &k) == 1) && ((0 <= k) && (k < len_f))))
|
||||
) {
|
||||
fprintf(stderr, "Usage: %s x_0 eps M k\n", argv[0]);
|
||||
return -1;
|
||||
|
|
|
@ -9,21 +9,16 @@ int t7_solve (
|
|||
int m, double *x
|
||||
) {
|
||||
int it = 0;
|
||||
double y = f(x_0);
|
||||
|
||||
if (fabs(y - x_0) - eps < DBL_EPSILON)
|
||||
{
|
||||
*x = x_0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (it = 1; it <= m; ++it)
|
||||
{
|
||||
x_0 = y;
|
||||
y = f(x_0);
|
||||
const double y = f(x_0);
|
||||
const double max = fabs((y < x_0) ? x_0 : y);
|
||||
|
||||
if (fabs(y - x_0) - eps < DBL_EPSILON)
|
||||
if (fabs(y - x_0) < eps * max) {
|
||||
x_0 = y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (it > m)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue