My old project for strange attractors
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

98 lines
2.1 KiB

15 years ago
//
// $filename
// $projectname
//
// Created by Joshua moerman on $TODAY.
// Copyright 2010 Joshua Moerman. All rights reserved.
//
#include "Logistic.hpp"
15 years ago
Logistic::Logistic():
myParameters(NULL), vectorNew(NULL), vectorOld(NULL) {
15 years ago
dimension = 3;
init();
}
Logistic::Logistic(const unsigned int dimension):
15 years ago
myParameters(NULL), vectorNew(NULL), vectorOld(NULL), dimension(dimension) {
15 years ago
init();
}
void Logistic::init() {
const unsigned int numberOfParameters = dimension;
if ( myParameters != NULL ) {
delete myParameters;
}
myParameters = new double[numberOfParameters];
if ( vectorNew != NULL ) {
delete vectorNew;
}
vectorNew = new double[dimension];
if ( vectorOld != NULL ) {
delete vectorOld;
}
vectorOld = new double[dimension];
assert(myParameters != NULL);
assert(vectorNew != NULL);
assert(vectorOld != NULL);
for ( unsigned int i = 0; i < numberOfParameters; i++ ) {
myParameters[i] = 0.0;
}
for ( unsigned int i = 0; i < dimension; i++ ) {
vectorNew[i] = vectorOld[i] = 0.5;
}
}
void Logistic::iterate() {
swap(vectorNew, vectorOld);
15 years ago
for ( unsigned int i = 0; i < dimension; i++ ) {
vectorNew[i] = myParameters[i]*vectorOld[i]*(1.0 - vectorOld[i]);
15 years ago
}
}
// setters, getters, all i/o to other classes/objects
void * Logistic::getProperty(const string identifier) {
if ( identifier == "dimension" ) {
unsigned int * _return = new unsigned int;
*_return = dimension;
return _return;
}
return NULL;
}
void Logistic::setProperty(const string identifier, const void * _value) {
if ( identifier == "dimension" ) {
unsigned int * value = (unsigned int*) _value;
dimension = *value;
init();
}
}
double * & Logistic::parameters() {
return myParameters;
}
double & Logistic::parameter(const unsigned int index) {
return myParameters[index];
}
unsigned int Logistic::getNumberOfParameters() {
return dimension;
}
15 years ago
double * & Logistic::vector() {
return vectorNew;
}
double * & Logistic::previousVector() {
return vectorOld;
}