Part 1: Numerical integration reloaded

Similar documents
Quiz 1. Queues , Fall 2007 Recitation 10 Solutions 1

Numerical Integration

Double Integration: Non-Rectangular Domains

NUMERICAL INTEGRATION AND FUNCTION FUNCTIONS

Name & Recitation Section:

Euler s Method with Python

AP Calculus AB Summer Assignment 2018

Section 6.1 Estimating With Finite Sums

An introduction to Scheme

UNIT 11 VOLUME AND THE PYTHAGOREAN THEOREM

Animations involving numbers

Problem #3 Daily Lessons and Assessments for AP* Calculus AB, A Complete Course Page Mark Sparks 2012

Name: Target 12.2: Find and apply surface of Spheres and Composites 12.2a: Surface Area of Spheres 12.2b: Surface Area of Composites Solids

HVRSD Standards-Based Report Card Correlations for Math. Grade 1

R f da (where da denotes the differential of area dxdy (or dydx)

Lesson 13: Exploring Factored Form

SCHEME AND CALCULATOR 5b

Math 11 Fall 2016 Section 1 Monday, October 17, 2016

4.7 Approximate Integration

MEI Desmos Tasks for AS Pure

RACKET BASICS, ORDER OF EVALUATION, RECURSION 1

3.3 Optimizing Functions of Several Variables 3.4 Lagrange Multipliers

2002 Midterm Solutions

Parametric curves. Reading. Curves before computers. Mathematical curve representation. CSE 457 Winter Required:

1.OA.1. 1.OA.2 MP: Make sense of problems and persevere in solving them MP: Model with mathematics. Common Core Institute

My Notes CONNECT TO SCIENCE. Horticulture is the science and art of growing fruit, flowers, ornamental plants, and vegetables.

Prime Time (Factors and Multiples)

Math 113 Exam 1 Practice

This exam is worth 30 points, or 18.75% of your total course grade. The exam contains

Math 250A (Fall 2009) - Lab I: Estimate Integrals Numerically with Matlab. Due Date: Monday, September 21, INSTRUCTIONS

Notice that the height of each rectangle is and the width of each rectangle is.

Direction Fields; Euler s Method

CS2500 Exam 2 Fall 2011

INTERPRETERS 8. 1 Calculator COMPUTER SCIENCE 61A. November 3, 2016

The purpose of this lesson is to familiarize you with the basics of Racket (a dialect of Scheme). You will learn about

Slide 2 / 222. Algebra II. Quadratic Functions

MATH 31A HOMEWORK 9 (DUE 12/6) PARTS (A) AND (B) SECTION 5.4. f(x) = x + 1 x 2 + 9, F (7) = 0

CS1102: Macros and Recursion

Integrated Mathematics I Performance Level Descriptors

Measurement and Geometry: Area and Volume of Geometric Figures and Objects *

C3 Numerical methods

Common Core Standards for Mathematics. Grade 1. Operations and Algebraic Thinking Date Taught

CS3: Introduction to Symbolic Programming. Lecture 8: Introduction to Higher Order Functions. Spring 2008 Nate Titterton

Building a system for symbolic differentiation

Volumes of Rotation with Solids of Known Cross Sections

Three-Dimensional Shapes

A Brief Introduction to Scheme (II)

Recursion. CSCI 112: Programming in C

Prentice Hall Mathematics: Course Correlated to: Colorado Model Content Standards and Grade Level Expectations (Grade 8)

6.001: Structure and Interpretation of Computer Programs

Lecture 17. ENGR-1100 Introduction to Engineering Analysis CENTROID OF COMPOSITE AREAS

2.2 Volumes of Solids of Revolution

Concept of Curve Fitting Difference with Interpolation

Worksheets for GCSE Mathematics. Perimeter & Area. Mr Black's Maths Resources for Teachers GCSE 1-9. Shape

User-defined Functions. Conditional Expressions in Scheme

POLYGONS

CS115 - Module 10 - General Trees

Middle School Math Course 3

Parametric curves. Brian Curless CSE 457 Spring 2016

Diocese of Erie Mathematics Curriculum First Grade August 2012

Cecil Jones Academy Mathematics Fundamentals

Represent and solve problems involving addition and subtraction

Standards for Mathematics: Grade 1

Identify the following 3-D Geometric Shapes

8.4 Graphs of Sine and Cosine Functions Additional Material to Assist in Graphing Trig Functions

Grade 7/8 Math Circles Fall Nov.4/5 The Pythagorean Theorem

Double Integrals in Polar Coordinates

Ch. 3 Review. Name: Class: Date: Short Answer

Area rectangles & parallelograms

3.1 Maxima/Minima Values

Inequalities and you 3

To graph the point (r, θ), simply go out r units along the initial ray, then rotate through the angle θ. The point (1, 5π 6

Introduction to Functions

Algebra 1. Standard 11 Operations of Expressions. Categories Combining Expressions Multiply Expressions Multiple Operations Function Knowledge

Unit Maps: Grade 7 Math

CSAP Achievement Levels Mathematics Grade 7 March, 2006

11.4 Volume of Prisms and Cylinders

Interpreters and Tail Calls Fall 2017 Discussion 8: November 1, 2017 Solutions. 1 Calculator. calc> (+ 2 2) 4

Chapter 8 Review. 1. Find both the perimeter and the area 2. Find both the perimeter and the area

Number Sense Third Grade Fourth Grade Fifth Grade MA.4.NS.1.a.1: Read, demonstrate, and write whole numbers up to 500.

Pre-Algebra Notes Unit 10: Geometric Figures & Their Properties; Volume

Equivalent Fractions R46. Step 1 Make a model to represent 2 _. Step 2 Divide the rectangle from Step 1 in half.

1 Programs for double integrals

Volume of Cylinders. Volume of Cones. Example Find the volume of the cylinder. Round to the nearest tenth.

Contemporary Calculus Dale Hoffman (2012)

Case Study: Undefined Variables

MAT 1475 Final Exam Review Problems

Someone else might choose to describe the closet by determining how many square tiles it would take to cover the floor. 6 ft.

Geometry. Unit 9 Equations of Circles, Circle Formulas, and Volume

Maths Year 11 Mock Revision list

CROSSWALK A: Oregon Mathematics, 2002 Grade Level Standards to 2007 Content Standards

Deferred operations. Continuations Structure and Interpretation of Computer Programs. Tail recursion in action.

First Grade Math Map

Pre-Algebra, Unit 10: Measurement, Area, and Volume Notes

Exercises for a Numerical Methods Course

1.00 Lecture 32. Integration. Reading for next time: Numerical Recipes Packaging Functions in Objects

Homework 3: Recursion Due: 11:59 PM, Sep 25, 2018

CS 61A Interpreters, Tail Calls, Macros, Streams, Iterators. Spring 2019 Guerrilla Section 5: April 20, Interpreters.

EECS 321 Programming Languages

Discovering. Algebra. An Investigative Approach. Condensed Lessons for Make-up Work

Transcription:

6.037, IAP 2018 Project 1 1 MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.037 Structure and Interpretation of Computer Programs IAP 2018 Project 1 Release date: 10 January, 2018 Due date: 16 January, 2018 at 1900h In this project you will write more sophisticated procedures, including higher-order procedures and list manipulation. This project is divided into two parts, which you should submit together. Part 1: Numerical integration reloaded Problem 1: Integrating any function In Project 0, you wrote procedures to integrate the function from Ben Bitdiddle s dream. Since we might want to approximate the area under other curves, let s generalize that code. We will pass the function to integrate as a parameter. You may implement integral using either a recursive or iterative algorithm. (define (integral func num-steps x1 x2) Problem 2: Area of a unit circle Integration is good for more than just dream interpretation. Recall that a circle of radius 1 is the set of points (x, y) such that x 2 + y 2 = 1. With a little algebra, we get y = ± 1 x 2.

6.037, IAP 2018 Project 1 2 The area of our circle is four times the area of the upper-right quarter-circle: Therefore, π = 4 1 0 1 x 2 dx. Write a procedure to approximate π using integral. Try to do it without any additional defines. (define (approx-pi num-steps)

6.037, IAP 2018 Project 1 3 Problem 3: Integrating with pieces of any shape Alyssa P. Hacker points out to Ben that a rectangle is a rather poor approximation of a curve. What s better than a rectangle with one corner on a curve? A trapezoid with two corners on the curve! Recall that integral sums a bunch of areas obtained from rectangles, like bitfunc-rect did for Ben s original function. We could change integral to use trapezoids but instead, let s make this another parameter. Write procedures rectangle and trapezoid to compute the area of the respective shapes. Then write integral-with, which is like integral, but takes one of these procedures as its first argument, and uses it for each segment of the integral. (define (rectangle func x1 x2) (define (trapezoid func x1 x2) (define (integral-with piece func num-steps x1 x2) The idea is that (integral-with rectangle f n x1 x2) should give exactly the same result as (integral f n x1 x2), while (integral-with trapezoid f n x1 x2) might be more accurate (for the same num-steps).

6.037, IAP 2018 Project 1 4 Problem 4: Better approximation of π Rewrite your procedure from Problem 2 to use trapezoidal integration. (define (better-pi num-steps) Optional problems There are many more sophisticated ways to do numerical integration. You could replace the trapezoids with quadratic functions; this is known as Simpson s rule. Or you could discard the idea of evenly-spaced intervals, and instead subdivide intervals whose estimated error is too high. If you like, implement one of these ideas, or another fancy integration method. Tell us what you did, and how much it improves accuracy. Racket includes a sophisticated graphing system, which you can read about at http://docs. racket-lang.org/plot. Use this to illustrate some properties of your numeric integrators. For example, you could plot a function along with rectangular and trapezoidal area approximations, shading each one differently.

6.037, IAP 2018 Project 1 5 Part 2: Symbolic differentiation Alyssa P. Hacker isn t too impressed with Ben s numerical integrals. What good is an approximate answer? I ll get an exact answer, by manipulating algebraic expressions containing variables. Alyssa does some reading and discovers that symbolic integration is very hard, so she decides to tackle symbolic differentiation. Alyssa needs a way to represent algebraic expressions as Scheme data. She decides to represent numerical constants as Scheme numbers, and variables as Scheme symbols. She starts with a procedure to find the derivative of a constant with respect to ( wrt ) some variable: (define (deriv-constant wrt constant) 0) And she tests it: > (deriv-constant 'x 3) 0 That was easy. Problem 5: Derivative of a variable Write a procedure to find the derivative of a variable with respect to some variable. (define (deriv-variable wrt var) Test cases: (deriv-variable 'x 'x) ; -> 1 (deriv-variable 'x 'y) ; -> 0 Problem 6: Calling the right function So far, an expression could be either a constant or a variable. Write a procedure which finds the derivative in either case, by calling deriv-constant or deriv-variable as appropriate. (define (derivative wrt expr) (cond ; your code here (else (error "Don't know how to differentiate" expr)))) Test cases: (derivative 'x 3) ; -> 0 (derivative 'x 'x) ; -> 1

6.037, IAP 2018 Project 1 6 Problem 7: Derivative of a sum Alyssa decides to represent the sum of two expressions as a 3-element list: the symbol + followed by the two expressions. Recall that the derivative of a sum is just the sum of the derivatives: d d (A + B) = dx dx A + d dx B And write a procedure which finds the derivative of such an expression. (define (deriv-sum wrt expr) Then modify your code for Problem 6 to call deriv-sum when appropriate. You can add it to your solution for Problem 6, as long as you make a note here. Test case: (derivative 'x '(+ x 2)) ; -> (+ 1 0) Problem 8: Derivative of a product Alyssa represents products similarly, using * instead of +. Recall the product rule for derivatives: d dx (A B) = A d dx B + d dx A B And then write a procedure which finds the derivative of a product, and extend derivative as before. (define (deriv-product wrt expr) Test case: (derivative 'x '(* x 3)) ; -> (+ (* x 0) (* 1 3)) Returning any algebraically equivalent expression is also fine. Problem 9: Additional testing Write some additional test cases to test all the functionality of derivative. Optional problems Improve your code to handle sums and products of more than two expressions. Add support for more kinds of algebraic expressions.