lecture5 - E7 Spring 2010 Lecture 5 Raja Sengupta College...

Info iconThis preview shows pages 1–14. Sign up to view the full content.

View Full Document Right Arrow Icon
E7 Spring 2010: Lecture 5 Raja Sengupta College of Engineering University of California, Berkeley
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
What is the shape of BART’s speed as it travels between stations? The train accelerates from rest at 1.5 m/s2 for 20 seconds, travels at steady speed for 2 minutes, and decelerates again for 20 seconds at the same rate. Plot the speed profile of the train. What will the speed profile look like?
Background image of page 2
Answer: Like a trapezium 0 20 140 160 Slope 1.5 m/s 2 Slope -1.5 m/s 2 Speed Seconds
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
From lecture 3: trapezium(x) sets
Background image of page 4
From lecture 3: Code function out = myTrapezium(in) if lt(in,-2) out = 0; elseif and(ge(in,-2),lt(in,-1)) out = in + 2; elseif and(ge(in,-1),lt(in,1)) out = 1; elseif and(ge(in,1),lt(in,2)) out = -(in-2); else out = 0; end end
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
To get a nice plot we need to compute our trapezium function over and over again How do we write a program that will compute the same function many times? mT(0) mT(1.5) mT(1) mT(2)
Background image of page 6
How would we compute the Mandelbrot Set?
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Topics • Recursion – How do we make a computer do something n times, where n is large, or we do not know the value of n beforehand?
Background image of page 8
Textbook • The textbook does not discuss this topic • Try http://en.wikipedia.org/wiki/Recursion
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Aim: Write a program that will compute myTrapezium for an array of points. We should be able to make the array as large as we like. Mathematically this may be stated as: Program the function myTrapeziumArray defined below myTrapeziumArray([v 1 v 2 …..v n ]) = [myTrapezium(v 1 ) myTrapezium(v 2 ) ….….myTrapezium(v n )] n could be any number in {1, 2, 3, …. .}
Background image of page 10
To get a nice plot we need to compute our trapezium function over and over again mT(0) mT(1.5) mT(1) mT(2) Example: [v1 v2 v3 v4] = [0 1 1.5 2] Problem: Compute myTrapeziumArray ([0 1 1.5 2])
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Aim: Write a program that will compute myTrapezium for an array of points. We should be able to make the array as large as we like. Mathematically this may be stated as: Program the function myTrapeziumArray defined below myTrapeziumArray([v 1 v 2 …..v n ]) = [myTrapezium(v 1 ) myTrapezium(v 2 ) ….….myTrapezium(v n )] n could be any number in {1, 2, 3, …. .} How do we program the ….?
Background image of page 12
One way of doing this: Figure out how to define the function recursively • Previous definition myTrapeziumArray([v 1 v 2 …..v n ]) = [myTrapezium(v 1 ) myTrapezium(v 2 ) ….….myTrapezium(v n )] • Recursive definition myTrapeziumArray([v 1 v 2 …..v n ]) = [myTrapezium(v 1 ) myTrapeziumArray([v 2 …..v n ]) if n >=2 = [myTrapezium(v n )] if n = 1
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 14
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/09/2010 for the course ENGIN 7 taught by Professor Horowitz during the Spring '08 term at Berkeley.

Page1 / 34

lecture5 - E7 Spring 2010 Lecture 5 Raja Sengupta College...

This preview shows document pages 1 - 14. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online