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

Info icon This preview shows pages 1–15. 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
Image of page 1

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

View Full Document Right 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?
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
Image of page 3

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

View Full Document Right Arrow Icon
From lecture 3: trapezium(x) sets
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
Image of page 5

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

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

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

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

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

View Full Document Right 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, …..}
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])
Image of page 11

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

View Full Document Right 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 ….?
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
Image of page 13

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

View Full Document Right Arrow Icon
From lecture 3 we know how to do myTrapezium
Image of page 14
Image of page 15
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern