New User Special Price Expires in

Let's log you in.

Sign in with Facebook


Don't have a StudySoup account? Create one here!


Create a StudySoup account

Be part of our community, it's free to join!

Sign up with Facebook


Create your account
By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here

Research for Advanced Undergraduates

by: Harvey Krajcik

Research for Advanced Undergraduates CHM ENG H194

Harvey Krajcik

GPA 3.99


Almost Ready


These notes were just uploaded, and will be ready to view shortly.

Purchase these notes here, or revisit this page.

Either way, we'll remind you when they're ready :)

Preview These Notes for FREE

Get a free preview of these Notes, just enter your email below.

Unlock Preview
Unlock Preview

Preview these materials now for free

Why put in your email? Get access to more of this material and other relevant free materials for your school

View Preview

About this Document

Class Notes
25 ?




Popular in Course

Popular in Chemical Engr And Materials Science

This 12 page Class Notes was uploaded by Harvey Krajcik on Thursday October 22, 2015. The Class Notes belongs to CHM ENG H194 at University of California - Berkeley taught by Staff in Fall. Since its upload, it has received 23 views. For similar materials see /class/226641/chm-eng-h194-university-of-california-berkeley in Chemical Engr And Materials Science at University of California - Berkeley.

Popular in Chemical Engr And Materials Science


Reviews for Research for Advanced Undergraduates


Report this Material


What is Karma?


Karma is the currency of StudySoup.

