EECS 110 Recitation #3 Ning Xia Northwestern University.

Slides:



Advertisements
Similar presentations
COMPSCI 105 S Principles of Computer Science
Advertisements

Computer Science 1000 LOGO I. LOGO a computer programming language, typically used for education an old language (1967) the basics are simple: move a.
Logo Lesson 3 TBE 540 Fall 2004 Farah Fisher. Prerequisites for Lesson 3 Before beginning this lesson, the student must be able to… Use simple Logo commands.
Geometric Probability
Congruence and Similarity
EECS 110: Lec 6: Fractals and Trutles Aleksandar Kuzmanovic Northwestern University
SOLVING LINEAR EQUATIONS. Example 1 Solve take 3 from both sides divide both sides by 2.
CS 5 Today CS 5 alien on strike! Claremont residents report droplets of water falling down-ward from the sky: unexplained meteorological phenomenon causes.
EXAM TIPS What to do and What not to do!. ALWAYS SHOW YOUR WORKING OUT Most questions are worth two or more marks, so even if you make a slip and get.
Simulation of Random Walk How do we investigate this numerically? Choose the step length to be a=1 Use a computer to generate random numbers r i uniformly.
Log on and Download from website:
Perimeter & Area Lessons 19 & 20.
Similar Figures Examples and Step by Step Directions.
Programming Training kiddo Main Points: - Python Statements - Problems with selections.
Jeopardy Geometry Circles 1 Triangles 2 Polygons 3 Formulas 4 Angles 5 Pot Luck
B.A. (Mahayana Studies) Introduction to Computer Science November March Logo (Part 2) More complex procedures using parameters,
Python Programming in Context Chapter 9. Objectives To introduce functional programming style To practice writing recursive functions To introduce grammars.
Computer Science 111 Fundamentals of Programming I Introduction to Graphics.
1 CSC 221: Computer Programming I Fall 2011 Fun with turtle graphics  turtle module  relative motion (setup, reset, left, right, forward, backward) 
Main Points: - Python Turtle - Fractals
A new human-computer interface?
EECS 110: Lec 6: Fractals and Trutles Aleksandar Kuzmanovic Northwestern University
Warm Up Evaluate. Round to the nearest hundredth () 6. (3)
IS 313: Putting loops to work for you What's next? [ 1, 11, 21, 1211, , ? ] [ -35, -24, -13, -2, 9, 20, 31, ? ] [ 2, 22, 222, ? ] [ 26250, 5250,
CS 121 Today Fractals and Turtles! The Koch Curve how random…
Rhombus in Shapesville 5 th grade reading book By: Yasir fisher.
Jeopardy Terminology Geometry This PowerPoint was revised from the original version from; geometry.ppt.
Constructing and finding area of regular flatlanders
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 4 Conditionals Turtles.
4.5: Do Now: Review 4.3/4.4. The area of a rectangle with length = 3x + 1 and width = 2x + 1 is 22. Write and solve an equation to find the dimension of.
To find the perimeter of a rectangle, just add up all the lengths of the sides: Perimeter = L + w + L + w         = 2L + 2w To find the area of a rectangle,
NCSC Sample Instructional Unit - Elementary Measurement Lesson 4
Maths Notes Graphs 4. Travel Graphs
Programming Training kiddo Main Points: - Python Statements - Problems with selections.
Toddrick’s Shape Scrapbook By:Toddrick Newton. The perimeter, P, of a rectangle is given by the formula P = 2(l + w) where l is the length width of the.
Insertion Sort Suppose that you have a hand of cards that you want to sort – in this case, assume that you have all thirteen cards of one suit. One way.
Stretching & Shrinking 7th grade Writing Rules Scale Factors Vocabulary Terms SF and AreaSimilar.
PYTHON FUNCTIONS. What you should already know Example: f(x) = 2 * x f(3) = 6 f(3)  using f() 3 is the x input parameter 6 is the output of f(3)
Holt Geometry 9-6 Geometric Probability 9-6 Geometric Probability Holt Geometry.
Functions. functions: a collection of lines of code with a name that one can call. Functions can have inputs and outputs.
G-11 (1-5) Using formulas in Geometry I can use formulas to compute perimeter and area of triangles, squares, rectangles, and circles.
Jeopardy Terminology Quiz Geometry All points on a circle are the same distance from this point. (100)
Year 8 Revision Each slide will have a different topic. There will be questions and hints to help you.
LENGTH and PERIMETER.
Fundamentals of Programming I Introduction to Graphics
Graphics CIS 40 – Introduction to Programming in Python
Lecture 19 – Numerical Integration
Main Points: - Python Turtle - Fractals
5-6 to 5-7 Using Similar Figures
EECS 110: Lec 6: Fractals and Trutles
Position vs. Time Graph Scalar vs. Vector Quantities
Area of Triangles.
Fundamentals of Programming I Introduction to Graphics
We are removing the 4th part of hw2pr2 for now.
Fractions and Decimals
EECS 110: Lec 10: Definite Loops and User Input
Exercise (1) What does function chai draw? def chai(size):
Chap. 3 Functions Start Python IDLE (Shell) and open a new file.
Main Points: - Python Turtle - Fractals
Trees and Colored Edge Detection
Area of Triangles.
2 types of scale factor problems
Objectives Students will learn how to use geometric mean to find segment lengths in right triangles and apply similarity relationships in right triangles.
Loops and Simple Functions
By- Sabrina,Julianna, and Killian
Dilations on the Coordinate Plane
Area Of Composite Shapes
Some helpful formulas:
Background for lab: the ord() function
From Barb Ericson Georgia Institute of Technology June 2008
Presentation transcript:

EECS 110 Recitation #3 Ning Xia Northwestern University

y = 1 x area steps(low,hi,N)fsteps(recip,low,hi,N) def recip(x): return 1.0/x finteg(f,low,hi,N) Numerical Integration Lab 2: Tuesday

low = 1.0hi = 10.0 y = 1 x area steps(low,hi,N) N == 9 == total number of steps (rectangles) fsteps(recip,low,hi,N) def recip(x): return 1.0/x finteg(f,low,hi,N)

Numerical Integration def fracSteps(N): return [ x/N for x in range(N) ] def steps(low,hi,N): return [ low + (hi-low)*x for x in fracSteps(N) ] def fsteps(f,low,hi,N): return [ f(x) for x in steps(low,hi,N) ] def finteg(f,low,hi,N): return sum(fsteps(f,low,hi,N))*(hi-low)/float(N) x values fractional steps y values integral: heights width

An example closer to home An overworked NU student (S) leaves a pub after a “late- night” breakfast and, each moment, randomly stumbles toward Dorms (W) or toward Michigan Lake (E) DormsMichigan Lake (E) (W) Platt Write a program to model and analyze! this scenario... Hw2 Pr2 S Once the student arrives at the dorms or the Michigan Lake, the trip is complete. The program should then print the total number of steps taken.

An example closer to home DormMichigan Lake (E) (W) Platt Write a program to model and analyze! this scenario... Hw2 Pr2 S rs()rwPos(s, nsteps)rwSteps(s, low, hi) take a random step of +1 or -1 take nsteps random steps starting at s take random steps starting at s until you reach either low or hi An overworked NU student (S) leaves a pub after a “late- night” breakfast and, each moment, randomly stumbles toward Dorms (W) or toward Michigan Lake (E) Once the student arrives at the dorm or the Michigan Lake, the trip is complete. The program should then print the total number of steps taken.

rwPos(start,nsteps) start = position of sleepwalker nsteps = number of random steps taken by walker Returns the position of the walker after nsteps random steps Call to rs() + recursion

rwSteps(start, low, hi) start = position of sleepwalker low = lowest position he can be at hi = highest position he can be at Returns the number of steps until walker reaches low or hi Call to rs() + recursion.

Random walk analysis Average final signed-displacement - Statistics on the output of rwPos() Average final squared signed-displacement Both take as input the number of steps of the random walker and the number of statistical runs

Python's Etch-a-Sketch A new human-computer interface? from turtle import * reset() left(90) forward(50) right(90) backward(50) down() or up() color('green') width(5) done() and lots more! for turtle help degrees! states if the pen draws or not

hw2pr3 spiral (I) spiral( initLength, angle, multiplier ) close-up of innermost part of the spiral… spiral( 100, 90, 0.9 )

hw2pr3 spiral (II) You can draw it inside out (stop at 1000 pixels) or outside in (stop at 1 pixel) Function takes as input length of segment to draw, angle and a scaling factor for the length of the segment Uses recursion Each call to spiral: – Draw line – Change orientation by angle – Update length of segment by scaling – Check base case – Recall spiral

hw2pr3 svTree (I) svTree( trunkLength, levels ) svTree( 100, 4 ) and more! (if you want)

hw2pr3 svTree (II) Function takes as input a segment length and the number of tree levels Uses recursion Each call to svTree: Decrease number of levels Draw part of tree at this level Check base case Call recursively svTree twice to draw the left and right subtrees Don’t forget to change the angles before

The Koch curve (I) snowflake( 100, 0 ) snowflake( 100, 1 )snowflake( 100, 2 ) snowflake( 100, 3 )snowflake( 100, 4 )snowflake( 100, 5 )

The Koch curve (II) snowFlake gets as input the segment size and the number of levels to draw Helpful to have a function which draws the sides of the triangle. The side drawing function: If reached final level, draw full side Otherwise just call the side drawing function on the 4 sides that we just broke into

Good Luck !