Joshua
15 years ago
5 changed files with 139 additions and 90 deletions
@ -0,0 +1,92 @@ |
|||
//
|
|||
// $filename
|
|||
// $projectname
|
|||
//
|
|||
// Created by Joshua moerman on $TODAY.
|
|||
// Copyright 2010 Joshua Moerman. All rights reserved.
|
|||
//
|
|||
|
|||
#include "Logistic.hpp" |
|||
|
|||
Logistic::Logistic() { |
|||
dimension = 3; |
|||
|
|||
init(); |
|||
} |
|||
|
|||
Logistic::Logistic(const unsigned int dimension): |
|||
dimension(dimension) { |
|||
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); |
|||
|
|||
for ( unsigned int i = 0; i < dim; i++ ) { |
|||
new_point[i] = param[i]*point[i]*(1.0 - point[i]); |
|||
} |
|||
} |
|||
|
|||
|
|||
// 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]; |
|||
} |
|||
|
|||
double * & Logistic::vector() { |
|||
return vectorNew; |
|||
} |
|||
|
|||
double * & Logistic::previousVector() { |
|||
return vectorOld; |
|||
} |
@ -0,0 +1,42 @@ |
|||
#ifndef LOGISTIC_HPP |
|||
#define LOGISTIC_HPP |
|||
|
|||
#include "../AttractorKernel.hpp" |
|||
|
|||
class Logistic : AttractorKernel { |
|||
double * myParameters; |
|||
|
|||
double * vectorNew; |
|||
double * vectorOld; |
|||
|
|||
unsigned int dimension; |
|||
|
|||
void init(); |
|||
|
|||
public: |
|||
|
|||
Logistic(); |
|||
Logistic(const unsigned int dimension); |
|||
|
|||
// parameters are stored in a array of doubles
|
|||
// if you want to use other types, use the properties
|
|||
virtual double& parameter(const unsigned int index); |
|||
virtual double*& parameters(); |
|||
|
|||
// get properties of the attractor
|
|||
// such as the dimension
|
|||
// you should delete the void pointer if you used it
|
|||
virtual void * getProperty(const string identifier); |
|||
virtual void setProperty(const string identifier, const void * value); |
|||
|
|||
// iterate his formula
|
|||
// vector pointers will be swapped! so new remains new and old remains old
|
|||
virtual void iterate(); |
|||
|
|||
// getter functions for teh resulta
|
|||
virtual double * & vector(); |
|||
virtual double * & previousVector(); |
|||
}; |
|||
|
|||
#endif // LOGISTIC_HPP
|
|||
|
Reference in new issue