-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlogistic_mpfi.c
66 lines (56 loc) · 1.78 KB
/
logistic_mpfi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//******************************************************************************
// logistic_mpfi.c : logistic map with MPFI
// Copyright (C) 2019 Tomonori Kouya
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by the
// Free Software Foundation, either version 3 of the License or any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
// for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
//******************************************************************************
#include <stdio.h>
#include "mpfr.h"
#include "mpfi.h"
#define MAX_NUM 128
int main()
{
int i;
unsigned long prec;
mpfi_t x[MAX_NUM];
mpfr_t relerr;
printf("prec(bits) = "); while(scanf("%ld", &prec) < 1);
mpfr_set_default_prec(prec);
// initialize variables
mpfr_init(relerr);
for(i = 0; i < MAX_NUM; i++)
mpfi_init(x[i]);
// set a initial interval
mpfi_set_str(x[0], "0.7501", 10);
for(i = 0; i <= 100; i++)
{
if((i % 10) == 0)
{
printf("%5d, ", i);
mpfi_out_str(stdout, 10, 17, x[i]);
mpfi_diam(relerr, x[i]);
mpfr_printf("%10.3RNe\n", relerr);
}
//x[i + 1] = 4 * x[i] * (1 - x[i]);
mpfi_ui_sub(x[i + 1], 1UL, x[i]);
mpfi_mul(x[i + 1], x[i + 1], x[i]);
mpfi_mul_ui(x[i + 1], x[i + 1], 4UL);
}
// delete variables
mpfr_clear(relerr);
for(i = 0; i < MAX_NUM; i++)
mpfi_clear(x[i]);
return 0;
}