You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 10/22/15
C561A Notes Week 2 Order of evaluation recursion procedures as data The Substitution Model We consider how Scheme evaluates an expression by using the substitution model First let s review how an expression is evaluated again 1 Evaluate all subexpressions of the combination including the procedure and arguments so that we know exactly what they are 2 Apply the evaluated procedure to the evaluated arguments that we obtained in the previous step To perform step 2 we evaluate the body of the procedure after we replace the formal parameters with the given arguments Let s dive right in First a few functions to play with define double x x x define square y y y define f z square double 2 in Now what happens when we do f 2 l Here s how the substitution model wants us to think 1 Let s evaluate the expression f is a lambda what s 2 l f 3 2 Now let s take the body of f and substitute 3 for z square double 3 1 3 Now we evaluate the expression is l is l but what is square double 3 Well square is a procedure what is double 3 Well double is a procedure and 3 is 3 So now that we ve evaluated everything we can start applying the procedures First we do double by substituting the body in again square 3 3 l 4 Now what s 3 3 square 6 l 5 How do we apply square Let s substitute in the body of square Jr 6 6 l 6 Sowhat s 6 6 36 1 7 And what s 36 l If the above seems a little obvious it s because it is the substitution model is the most intuitive way to think about expression evaluation Note however that this is not how Scheme actually works and as we ll find out later in the course the substitution model eventually will become inadequate for evaluating our expressions or more specifically when we introduce assignments But for now when we re still in the realm of functional programming the substitution model will serve us nicely Applicative vs Normal Order The substitution model example presented above was done using quotapplicative orderquot where Scheme first evaluates completely all the procedures and arguments before executing the function call Another way to do this in quotnormal order is to expand out complex expressions involving defined procedures into one involving only primitive operators and selfevaluating values and then perform the evaluation In other words we defer evaluation of the arguments we substitute the unevauated expression as opposed to evaluated expression for applicative order into the body of a procedure Justin Chen CSGlA Fall 2009 notes courtesy of Chung Wu Soforthesame problem f 2 1 l We llexpand f into its body first leaving 2 l unevaluated square double 2 1 1 2 Now we want to expand square let s write in the body ofsquare and substitute double 2 l for y leaving double 2 1 unevaluated double 2 1 double 2 1 l 3 Now we want to expand double let s write the body of double and substitute 2 l for x 2 1 2 1 2 1 2 11 4 Finally we ve expanded everything tojust primitive operators and selfevaluating values We ll do these one by one 3 2 1 2 1 2 1 1 33 2 1 21 1 33 3 21 1 33 33 1 6 3 3 1 66 1 361 3397 Well okay that seems harmless enough It sjust two ways of thinking about the problem for applicative order we evaluate completely a subexpressions first before we apply the current procedure For normal order we expand all the defined procedures into their bodies until everything is expressed in terms of primitive operations and selfevaluating values then we find the answer So what s the difference Some ofyou will raise concerns about efficiency obviously in this case normal order causes us to perform 2 1 four times whereas we only performed the same calculation once for applicative order But in terms of correctness the two are the same That is infunctional programming applicative and normal order of evaluation will always return the same answer QUESTIONS 1 Above applicative order was more efficient Define a procedure where normal order is more efficient 2 Evaluate this expression using both applicative and normal order square random x Will you get the same result from both Why or why not 3 Consider a magical function count that takes in no arguments and each time it is invoked it returns 1 more than it did before starting with 1 Therefore count count will return 3 Evaluate square square count with both applicative and normal order explain your result Justin Chen CSGlA Fall 2009 notes courtesy of Chung Wu 2 Yoshimi Battles the Pink Recursive Robots A quotrecursive procedure is one that calls itself in its body The classic example is factorial define fact 11 if n 0 l n fact n l Note that in order to calculate the factorial of n we tried to first calculate the factorial of n l This is because of the observation that 5i 5 4 l and that if we know what 4i is we could find out what Si is If this makes you a bit suspicious it s okay it takes a little getting used to The trick is to use the procedure as fit is already correcty defined This will become easier with practice The mantra to repeat to yourself is TRUST THE RECURSION QUESTIONS 1 Write a procedure expt base power which implements the exponents function For example expt 3 2 returns 9 and expt 2 3 returns 8 2 I want to go up a flight of stairs that has 1 steps I can either take 1 or 2 steps each time How many ways can I go up this flight of stairs Write a procedure count Stairways that solves this for me 3 Define a procedure subsent that takes in a sentence and a parameter 1 and returns a sentence with elements starting from position i to the end The first element has i 0 In other words subsent 6 4 2 397 5 8 3 gt 397 5 8 4 I m standing at the origin of some xy coordinate system for no reason when a pot of gold dropped onto the point x y I would love to go get that gold but because of some arbitrary constraints or in my case mental derangement I could only move right or up one unit at a time on this coordinate system I d like to find out how many ways I can reach x y from the origin in this fashion because umm my mother asked Write count ways that solves this for me 5 Define a procedure sum of sents that takes in two sentences and outputs a sentence containing the sum of respective elements from both sentences The sentences do not have to be the same size sum of sents 1 2 3 6 3 9 gt 397 5 12 sumofsents 1 2 3 4 5 s 9 gt 9 11 3 4 5 Justin Chen CSGlA Fall 2009 notes courtesy of Chung Wu 3 What in the World is lambda No here lambda is not a chemistry term nor does it refer to a brilliant computer game that spawned an overrated mod lambda in Scheme means quota procedure The syntax lambda formal parameters body of the procedureD So let s use a rather silly example lambda x x x Read a procedure that takes in a single argument x and returns a value that is that argument x multiplied by itself When you type this into Scheme the expression will evaluate to something like closure arglistx 14da38 This is simply how Scheme prints out a procedure Since lambda just gives us a procedure we can use it the way we always use procedures as the first item ofa function call So let s try squaring 3 lambda x w x x 6 Read that carefully and understand what we just did Our statement is a function call whose function is quota procedure that takes in a single argument and returns a value that is that argument multiplied by itself and whose argument is the number 6 Compare with 2 3 in that case Scheme evaluates the first element some procedure and passes in the arguments 2 and 3 In the same way Scheme evaluates the first element of our statement some procedure and passes in the argument 6 A lot ofyou probably recognized the above lambda statement as our beloved square Of course it s rather annoying to have to type that lambda thing every time we want to square something So we can bind it to a name of our desire Oh let sjust be spontaneous and use the name square define square lambda x x x Note the similarities to define pi 3 1415 92 6 Forpi we told Scheme to quotbind to the symbol pi the value of the expression 3 14 15 92 6 which is selfevaluating For square we told Scheme to quotbind to the symbol square the value of the lambda expression which happens to be a procedure The two cases are not so different after all fyou type square into the Scheme prompt it would print out something like this again closure arglistx 14da38 I I As we said before this is how Scheme prints out a procedure Note that this is not an error It s simply what the symbo square evaluates to a procedure It s as natural as typing in pi and getting 3 14 15 92 6 back ifyou ve already defined pi of course It s still a little annoying to type that lambda though so we sugarcoat it a bit with some quotsyntactic sugar to make it easier to read define square x x x Ah now that s what we re used to The two ways of defining square are exactly the same to Scheme the latter isjust easier on the eyes and it s probably the one you re more familiar with Why bother with lambda at all then That is a question we will eventually answer with vengeance QUESTIONS What do the following evaluate to lambda x x 2 1ambda b 10 1311de C C h b 1311de e e 5 5 lambda a a 3 lambda z z 2 Justin Chen CSGlA Fall 2009 notes courtesy of Chung Wu 4 Firstclass Procedures In programming languages something is firstclass if it doesn t chew with its mouth open Also as SICP points out it can be bound to variables passed as arguments to procedures returned as results of procedures and used in data structures Obviously we ve seen that numbers are firstclass we ve been passing them in and out of procedures since the beginning of time which is about last week ago and have been putting them in data structures sentences since the dinosaurs went extinct also last week What is surprising and exceedingly powerful about Scheme is that procedures are also awarded firstclass status That is procedures are treated just like any other values This is one of the more exotic features of LISP compared to say C or Java where passing functions and methods around as arguments require much more work And as you ll see it s also one of the coolest Procedures as Arguments A procedure which takes other procedures as arguments is called a higherorder procedure You ve already seen a few examples in the lecture notes so I won t point them out again let s work on something else instead Suppose we d like to square or double every word in the sentence define square every word sent if empty sent 0 se first sent first sent square every word bf sent define double every word sent if empty sent se 2 first sent double every word bf sent Note that the only thing different about square every Word and double every word isjust what we do to first sent Wouldn t it be nice to generalize procedures of this form into something more convenient When we pass in the sentence couldn t we specify also what we want to do to each word of the sentence To do that we can define a higherorder procedure called every every takes in the procedure you want to apply to each element as an argument and applies it indiscriminately So to write square every Word you can simply do define square every word sent every lambdax x x sentH Now isn t that nice Nicer still the implementation of every is left as a homework exercise You should be feeling all warm and fuzzy now The secret to working with procedures as values is to keep the domain and range of procedures straight Keep careful track of what each procedure is supposed to take in and return and you will be fine Let s try a few QUESTIONS 1 What does this guy evaluate to 1ambda x x x 13 de Y 4 2 What about his new best friend 1ambda y z z y lambda a a 3 5 3 Write a procedure foo that given the call below will evaluate to 10 foo foo foo foo 10 4 Write a procedure bar that given the call below will evaluate to 10 as well bar bar bar 10 bar bar bar Justin Chen CSGlA Fall 2009 notes courtesy of Chung Wu 5 Procedures as Return Values The problem is often write a procedure that given return a procedure that The keywords conveniently boldfaced are that your procedure is supposed to return a procedure This is often done through a call to lambda define my wicked procedure blah lambda x y z Note that the above procedure when called will return a procedure that will take in three arguments That is the common form for such problems of course never rely on these quotcommon forms as they ll just work against you on midtermsl QUESTIONS In lecture you were introduced to the procedure keep which takes in a predicate procedure and a sentence and throws away all words of the sentence that doesn39t satisfy the predicate The code for keep was define keep pred sent cond empty sent pred first sent sentence first sent keep pred bf sent else keep pred bf sent Recall that Brian said to keep numbers less than 6 this wouldn t work keep lt 6 4 5 6 397 8 1 Why doesn t this work 2 Of course this being Berkeley and us being rebels we re going to promptly prove the authority figure the Professor himself wrong And just like some rebels we ll do so by cheating Let s do a simpler version suppose we d like this to do what we intended keep lessthan 6 4 5 6 397 8 Define procedure lessthan to make this legal 3 Now how would we go about making this legal keep lt 6 4 5 6 397 8 Secrets to Success in CSGlA I Ask questions When you encounter something you don t know ask That s what we re here for Though this is not to say you should raise your hand impulsively some usage of the brain first is preferred You re going to see a lot of challenging stuff in this class and you can always come to us for help I Go to office hours Office hours give you time with the professor or TAs by themselves and you ll be able to get some nearly oneonone instruction to clear up confusion You re NOT intruding the professors LIKE to teach and the TAswel the TAs get paid Remember that if you cannot make office hours you can always make separate appointments with us I Do the readings on time There s a reason why they re assigned And it s not because we re evil that s only partially true I Do all the homeworks Their being graded on effort is not a license to screw around We don t give many homework problems but those we do give are challenging timeconsuming but very rewarding as well I Do all the labwork Most of them are simple and take no more than an hour or two after you re used to using emacs and Scheme This is a great time to get acquainted with new material lfyou don t finish work on it at home and come to office hours if you need more guidance I Study in groups Again this class is not trivial you might feel overwhelmed going at it alone Work with someone either on homework on lab or for midterms as long as you don t violate the cheating policyl Justin Chen CSGlA Fall 2009 notes courtesy of Chung Wu 6 8202007 3 Parameter Estimation of Soil Dynamic System CE291F Final Presentation Min Chen 050207 Objectives 3 Dynamic Soil Properties 5 Vertical Array Instrumentation W System Identification Treasure Island Array SIS 0 System Modeling 1D Visco elastic shear wave Propagation Equation I006 624251 3 6uxt2 52xt 1 at 6x 6x 6x axat 0 t d h l 39 Boundary Conditions u 2 own 0 6 senes la uL I uphole series 21 33 Initial Conditions ux0 a 0 3b Estimate Shear Modulus Visco Damping Coef cient Input Out ut Measurements PDE g n p Cost Function min IJ if I W xJ39 drdx Subject to PDE 1 BC2a2b ILC 3a3b Adj 0th Method Find the Optlmlzatlon VJ True value g n 8202007 Adjoint Method 32 a a a 32 m Adjoint PDE we Egx anx 2 Wow ux1rltx x1 q co state a L 0 Boundary Conditions q0l I 0 x Initial Conditions xT 2 6101 0 64x1 0 6 10 0 a 1 at 6x 0 6x2 Gradients a39 J 6g T Z ale m 6 a u d 6x 6x 677 T 6t Bxat 0 Optimization 5 BFGS Method Start I0 initial guess gm l Solve the direct PDE for u with gkmk l Solve the adjoint PDE for q Calculate the gradient VJ Find the search direction MkVJ Update gm kn 9 8202007 quota Numerical Modeling 3 Forward Modeling 1 Assign a known distribution to gX nX Input downhole series MM 7 predict the uphole response m 5 a w jInverse Modeling 1 Give upholedownhole series compute the j 39 parameters Vertical Array Data Lotung Site m I 039 hill I m xquot 0 wl39 l39r i l5J3 quotV v il Y r V 0 w LM ar39y frgvKanri 39lyljquot f aquot39rquotvquottquot 5 a newi lflv flljllgd39llyi lquotLIE 0 quot 39V1V V D r NW r I3Vi lllr fl f AM45 39 lw 1quot 3a 8202007 8202007 Preliminary ReSUIt 1 Forward m V 7 Modeling l l L1 J Y M p ll l I l l i W l u quot lwquot allllll39lllllla will l l39 quotl l l quot ww lltl i l l Mm lr llllLal l l39l igllrl l39rillquotif 39i quotw quotquot squotquotquot ll ill r Preliminary Results 2 Inverse 1 7 w W l Modeling l a 39l l 7 7 7 7 f l i Future Work Compare the Lotung site s csuu mu the existing results Simultaneous estimate px gx and W E Estimate time variant parameters gxt and nxt 8202007


Buy Material

Are you sure you want to buy this material for

25 Karma

Buy Material

BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.


You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

Why people love StudySoup

Steve Martinelli UC Los Angeles

"There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."

Kyle Maynard Purdue

"When you're taking detailed notes and trying to help everyone else out in the class, it really helps you learn and understand the I made $280 on my first study guide!"

Bentley McCaw University of Florida

"I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

Parker Thompson 500 Startups

"It's a great way for students to improve their educational experience and it seemed like a product that everybody wants, so all the people participating are winning."

Become an Elite Notetaker and start selling your notes online!

Refund Policy


All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email


StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here:

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.