nm0765: er so where we were last time is we had er written down a likelihood that we wanted to maximize and then we'd written down the first order condition so let's write remember the likelihood the likelihood went like er the Lagrangian sorry went like this that was the flow element of it and er there we had this extra stuff that came from the end conditions now we realized that this Lagrangian didn't contain terms in the X-prime term so this was a separable maximization and all we needed to do to maximize this lagra-, Lagrangian was to differentiate it at each time into T and set those derivatives equal to zero and if we did that what we got from in here was D-F- by-D-X plus lambda-D-G- by-D-X is equal to minus-lambda-prime at all times little-T okay and that's just differentiating this expression with respect to X so that it's maximizing this term in the integral at each time little-T with respect to X and the other condition we had was D-F-by-D-U plus lambda-D-G- by-D-U was equal to zero at all times little-T and that was again differentiating this point thing in the integral here with respect to U at all times little-T so we're maximizing this with respect to U now these two conditions have a special name they're called the Hamiltonian conditions and er the reason they're called the Hamiltonian conditions a-, are apart from being named after a man called Hamilton is that they er sta-, are basically derivatives of the function F plus lambda times G with respect to X here and with respect to U here so we think of the function H which is F plus lambda times G as the thing that's being differentiated on the left-hand side now so these are like first order conditions if we wanted to maximize something we'd take these first order conditions and solve them but there's other things here that we also need to worry about the other things here that we need to worry about come from differentiating this Lagrangian at the terminal time you see X at time T appears here then it appears here so if we differentiate the Lagrangian with respect to X at time T we don't get an expression like this or an expression like this we get mu minus lambda at T and that's actually written right at the bottom of of page two of your notes now and this has got to equal zero now where did this bit of the Lagrangian come from this bit of the Lagrangian came from the terminal constraint by our state variable we had a ke-, terminal constraint which said that X at time T had to be greater than or equal to some number X-nought and this lambda at time T and this mu at time T are two Lagrange multipliers for X at time T mu is the Lagrange multiplier that applies this constraint lambda at T is the costate variable so this condition here gives you a link between the two so i think probably the best thing to do now is to use these conditions to solve a particular problem so let's forget this stuff the stuff up there and use the first order conditions to solve a particular problem so you can see how they work in practice so what i'm going to do is i'm going to take this stuff and put it up there and then i'm going to solve the problem over here and you'll be able to see how they relate one to the other so first of all i've got to be able to rub the blackboard off excuse me right so let's get rid of that and get rid of that and we can get rid of that too we'll leave the rest up now the example i give you is on page three of the notes and the example is one of a a consumer trying to maximize their lifetime's utility so what's the problem the the problem we face is for a consumer who lives from time period zero up to time period capital titl-, capital-T whose utility is the logarithm of their consumption level at time T and er they want to maximize this by choosing a path of consumption and their their ability to do this is constrained in certain ways well they start off their lives with er a level of saving say er ooh now they've got to have some positive saving so let's call it some level S-zero and er they also have a constraint on their the way in which saving changes through time so saving changes through time that's we look at the derivative of S at T saving's going to go up if we get income from our current stock of saving so this is the rate of interest on our current stock of saving and saving's going to go down if we eat some of our saving right so we're going to maximize our lifetime's utility given we start off with this fixed level of saving given saving evolves in this way and the final condition we have to have is we have to have we die not owning money right right so this is a maximization problem how are we going to apply these conditions to this maximization problem well what we want to do is we want to think about what is a function F what is our function G here so let's do that first of all F at time T er it's an F let's just call it F is a logarithm of your consumptions at time T G in this particular case it's the stuff here whatever that is in this case it's R of S-T minus C of T and that's it so these this is the thing you want to maximize this is the thing on the other side of the savings equation this is how savings change through time G was the constraint on the rate of change in savings clear clear sf0766: mm nm0765: jolly good so er how are you going to do this well let's do it in two stages first of all let's write down a Hamiltonian for this problem so it's the logarithm of C plus lambda times R of S minus C that's the er G bit that's the F bit now these conditions tell us how to solve the problem now first of all we have to do D-H- by- D-X now at where X is the state variable okay so let's pick someone namex what's the state variable in this problem what's the okay what's the thing we can't choose sf0767: consumption [laughter] saving nm0765: really sf0767: and stuff nm0765: really consumption's the thing we're choosing for C for control sf0767: it's probably saving nm0765: okay S for state very good so the thing we'd we can't control the state variable is S so in this case the state variable we call saving so you're going to have to do D-H-by-D-S is equal to minus- lambda-prime this one says D-H by the control variable which is consumption is equal to zero and so we need to take these two equations and now i can rub that stuff off and come over here and fill these in in more detail what is H differentiated with respect to S well S isn't here but it's it's just this this is just the C S only appears here in the H equation so D-H- by-D-S is actually lambda times C R sorry and that's got to equal minus-lambda-prime D-H-by-D-C i know you like differentiating logarithms so you've got to differentiate this logarithm with respect to C one-over-C and there's a C term here so we can have minus-lambda and that equals zero yes thanks so we've got these two equations that come from the Hamiltonian condition but we also know one other thing the other thing we know is how saving evolves through time so let's not lose that S-prime of T is equal to R-S minus C we've got three equations now i'm going to rub this off and let's see what we've got well the first thing we have is that we have a differential equation for the costate variable costate variable is comes straight from that the second thing we have is we have a relationship between a costate variable and consumption at time T and the final thing we have is we have a relationship between saving a differential equation for saving and consumption okay so once we've solved these three equations for the path of the costate variable the path of consumption and the path of saving then we will have found the optimal path for consumption in this problem and the consequent optimal path for saving okay there are some constraints we haven't worried about yet where saving starts up where saving finishes we'll bing the bung those in later clear sf0768: i don't understand how the Hamiltonian relates to the Lagrangian nm0765: [sigh] okay let's go back sf0768: sorry sf0768: we had the Lagrangian yes sf0768: mm nm0765: which consisted of F plus what oh dear hang on lambda-G plus some other stuff sf0768: right nm0765: okay and we said we needed to maximize that at each time period little- T sf0768: oh so nm0765: so when we maximize the Lagrangian at each pime time period little-T we're basically maximizing the ham-, Hamiltonian plus some other stuff at each time period little-T sf0768: mm nm0765: so that's how the Hamiltonian comes in it's just basically a way of writing a part of the Lagrangian sf0769: er okay nm0765: is that all right sf0768: so it's not the differential of the Lagrangian then like nm0765: no the derivative of the Hamiltonian is the differential of the Lagrangian sf0768: oh okay nm0765: so we differe-, when we differentiate the Lagrangian we're doing the same thing we're differentiating the Hamiltonian sf0768: so we just forget about all those other bits then Lagrangian nm0765: basically provided you know the differential equation that gives you this the differential equation that gives you that you can forget all that stuff about the Lagrangian if you want if you just want to solve the problem sf0768: okay nm0765: so the only conditions you need to know i've written on for you at the bottom of page two of the notes provided you know that you can solve optimal control problems sf0768: okey-dokey nm0765: okey-dokey now any more questions while i'm at it oh i've got a question for you what's the solution for this differential equation i'm going to choose the back row ha ha ha you haven't got the faintest idea sm0770: solution lambda nm0765: ah nice try suppose i gave you X-prime is equal to R-times-X it's a linear differential equation with R okay a solution to this one is lambda at time T is equal to an arbitrary constant times E-to-the-power-R-T if i differentiate this with respect to R i just get an extra R at the front ah minus-R is that clear [laugh] i'll take it slower [laughter] i've got to rub off the problem 'cause we need all that stuff so we now have these three equations in these three unknowns lambda-T we don't know consumption we don't know savings we don't know we've got differential equation here in lambda it's a very simple differential equation it's a differential equation that appeared on right on the front of your notes on differential equations it's a one variable linear differential equation if you just took those notes on differential equations and plugged everything in you would find that the solution was lambda at time T some arbitrary constant times E-to-the-minus-R-T you can check that because if we do differentiate lambda at time T you get minus-R-K E-to-the-minus-R-T right which is the same thing as minus-R times lambda-T yeah brilliant so the solution to this equation now i can write it down is lambda at time T is equal to an arbitrary constant times E-to-the-minus-R-T so we know what lambda is and because we know what lambda is we know what consumption is let's get rid of that consumption is one-over- lambda at time T from this equation and one-over-lambda at time T is er one-over-K E-to-the-R-T so what's happening to the optimal path of consumption in this problem well it's growing exponentially fast at the rate E-to-the-R-T we've solved we've learned something we don't know where what this arbitrary constant is but we know the general pattern of the path of consumption what about savings well the cha-, rate in change of savings is equal to R-S minus consumption which is minus- er - one-over-K E-to-the-R-T so now we have a differential equation for savings at time T which we need to solve so do i solve it i've just told you what the solution is how are we going to do it well we're going to do it in two stages we'll do it S-prime minus R-S is equal to minus- one-over-K E-to-the-R-T and then we multiply through by E-to-the-minus-R-T so we get S-prime E-to-the-minus-R-T minus R E-to-the-minus-R-T S is equal to minus-one-over-K and then we notice that this term here is the derivative of S times E-to-the-minus-R-T just applying the prod-, product rule so if i differentiate S with respect to T and hold the E-to-the-minus-R-T term constant i get this bit if i di-, differenti-, hold the S constant and differentiate E- to-the-minus-R-T with respect to T i get minus-R E-to-the-minus-R-T here and then the S which i'm holding constant right just from the product rule do you believe me sf0771: yeah [laughter] nm0765: do you un-, that's another que-, do you understand sf0771: yes i think nm0765: [laugh] i can do it again sf0771: yeah just do the last two lines nm0765: okay from this bit to this bit sf0771: yeah nm0765: okay i said to you the problem differentiate this with respect to T what are you going to do well first of all you'll differentiate S with respect to T and hold this bit constant if you did that you'd get S-prime E-to-the-minus-R-T then you'd hold the S bit constant and you'd differentiate this bit so you'd get minus-R E-to- the-minus-R-T from differentiating this stuff and then the S that you're holding constant brilliant sf0772: yeah nm0765: right so we know the differe-, differential of this with respect to T is this so to solve for S oh er you're not going to like that i'd better come back over here so for S we say write S E-to-the-minus-R-T is equal to T-over-K plus another arbitrary constant which we'll call C or minus-T-over-K just integrating both sides we integrate this we get minus-one-over-K times T plus another arbitrary constant so finally we know the path of saving which is E-to-the-minus-R-T times T-over-K with a minus there plus another arbitrary constant er E-to-the-minus-R-T no we don't that's a minus-R-T so these are pluses okay so what have we done we've taken the differential equation for lambda and solved it that allowed us to find what consumption was and then we plugged in the what we knew for consumption into the differential equation for saving and solved that so to sum up we've got lambda at time T is from here an arbitrary constant times E-to-the-minus-R-T s-, consumption at time T is the same arbitrary constant one-over-it times E-to- the-plus-R-T so consumption is growing at the rate exponentially at the rate T and we've got saving at time T finally from up here which is doing something funny it's growing at the rate E- to-the-R-T from this bit then we have to knock off K oh sorry knock off T-over- K times E-to-the-R-T here so it's not clear what saving's doing but if consumption's growing i guess saving's got to grow so we've solved our problem we took the problem of finding the optimal path for capit-, good consumption wrote down the Hamiltonian conditions which gave us this equation and this equation and we got er this equation from the constraint solved them and we had to solve some differential equations to do that but it's not surprising you have to solve differential equations 'cause differential equations are equations which have functions as solutions paths as solutions and we're trying to find paths aren't we we're trying to find a path for consumption and this is what we get right any questions sf0768: yeah i lost the second when you went from that side of the board over here nm0765: this side sf0768: yeah nm0765: to this side sf0768: mm what happened there nm0765: what happened there i integrated both sides sf0768: oh okay nm0765: so if the derivative of this is a constant if anything has a constant derivative sf0768: mm nm0765: then the actual thing has got to be a linear function sf0768: right nm0765: so this is a has a k-, constant derivative so when i integrate it up it's got to have K it's got to be linear in T sf0768: okay sf0772: is that C consumption or a constant nm0765: if i it's a constant sf0768: mm okay nm0765: so if i do it backwards let's do it backwards if i took that and then i differentiated both sides with respect to T what am i going to get if i differentiate this with respect to T sf0768: nm0765: i'm going to get minus-one-over-K which i've got here minus-one-over-K here i've got just that differentiated with respect to T sf0768: mm-hmm nm0765: so you're happy that that's the same as that it sorry this stuff is the same as this stuff sf0768: mm-hmm nm0765: so let's just rub out the the brackets oh i'd better write it out again S E-to-the-minus-R-T minus-one-over- K T plus an arbitrary constant it's a big C not a little C in the notes it's it's clear that it's a big C right but we haven't done anything because this solution that we've written up here oh dear right this solution that we've written up here has these arbitrary constants and how and we got two arbitrary constants we got this K and now we've got this C as well this big C here how are we going to solve them well we know two things we know what the initial level of saving was it's some number S-nought that's what you start your life with you know something else as well you know that you can't end your life with zero saving so we know that S at time capital-T has got to be greater than or equal to nought that gives us a different a condition a la-, Lagrangian which says that lambda at time T times S at time T minus zero has got to be greater than or equal to zero oh sorry it's got to equal zero we know that S this has got to be positive we know that's got to be positive so we can use this condition and this condition to tie down the arbitrary constants basically what we're going to get is going to get S at time zero is equal to S-nought S at time T well right so before we go on any questions yeah sm0773: where was that er multiplier you put down on top of the nm0765: this one sm0773: er that's right nm0765: that came from the f-, last things i wrote down right before i rubbed off the er Lagrangian the Lagrangian on page two of your notes if you look right down at the bottom you'll see what i wrote on the board the very last line mu is equal to lambda at time T nu times ek-, ma-, times X at time T-minus- X-nought oh that's a is equal to zero so this statement here was the last thing i wrote down before is equivalent to mu times X at time T- minus-X-nought equals zero it's equivalent to that thing okay we're going to deal with these terminal conditions in greater depth now so let's move on nm0765: we've always talked about the constraint at the end as being you can't die owe-, owning money you can't die with negative savings but we talked about other sorts of terminal constraints that you might have when you're doing these optimizations we talked about steering a rocket to the moon and the terminal condition there was you ended up at the moon another sort of terminal condition you might have is you comes up when you er fill the bath when you fill the bath you have a an absolute level that you want the bath to fill to so you know the bath is full once the state variable has hit this particular level final sort of terminal condition you might come across would occur if you owned a machine or a factory or something like that actually this isn't the final one there's another one and the terminal condition there is when do you quit when do you decide enough is enough and you want to leave the factory so that will be a terminal condition req-, required you to decide when to stop doing something another ker-, terminal condition would arise if once you die or once your machine is dead [laughter] om0774: it's okay nm0765: [laughter] i'm ruining your equipment [laughter] once your machine is dead er you get a certain value from it so er suppose we looked at an investment problem and you had to plan your production for your firm so you had to choose the path of production and then decide when to scrap your machine but once the machine and your investment and your plant were scrapped you could take it and sell it to somebody so the amount which you could sell this stuff to at the end of the machine's life would determine when you wanted to stop okay so there are lots and lots of different sorts of ways in which the end point might affect what you wanted to do it with your problem so let's look at some of them now er so we're actually on page four of your notes so first of all let's study the situation where you have a finite time of shall we say death capital-T and what sorts of constraints might you face when you die well the easiest would be none what that means is that when you die there is no constraint on the your final position your final value of the state variable so none I-E X at time capital-T is unconstrained if X at time capital-T is unconstrained what would you expect the Lagrange multiplier associated with X at time T capital-T to b-, take well we'd expect a Lagrange multiplier was zero i-, if if something is unconstrained it has a zero Lagrange multiplier and that's exactly the condition if you have a problem where you don't care about w-, where you end up then it must be the case that your costate variable takes a zero value at the end of your life second sort of constraint you might have you might have a a precise constraint like the filling of the bath which says that once the bath is full it has to have a certain amount of water in it and that's it there is no discussion in that case lambda at time capital-T is completely unrestricted and we saw that sort of constraint coming in when we did er standard constraint optimization when we did standard constraint optimizations equality constraints meant lambda- T could take positive values negative values we couldn't necessarily say that Lagrange multiplier will be positive or negative when we had equality constraints and the same comes through here final condition which we've seen before X at time T has got to be greater than some number so that means you can't die owe-, owning money for example and the constraint there i've given you is that er that looks wrong to me no lambda at time T times X at time T minus X-T equals zero which it so that says either the costate variable is zero so this constraint isn't binding and it's like X at time T is entirely free or X at time T equals X-subscript- capital-T so the constraint does bind and then lambda at time T can be any value so this is a a way of writing this statement and this statement in some sort of composite form okay so that's w-, these conditions have a prop-, a name they're called transversality conditions transversality conditions are conditions that arise from the what goes on at the end of a life problem end of the life of a problem condition and they're very useful information not in solving for the path usually but they're useful information in solving for these arbitrary constants nm0765: right now that's er transversality conditions when we have a finite time horizon but lots of economic problems we don't want to have finite time horizons we want to allow consumers to live forever firms to live forever we want to allow countries and planning problems to go on forever and in problems like that we need a different set of transversality conditions so let's look at er infinite horizon problems now infinite horizon problems we really want to say the same things as these but for the case where the capital-T is infinite so if there's no constraint what we want is then to the limit as T tends to infinity of the costate variable of time capital-T is zero so instead of it being zero at time t-, capital-T we have it going to zero as we go off to infinity if we wanted a constraint which said that in the limit X at time T equals some number let's call it X-infinity so as T wen-, goes to infinity the state variable gets closer and closer to this number X-infinity then the equivalent transversality condition this one over here is just er well let's see lim- T tends to infinity lambda at time T is unrestricted and the final one again just rewriting that do you think for T tending to infinity is the lim-T tends to infinity X at time T is greater than or equal to some number X let's call it X-subscript-infinity what we require is that the limit as the capital-T tends to infinity lambda-T times X-T minus X-infinity equals zero and all that's written in your notes and all this is the same as all that just letting capital-T go off places right so we've dealt with three sorts of end point restrictions that you might actually have in the your problems and these three sorts of end point restrictions just come from the Lagrange multiplier nature of the problem and we've done them in two cases we've done them where we in finite time horizons we've done them for infinite time horizons but there are other sorts of end point constraints that we talked about so let's look at one of them now now let's think of the machine problem the machine problem what you have is you have a finite time horizon with a pay-off which depends upon the time the states and the control and then you get some pay-off from what happens at the end of your life so we have er a function phi here which depends upon where you end up so you can think of it as like being a prize or a reward or something so if you get big Xs here maybe this number's good if you get small Xs here maybe this number's bad but it's what the stock of assets of you own at the end of your life are actually worth to you in this problem now if we wanted to maximize this object we'd need to take account of the fact that where we end up has effects on what pay-off we're going to get from this problem so what is the relevant terminal condition in this problem well the relevant terminal condition is that lambda at time T is equal to the derivative of this function evaluated at X at time T so what does this say well suppose for some reason i was able to give you one more unit of final income one more unit of it how much more pay-off are you going to get well your pay-off is going to go up and find out it's close to this derivative so this says that lambda at time T has got to be equal to the marginal value to you of extra income at time T okay so this yeah that's what it says so you can think about this lambda at time T as being the value of extra X at time T nm0765: so we've been talking about these costate variables a lot we've talked about how we choose these costate variables and different constraints and how they affect the terminal value of these ker-, costate variables but i haven't really told you yet what these costate variables mean what they actually indicate so let's think about that lambda-T is the costate variable what is it well we know that it's a Lagrange multiplier and we know that Lagrange multipliers in some sense measure the cost of a constraint right when we look at straight consumer optimization problems the Lagrange multiplier there represents the marginal utility of mon-, money the Lagrange multiplier represents how much it costs the consumer to be constrained in its income if you could give the consumer more income the constraint would be weaker and the Lagrange multiplier measures that this is a Lagrange multiplier for a different sort of constraint it's essentially the Lagrange multiplier for the constraint that says X-prime of T is G-T- X-U right this is the constraint that relates X today to values of X tomorrow so what does this Lagrange multiplier measure well it measures the cost of this constraint how much having X linked in this way to today and tomorrow costs you as an optimizer now that doesn't seem particularly transparent until you write it in a different way lambda at time T measures the cost or benefit of a small increase in X at time T on on the solution to a an sorry optimal control problem so for some reason so what does lambda-T measure in an example think about er think about the problem of sending your rocket to the moon lambda at time T essentially measures maybe the costs associated with your fuel at time T so i s-, you're sending your your rocket to the moon and somehow someone comes along to you and says halfway to the moon i can give you another gallon of petrol how much is that worth to you well that's what lambda at time T measures the m-, the value to you somewhere along your problem of an extra unit of your state variable an extra unit of petrol an extra mile gone clear sf0768: what does lambda-T measure in your consumption problem nm0765: okay so it measures your money because what's the constraint in your consumption problem the constraint in your consumption problem was S-prime is equal to R-S-minus-C right so i can going to give you an extra unit's saving somewhere along the line so it measures the margin of utility of money to you sf0768: mm-hmm nm0765: yeah sf0768: mm-hmm nm0765: but it doesn't measure the marginal utility of money at any old point of time lambda at T repre-, represents the marginal utility of money to you at time T yeah fine er i can't think of a i can't think of a bath one but it would measure something like an extra egg cup full of water somewhere along the lay or er yeah er i think i've covered all the examples i understand if you can think of another one i'll have a go at it i've got another piece okay so we've done that let's say more about these costate variables nm0765: consider a problem with discounting now this is a some-, something that lots of mathematicians don't really understand but er let let's er we as economists do right this is a problem where we have a flow of utility from consumption at each point in time but this effect on our lifetime's income is discounted by the amount E-to-the-minus-R-T so one unit of consumption you to you at time zero is worth a lot le-, more to you than one unit of consumption at time capital-T because you're impatient and so this E-to-the-minus-R-T makes future consumption worth less to you than current consumption right fine so lambda at time T we've already talked about thanks to er namex measures the additional value to you of an extra unit of income at time T right so this is value to you of extra income at time little-T but that's not actually what you're interested in because you're now in period zero trying to decide what you're going to do for the whole of your life and lambda at time T measures how you feel about an extra unit of income at time little-T given you're currently at time zero so you might ask me the question you might if i gave how about my feeling about this extra unit of income at time T rather than at time little-zero well we define this thing called M at T to be E-to-the-power-R-T times lambda-T and what does that do well it scales up the the value of to you of income at time T by the discount factor E-to-the-R-T so it undoes the effect of the discounting and says to you oh let's let's let's step back what it does is says to you okay an extra unit of income to you at time T is worth this much to you at time zero to work out how much it's worth to you at time T we have to scale it up again 'cause when you get to time T the time T now is the present and so you have to undo the effect of the discounting so this thing here is called the the current marginal valuation now this thing here is going to be jolly useful for us in solving economic optimal control problems because in economic optimal control problems we often find that we have discounting so it's often okay it's often useful to eliminate the costate variable lambda at time T and replace it with M at time T the current marginal valuation so it's time for an example of that and we'll do that next time