Różnice
Różnice między wybraną wersją a wersją aktualną.
|
|
pl:prolog:pllib:oscillator [2019/06/27 15:50] |
pl:prolog:pllib:oscillator [2019/06/27 15:50] (aktualna) |
| ====== Oscillator ====== |
| {{tag>model electronics}} |
| ===== Description ===== |
| An oscillator model with energy constraint. |
| |
| **Source**: PROLOG programming for artificial intelligence, 3rd Edition, Harlow, 2001, ISBN 0-201-40375-7. |
| ===== Download ===== |
| Program source code: {{oscillator.pl}} |
| ===== Listing ===== |
| <code prolog> |
| % File energy.pl: An oscillator model with energy constraint |
| % (alternative to one in Fig. 20.14). |
| |
| :- op( 200, xfy, [:, ::]). |
| :- op( 220, xfy, ..). |
| |
| legalstate( [ X, V, A]) :- |
| deriv( X, V), |
| deriv( V, A), |
| MinusA = a:_, |
| sum( A, MinusA, a:zero/std), % MinusA = -A |
| mplus( X, MinusA), % Spring pulling block back |
| energy( X, V). % Weak energy conserv. constraint |
| |
| energy( X, V) :- |
| V = v:v0/_, !, X = x:zero/_ % If V=v0, X must be zero |
| ; |
| X = x:zero/_, !, V = v:minf..zero/_ % Here V must be -v0 |
| ; |
| true. % Otherwise X non-zero, no constraint on V |
| </code> |
| ===== Comments ===== |
| |