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.
66 lines
1.5 KiB
66 lines
1.5 KiB
//
|
|
// $filename
|
|
// $projectname
|
|
//
|
|
// Created by Joshua moerman on $TODAY.
|
|
// Copyright 2010 Joshua Moerman. All rights reserved.
|
|
//
|
|
|
|
#include "Polynomial.hpp"
|
|
#include <algorithm>
|
|
|
|
|
|
unsigned int calculateNumberOfParameters(const unsigned int dimension, const unsigned int orde) {
|
|
double n_coef = orde + 1;
|
|
for (unsigned int i = 2; i <= dimension; i++) {
|
|
n_coef = n_coef*(orde + i)/(i - 1);
|
|
}
|
|
|
|
const unsigned int output = (unsigned int) n_coef;
|
|
return output;
|
|
}
|
|
|
|
|
|
#pragma mark -
|
|
#pragma mark ctors
|
|
|
|
Polynomial::Polynomial():
|
|
AttractorKernel(3, calculateNumberOfParameters(3, 2)), orde(2){}
|
|
|
|
Polynomial::Polynomial(const unsigned int dimension, const unsigned int orde):
|
|
AttractorKernel(dimension, calculateNumberOfParameters(dimension, orde)), orde(orde){}
|
|
|
|
|
|
#pragma mark -
|
|
#pragma mark attractor
|
|
|
|
void Polynomial::operator()() {
|
|
std::swap(vectorNew, vectorOld);
|
|
|
|
unsigned int m = 0;
|
|
for ( unsigned int i = 0; i < dimension; i++ ) {
|
|
|
|
vectorNew[i] = parameters[m];
|
|
m++;
|
|
recur(i, 0, 1, m);
|
|
}
|
|
}
|
|
|
|
void Polynomial::recur(unsigned int curr_dimension, unsigned int prev_i, unsigned int n, unsigned int& m, double prev_product) {
|
|
double product;
|
|
for (unsigned int i = prev_i; i < dimension; i++) {
|
|
|
|
product = prev_product * vectorOld[i];
|
|
vectorNew[curr_dimension] += parameters[m] * product;
|
|
m++;
|
|
if (n < orde) {
|
|
recur(curr_dimension, i, n+1, m, product);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|