lecture5

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

This preview shows pages 1–15. 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
From lecture 3 we know how to do myTrapezium
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern