# Różnice

Różnice między wybraną wersją a wersją aktualną.

 — pl:prolog:pllib:circuit_simulator [2019/06/27 15:50] (aktualna) Linia 1: Linia 1: + ====== Circuit simulator ====== + {{tag>​electronics simulator}} + ===== Description ===== + Electric circuit simulator in CLP(R) + + **Source**: ​ PROLOG programming for artificial intelligence,​ 3rd Edition, Harlow, 2001, ISBN 0-201-40375-7. + ===== Download ===== + Program source code: {{circuit_simulator.pl}} + ===== Listing ===== + + % Electric circuit simulator in CLP(R) + + % resistor( T1, T2, R): + %  R=resistance;​ T1, T2 its terminals + + resistor( (V1,I1), (V2,I2), R)  :- + I1 = -I2, V1-V2 = I1*R . + + % diode( T1, T2): + %   T1, T2 terminals of a diode + %   Diode open in direction from T1 to T2 + + diode( (V1,I1), (V2,I2) )  :- + I1 + I2 = 0, + I1 > 0, V1 = V2 + ; + I1 = 0, V1 =< V2. + + battery( (V1,I1), (V2,I2), Voltage) ​ :- + I1 + I2 = 0, Voltage = V1 - V2 . + + % conn( [T1,​T2,​...]):​ + %  Terminals T1, T2, ... connected + %  Therefore all el. potentials equal, sum of currents = 0 + + conn( Terminals) ​ :- + conn( Terminals, 0). + + conn( [ (V,I) ], Sum)  :- + Sum + I = 0 . + + conn( [ (V1,I1), (V2,I2) | Rest], Sum)  :- + V1 = V2, Sum1 = Sum + I1, + conn( [ (V2, I2) | Rest], Sum1). + + ​ + ===== Comments =====
pl/prolog/pllib/circuit_simulator.txt · ostatnio zmienione: 2019/06/27 15:50 (edycja zewnętrzna)