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 |
#include <iostream> #include <vector> #include <iomanip> // Constants const int ITERATIONS = 100; const double INITIAL_VALUE = 0.5; const double R_MIN = 2.5; const double R_MAX = 4.0; const double R_STEP = 0.1; // LogisticMap class class LogisticMap { public: LogisticMap(double r, double initialValue) : r(r), x(initialValue) {} void iterate() { x = r * x * (1 - x); } double getValue() const { return x; } private: double r; // Control parameter double x; // Current value }; // Main function int main() { std::vector<double> rValues; // Iterate over the range of r values for (double r = R_MIN; r <= R_MAX; r += R_STEP) { LogisticMap logisticMap(r, INITIAL_VALUE); std::cout << "r = " << std::fixed << std::setprecision(1) << r << ": "; // Generate and print the logistic map values for (int i = 0; i < ITERATIONS; ++i) { logisticMap.iterate(); std::cout << logisticMap.getValue() << ' '; } std::cout << std::endl; } return 0; } |
Explanation:
- LogisticMap Class:
r
: The control parameter for the logistic map, which influences the chaotic behavior.x
: The current value of the system, initialized with theinitialValue
.LogisticMap(double r, double initialValue)
: Constructor that sets the value ofr
and initializesx
.iterate()
: Updates the value ofx
using the logistic map formula xn+1=r⋅xn⋅(1−xn)x_{n+1} = r \cdot x_n \cdot (1 – x_n).getValue() const
: Returns the current value ofx
.
- Main Function:
- Creates a range of
r
values fromR_MIN
toR_MAX
with a step size ofR_STEP
. - For each
r
value, it initializes aLogisticMap
object with the currentr
andINITIAL_VALUE
. - Iterates the logistic map and prints the resulting values to show how the system evolves for different values of
r
.
- Creates a range of