class-projects

Computer Science Coursework

View the Project on GitHub

Table of Contents

Logistic Differential Equation

Routine Name: logistic

Author: Philip Nelson

Language: C++

Description

logistic returns the solution to the logistic differential equation given alpha, beta, time and an initial P. A make file is included with a driver program.

\[ \frac{dP}{dt} = \alpha P + \beta P^2 \]

$ make
$ ./logistic.out

This will compile and run the driver program.

Input

logistic(A a, B b, T t, N p0) requires:

Output

Logistic returns an N, which is the type of the initial parameter, with the solution to the logistic differential equation.

Code

template <typename A, typename B, typename T, typename N>
inline N logistic(A a, B b, T t, N p0)
{
  return a / (((a-p0*b)/p0) * exp(-a * t) + b);
}

Example

int main()
{
  double a = 1.0;
  double b = 2.0;
  double t = 50;
  double p0 = 10.0;

  std::cout << "alpha:\t" << a << "\nbeta:\t" << b << "\ntime:\t" << t << "\nP0:\t" << p0 << std::endl;

  std::cout << "------------\nresult:\t" << logistic(a, b, t, p0) << std::endl;
}

Result

alpha:	1
beta:	2
time:	50
P0:	10
-----------
result:	0.5

Last Modification date: 17 January 2018