灯下 登录
计算机科学 / SICP / 3.5.3 Exploiting the Stream Paradigm

Exercise 3.73 · 习题

Exercise 3.73: 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
RC circuit consisting of a
resistor of resistance R and a capacitor of capacitance C in series.
The voltage response v of the circuit to an injected current i is
determined by the formula in Figure 3.33, whose structure is shown by the
accompanying signal-flow diagram.

SVG

Figure 3.33: An RC circuit and the associated signal-flow diagram.

Write a procedure RC that models this circuit. RC should take as

inputs the values of R, C, and d

t and should return a procedure

that takes as inputs a stream representing the current i and an initial

value for the capacitor voltage v

0 and produces as output the stream of

voltages v. For example, you should be able to use RC to model an

RC circuit with R = 5 ohms, C = 1 farad, and a 0.5-second time step by

evaluating (define RC1 (RC 5 1 0.5)). This defines RC1 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.

练习 3.73:我们可以用流来对电路建模,以流表示一系列时刻上的电流或电压值。例如,假设我们有一个 RC 电路,由电阻值为 R 的电阻器和电容值为 C 的电容器串联组成。电路对注入电流 i 的电压响应 v 由图 3.33 中的公式确定,其结构如附图的信号流图所示。

SVG

图 3.33:RC 电路及其对应的信号流图。

请写一个过程 RC 来对该电路建模。RC 应以 R、C 和 dt 的值作为输入,并返回一个过程,该过程以表示电流 i 的流和电容器初始电压 v₀ 作为输入,产生电压流 v 作为输出。例如,你应当能够用 RC 来对一个 R = 5 欧姆、C = 1 法拉、时间步长为 0.5 秒的 RC 电路建模,方法是对 (define RC1 (RC 5 1 0.5)) 求值。这将把 RC1 定义为一个过程,它接受表示电流时间序列的流和电容器初始电压,并产生电压输出流。