Introduction

In this assignment, you will work with streams to evaluate power series.

Consider the series ?(?) = ? . We can represent this series by its finite or 0 + ? 1 ? + ? 2 ? 2 +... infinite sequence of coefficients (? . We will view this sequence as a stream

Specification

For all functions below, use memoized streams. All input streams are nonempty, and may be finite or infinite. Compute only as much of the result stream as needed.

1. Write a function addSeries that takes two streams of coefficients for the series s(x) and t(x) and returns the stream of coefficients for the sum s(x) + t(x). For example, given 1+2x+3x 2+... and 2+6x+9x 2+..., the result will be 3+8x+12x 2+...

2. Write a function prodSeries that takes two streams of coefficients for the series s(x) and t(x) and returns the stream of coefficients for the product s(x) ⋅ t(x). For example, given 1+2x+3x 2+... and 2+6x+9x 2+..., the result will be 2+10x+27x 2+... Hint: consider that a series can be written as , where s1 ?(?) = ? (x) is another series. 0 + ? ? 1 (?)

3. Write a function derivSeries that takes a stream of coefficients for the series s(x), and returns a stream of coefficients for the derivative s’(x). For example, given 1+2x+3x 2+..., the result will be 2+6x+...,

4. Write a function coeff that takes a stream of coefficients for the series s(x) and a natural number n, and returns the array of coefficients of s(x), up to and including that of order n. If the stream has fewer coefficients, return as many as there are.

5. Write a function evalSeries that takes a stream of coefficients for the series s(x), and a
natural number n, and returns a closure. When called with a real number x, this closure will
return the sum of all terms of s(x) up to and including the term of order n

HW5-Streams.pdf

56.4 KB

Get Higher Grades Now

Tutors Online

Get Free Quote!

313 Experts Online