正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 17.5.37 In fact exactly that idea of a feedback loop can be used to buildIntegration as an example an integrator Suppose we had an integrand represented as a (define (integral integrand init dt) tream of values, that is, the height of a function at a sequence define int of points, thus tracing out a curve. We want to get the area ⊥n⊥t add-streams (stream-scale dt integrand) under that curve, by integration. We could certainly generate a stream that corresponds to the sample values of the integrand We start with some initial value(probably zero). To get the next value, that is the area under the curve to this point, we take he area computed so far(that is the value of the output stream), and add to it the next value of the input stream, multiplied by the spacing between the sample points (i. e. the area of the rectangle with width dx and height the value of the function which is the approximation to the area of this section of the curve). Thus we can add up the area of the curve incrementally, generating the area obtained by adding in the next point to the area computed so far, all done incrementally on demand For example, we could use this to generate the integral of the stream of ones Integration as an example Slide 17.5.38 define (integral integrand init at if we take the integral of the stream of ones(i. e the function define⊥nt with constant value 1), with a spacing of, say, 2, we get the following behavior. The first element of the returned stream is (add-streams (atream-scale dt integrand) just the initial value, 0 111 sca1e22222 Slide 17.5.39 Integration as an example The next value in this integral stream is given by scaling the define (integral integrand init at first element of the input stream and adding it to what we have added up so far. In terms of streams, we get the first value of ones, multiply it by two, and add it to the first of the integral (add-streams (stream-gcale dt integrand) int))) which we just computed. This results in the new value, 2, plus a promise to compute the next value in the sequence when needed =>⊙24686.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 17.5.37 In fact exactly that idea of a feedback loop can be used to build an integrator. Suppose we had an integrand represented as a stream of values, that is, the height of a function at a sequence of points, thus tracing out a curve. We want to get the area under that curve, by integration. We could certainly generate a stream that corresponds to the sample values of the integrand. We start with some initial value (probably zero). To get the next value, that is the area under the curve to this point, we take the area computed so far (that is the value of the output stream), and add to it the next value of the input stream, multiplied by the spacing between the sample points (i.e. the area of the rectangle with width dx and height the value of the function, which is the approximation to the area of this section of the curve). Thus we can add up the area of the curve incrementally, generating the area obtained by adding in the next point to the area computed so far, all done incrementally on demand. For example, we could use this to generate the integral of the stream of ones... Slide 17.5.38 ... if we take the integral of the stream of ones (i.e. the function with constant value 1), with a spacing of, say, 2, we get the following behavior. The first element of the returned stream is just the initial value, 0. Slide 17.5.39 The next value in this integral stream is given by scaling the first element of the input stream and adding it to what we have added up so far. In terms of streams, we get the first value of ones, multiply it by two, and add it to the first of the integral, which we just computed. This results in the new value, 2, plus a promise to compute the next value in the sequence when needed
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有