lecture5

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

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

E7 Spring 2010: Lecture 5 Raja Sengupta College of Engineering University of California, Berkeley

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

View Full Document
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?
Answer: Like a trapezium 0 20 140 160 Slope 1.5 m/s 2 Slope -1.5 m/s 2 Speed Seconds

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

View Full Document
From lecture 3: trapezium(x) sets
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

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

View Full Document
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)
How would we compute the Mandelbrot Set?

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

View Full Document
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?
Textbook • The textbook does not discuss this topic • Try http://en.wikipedia.org/wiki/Recursion

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

View Full Document
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, …. .}
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])

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

View Full Document
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 ….?
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

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

View Full Document
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
Ask a homework question - tutors are online