TITLE:: LotkaVolterra
summary:: 2-species Predator-Prey model
categories:: UGens>Generators>Chaotic
related:: Classes/ArneodoCoulletTresser

DESCRIPTION::
UGen implementing 4th order Runge-Kutta approximation of the Lotka and Volterras Predator-Prey model:

code::
x' = x * (a - b * y)
y' = y * (c * x - d)
::

Implemented by Till Bovermann inspired by Gary William Flake's Book "The Computational Beauty of Nature". Implementation following on Lance Putnam's chaos UGens and MCLDs ChaosUGens.

link::http://tai-studio.org::



CLASSMETHODS::

METHOD:: categories

METHOD:: ar
argument:: freq
update frequency, best set to Nyquist frequency. To modulate tonal qualities, use code::h::.
argument:: a
meta-parameter, useful between 0 and 5; must not be negative.
argument:: b
meta-parameter, useful between 0 and 5; must not be negative.
argument:: c
meta-parameter, useful between 0 and 5; must not be negative.
argument:: d
meta-parameter, useful between 0 and 5; must not be negative.
argument:: h
step size for the approximation
argument:: xi
initial value for x, resets the UGen when changed
argument:: yi
initial value for y, resets the UGen when changed
argument:: mul
multiply code::withthis::
argument:: add
add code::that::

METHOD:: equation
returns

code::
x' = x * (a - b * y)
y' = y * (c * x - d)
::

private:: init


EXAMPLES::

code::
// scope signals, set graphics to 'xy' to see relations between predator (out 0) and prey (out 1)
{LotkaVolterra.ar(SampleRate.ir*0.5, \a.kr(1.5, 0.1), \b.kr(1.5, 0.1), \c.kr(0.5, 0.1), \d.kr(1.5, 0.1), h: \h.kr(0.01), xi: 0.1 + \tr.tr(1))}.scope;
::

code::
(
Ndef(\lv).addSpec(\freq, [0.1, 24000, \exp]);
Ndef(\lv).addSpec(\h, [0.01, 1, \exp]);
Ndef(\lv).addSpec(\which, [0, 2, \lin]);
Ndef(\lv).addSpec(\a, [0.01, 5, \lin]);
Ndef(\lv).addSpec(\b, [0.01, 5, \lin]);
Ndef(\lv).addSpec(\c, [0.01, 5, \lin]);
Ndef(\lv).addSpec(\d, [0.01, 5, \lin]);

Ndef(\lv, {
	LeakDC.ar(
		LotkaVolterra.ar(SampleRate.ir*0.5, \a.kr(1.5, 0.1), \b.kr(1.5, 0.1), \c.kr(0.5, 0.1), \d.kr(1.5, 0.1), h: \h.kr(0.01), xi: 0.1 + \tr.tr(1)) * 0.2
	).tanh + 1 * LFPar.ar([100, 150]);
});
)


(
Ndef(\lv, {
	Mix(
		LeakDC.ar(
			LotkaVolterra.ar(SampleRate.ir*0.5,
				a: {LFNoise2.ar(Rand(0.000174, 0.00174)).range(0.49, 0.5)}!3,
				b: \b.kr(1.5, 0.1),
				c: {LFNoise2.ar(Rand(0.000174, 0.00174)).range(2, 4)}!4, // \c.kr(0.5, 0.1),
				a: {LFNoise2.ar(Rand(0.000174, 0.00174)).range(0.4, 0.41)}!4,
				h: \h.kr(0.01).lag2(1) * [0.5, 1, 2, 4],
				xi: 0.1 + \tr.tr(1)) * 0.2
		) * [5, 3, 3, 1].normalizeSum;
	).tanh
});

)

Ndef(\lv).set(\tr, 0.1)

Ndef(\lv).set(\a, 3.029850, \b, 4.094132, \c, 1.967217, \d, 2.295942);



Ndef(\lv).scope

Ndef(\lv).edit
::