Complete the definition of the following procedure, which multiplies two series: (define (mul-series s1 s2) (stream-cons < ??E1?? > (add-series < ??E2?? > < ??E3?? > ))) To test your procedure, demonstrate that the product of S1 (from problem 1) and S1 is S2. What is the coefficient of x10 in the product of S2 and S2? Turn in your definition of mul-series. (Optional: Give a general formula for the coefficient of xn in the product of S2 and S2.)(please use racket)
时间: 2024-03-10 22:48:22 浏览: 77
Here is the complete definition of the `mul-series` procedure:
```
(define (mul-series s1 s2)
(stream-cons (* (stream-car s1) (stream-car s2))
(add-series (scale-stream (stream-cdr s1) s2)
(mul-series s1 (stream-cdr s2)))))
```
To test the procedure, we can define S1 and S2 as follows:
```
(define S1 (integrate-series (scale-stream (stream-cons 1 (stream-cons -1 (stream-repeat 0))) 1/2)))
(define S2 (mul-series S1 S1))
```
The coefficient of x10 in the product of S2 and S2 can be computed by extracting the 10th element of the product series:
```
(stream-ref S2 10)
```
The general formula for the coefficient of xn in the product of S2 and S2 is:
```
(coefficient of xn in S2) * 2 + (sum of (coefficient of xk in S2) * (coefficient of x(n-k) in S2) for k from 1 to n/2)
```
Here is the implementation of the `coefficient` procedure:
```
(define (coefficient s n)
(stream-ref s n))
(define (product-coefficient s n)
(+ (* 2 (coefficient s n))
(stream-sum (stream-map (lambda (k)
(* (coefficient s k)
(coefficient s (- n k))))
(stream-from 1)))))
```
We can use this procedure to compute the coefficient of x10 in the product of S2 and S2 as follows:
```
(product-coefficient S2 10)
```
阅读全文