Figure 3.33: An RC circuit and the associated signal-flow diagram.
We can model electrical circuits using streams to represent the values of currents or voltages at a sequence of times. For instance, suppose we have an
circuit consisting of a resistor of resistance
and a capacitor of capacitance
in series. The voltage response
of the circuit to an injected current
is determined by the formula in figure 3.33, whose structure is shown by the accompanying signal-flow diagram.
Write a procedure
that models this circuit.
should take as inputs the values of
and should return a procedure that takes as inputs a stream representing the current
and an initial value for the capacitor voltage
and produces as output the stream of voltages
. For example, you should be able to use
to model an
R = 5
C = 1
farad, and a
-second time step by evaluating
(define RC1 (RC 5 1 0.5))
. This defines
as a procedure that takes a stream representing the time sequence of currents and an initial capacitor voltage and produces the output stream of voltages.
There are no comments yet.
You must log in to post a comment.Login
(define (stream-car stream) (car stream)) (define (stream-cdr stream) (force (cdr stream))) (define (stream-ref s n) (if (= n 0) (stream-car s) (stream-ref (stream-cdr s) (- n 1)))) (define (stream-map proc . list-of-stream) (if (null? (car list-of-stream)) '() (cons-stream (apply proc (map (lambda (s) (stream-car s)) list-of-stream)) (apply stream-map (cons proc (map (lambda (s) (stream-cdr s)) list-of-stream)))))) (define (scale-stream stream factor) (stream-map (lambda (x) (* x factor)) stream)) (define (add-streams s1 s2) (stream-map + s1 s2)) (define ones (cons-stream 1 ones)) (define integers (cons-stream 1 (add-streams ones integers))) (define (integral integrand initial-value dt) (define int (cons-stream initial-value (add-streams (scale-stream integrand dt) int))) int) (define RC1 (RC 5 1 0.5)) (define voltage-stream (RC1 integers 1)) (check-equal? (stream-ref voltage-stream 0) 6) (check-equal? (stream-ref voltage-stream 1) 11.5) (check-equal? (stream-ref voltage-stream 2) 17.5)