 Where's everybody at the printer? This is not funny I still cannot type anything here usually it's like a part in class and part take home The in-class part would be Setting up a problem You know the first first two or three steps Yeah, and or and or solve something. That's simple, you know do it by hand for instance A simple optimization, you know just I need to restart this computer. I know for Let me Start mentioning about this I've gotten a few questions of from from the one of the problems Problem number 15 That asked for was that textile problem That once you set it up for linear programming You run the code and you read off the you know the outputs and The lambda that came out as the shadow prices Wasn't it a little bit weird So does anybody try the simplex method instead and same weird numbers Okay, well, I'll look them Because when I ran what would have been sort of the Obvious choice for the metrics a and the constraint, you know the constraints and B The simple the large-scale method gave Some shadow prices which are Not I mean not not realistic, okay And how can you tell you the shadow prices are not? realistic if you read them from the lambda You know from a lot lambda output of that program I mean, how do you how do you test? Say you didn't have this fancy way of collecting shadow prices from that command Shadow prices would have to be Change the number in the constraint. So it's the sensitivity to the constraint, right change the number in the constraint by one and look at the optimal Value, right and And again, if you do this with a large scale, then you would see that It's not it does it's not consistent, okay With the number that's been collecting through from the Lagrange from the Lagrange multiplier So sometimes again sometimes trying, you know, I guess if something doesn't look reasonable if it if it looks reasonable, that's you know That's that right I mean you make the interpretation and you move forward, right And again at this stage it may not be very clear, you know, what is reasonable and what is not, right? But I would say that trying Maybe two different methods Would be, you know two different methods for this limb probe would be a way or As I said brute force just just make the sensitivity analysis your on your own I should also mention that The implementation of linear programming or any of this methods since simplex or large scale The in MATLAB is you know, it's it's not foolproof so In fact No implementation is like universal at this point if you have a large scale problem like a large number of variables large number of constraints You know the in theory everything should work fine, right? But when you when you ask a computer to do it you run out into these cases where things don't You know certain errors Creep up, you know certain things certain limiting behaviors appear that that you didn't expect right and So it's it's really sort of an active field in fact Just I think a couple of years ago. There's been a Kind of a new algorithm for solving linear and non-linear programming problems, so Developed I think at Stanford that is now being commercialized so various commercial packages implement that that algorithm and Comsole is one of them so so I Don't know what's going on with this but just just to show you that that there are there are I mean It's it's an ongoing process. There's nothing like This is it and now we can use it close our eyes and and not you know just trust trust the computer 100% Please get this started. I might have to live with this Resolution if that's okay. It's really small on my screen. Okay. Well, let's see if it Hopefully I can run some some codes. I posted the code for Well, you've probably seen this dirt problem that we did yesterday last time in class And I posted two more codes here In chapter four, so we're gonna start talking about chapter four dynamic models Okay, so let me Do you like pink or white? We could sell or switch between the two Okay, so. Oh, this is interesting Now I cannot write on the screen Okay, now I can write on the screen, but you cannot see what I'm writing Let's see if there's a steady state here Now you okay, it's either you or me who? Any idea what to do Yeah, so if it's on the screen, then it's a If it's on the screen, then it's it's also on my machine, but I when I write here it appears here So it's not I could use that Yes, please See now you can see I cannot see anything So see how many people had differential equations here? Okay. I wasn't a trick question How many of you had have seen systems of differential equations in your course? Oh, okay So means we can skip chapter four I guess this is six months old. It's pretty old Okay, we can get a new one. Oh iPad. Yeah, that's right Now wait hold don't Okay All right, so it looks like I can at least write on this. All right, so let's talk about dynamic models Or dynamical systems first, okay, so So you've seen differential equations that are of this form where x is Kind of the state variable or it's some something that If you know it at each time Then you know the system they did that this this equation describes Right, so that's why we call a state variable And it's typically a function of time so we can It's like that we track a certain very you know a certain process in time And all this is saying is that this is a rate of change right It's it's a lot that says how the rate of change on this of this variable depends on the current state Okay, and this system is or this equation is understood sort of Well, if you can solve it explicitly, that's great Right, but not always you can solve Even first-order equation explicitly So alternative is to have what's called a direction field, right? excuse me. Yeah, so direction field and and That amounts to doing what so in the xt plane you do For instance, well, let's say it at time zero you can do that time zero for each x For each value of x You draw a direction that has slope equal to what? the right-hand side right So you have the right-hand side So the slope Equals the f at the value x where it's where you plot it where you compute it And again, this slope can change You know, I mean that that means the function is depends on x So this can change with respect to x Could also have x negative here something like that so Okay Now this is what you do when at t equals zero and then you have to do it at all Kind of you have to fill this plane With this directions, which of course you cannot do it by hand. So you just I guess you just illustrate this on On a few and of course with a computer would be much easier to do and What you notice here when you when you do this is that If there is no t in the right-hand side if there's no t dependence in the right-hand side So so the right-hand side only depends on x then at different times T the the slopes are the same so the directions are the same So this is a situation of what's called an autonomous system or an autonomous equation right, so this is right-hand side is Time independent means is an autonomous Equation or system and that is to distinguish between the case when the right-hand side would not be Depending on would be depending on the time. So what's an example of that? So more general You could have dx dt as a function of T and x right in which case what is the It's you have a possibility of the direction to be let's say it's a simple Function like this so it has the slopes are of this but At a different time it will it would look totally different right for the same x a Different time it would look different. Okay, and then another another time it would be again, maybe different Okay, so this would be a case of Autonomous system a non-autonomous system equation in this case right okay, so What do we do this direction field? How does this relate to the solutions of our of our differential equation coming back to first example here if I have a Initial condition so at time zero I know that what x is at time zero Right to solve this system this equation would amount to what amount to do what today? I just cannot write on these computers Okay, but I want to find a Curve that fits this direction field right? so for instance That might be a curve that that Fits direction field at all points right if it starts there, but if it starts here it might actually look Like this right and I look like this and so forth Also Right, so these are different solutions for this differential equation and they correspond typically to different initial conditions right if it is Non-autonomous, you know is the same the same issue except now it's it's going to have to adjust right to Kind of at each time there's going to be some sort of different You know think about it like wind when this changing conditions are changing as time evolves So you could be starting I didn't say you could be starting at one point here and follow a certain Trajectory a certain solution Right if you started this moment of time, but for the same x if you start at A different moment of time, which is let's say here at time zero then you could be doing a totally different Trajectory right so there is actually a fundamental difference between autonomous and non-autonomous systems or Equations and that is when you look at the solutions At the picture of the solution what what do you see? What do you notice right there consistent in the sense that they're translating their translation invariant you take the same picture and You just kind of shift it by a little bit right the direction feel is going to be the same So the solutions will be the same right Whereas here it will look I mean my picture is not great, but If you shift if you kind of translate this in time Then you're going to see a different picture right yeah Well, it's dynamic system because because your variable is time dependent So it's dynamic in the sense that given a national condition It's going to be you know, it's going to be time dependent right individual solutions But it's a time in the autonomous case it basically says that you can start at time zero and follow your dynamics Or you can start at time Ten the same location and you're going to follow the exactly the same dynamics I mean the best way to think is in the airplane you are taking off right you're waiting to be cleared Right, and there's no wind Okay, and you have your everything's pre-programmed Well, it doesn't matter if you start now or you start in two minutes Your trajectory is going to be the same right it's dynamic, but it's going to be the same it's going to be not depending on the Time when you start motion Whereas if there's a wind if there's like a thunderstorm, right if you start now or in two minutes Even though you're you know you're following exactly the same You know Physics physical laws your trajectory will be different. Okay So You can actually Experiment this on your own I I linked here something that's quite powerful called it's a mad love code for interactively kind of plotting this kind of Direction fields it's called the field eight As usually just copy you know Copy and paste it in your in your mad love On your own your local machine And it has four thousand lines of code so you don't want to even look at this But again, it's it's sort of Code developed by a professor in Rice University, and you know he graciously kind of Gave it gave it away, and it's it's it's kind of used throughout You know the best sort of tool for Solving differential equations with mad lab. So here's an example of that X square minus T that's not Great example, but I mean it's not a function. It's not a differential equation that you might Want to solve anyway? On paper, but here's here's here's a here's a time equal zero and X is I don't know between negative two and two and this is how the direction feel looks like Okay, if you can see it, but So I'm not I'm not talking about how mad love actually feeds this curve But that's basically how it solves that differential equation With this initial condition right X equals zero at time equals zero, right? And it you saw that it solves also backward in time, which Okay Which you can do So that's that's one trajectory right, but now imagine now look at if I start at the same X equals zero about a different time Right it looks different right I Mean it has sort of and you can do this I mean With a bunch of points in fact it's not that I mean I'm just I'm just hitting X equals zero a different time so you can see that it's it's it's not autonomous, right? But the best way is to kind of to see this Fix you know fix a time zero and take different initial conditions It's actually even more dramatic to see what that There's kind of a value here for X Below and above which the the dynamics is dramatically different, right? Okay, so you cannot really do this by hand I believe You cannot solve it explicitly by hand But be my guest to try it out anyway X X five equals X square minus T Doesn't look that Bad, but it is not you know you cannot solve it by hand let me Let me switch to something that we're going to be using quite a bit called a logistic equation and It's using P rather than X, but that doesn't matter And then he has a coefficient times the right-hand side is our X times 1 minus X over K or P And if you proceed with this This is the direction field that you're gonna get oh and by the way, this is not That great because it doesn't show the whole picture, so let me let me do What do I want to do I want to do some negative negative 5 to 15, okay? All right, so now Let's identify what T equals 0 is so this is what T equals 0. All right, so now you can see An autonomous system this is autonomous because there is no T dependence in the right-hand side Okay, and again, what's that feature and the in the You know in this direction field phase portrait it's translation invariant right so it's Now individual to individual trajectories are not constant right you start you start somewhere here and With time as time evolves you kind of reach a certain You know you do something right so as dynamic but again If you start at a later time at the same point it's going to be doing the same thing with that delay time time delay, okay? All right, so it's a kind of a great little tool It won't solve the differential equations Exactly So If you need more than just the picture or the behavior then you might need to solve those equations exactly so Let's start with a logistic equation. So this is dx dt equals well, let's just Do it really simple x times one minus x? Okay, so if nobody told you when you started this first time, you know, this is a kind of a simplest type of first-order od that you you were asked to solve in in in your introductory course, right? But if nobody told you that you know, there is a direction field. There's a picture that you can relate this to Then there was probably a mistake because the picture is very kind of suggestive so think about the right-hand side so the right-hand side is a quadratic Equation in x right so I want to I want to plot these directions according to The values of this quadratic function, right now the this quadratic functions function if I were to plot the right-hand side Versus x would be a problem of pointing downwards, right? and With x intercept at zero and one Okay, so this is and what do I take out of this? You know this information Can I help? Can it can that help? Figure out the direction field. I guess by hand Well when x is zero regardless of what t is What is the right-hand side when x is zero zero, right? So so this means the direction at x equals zero is zero and I can do it You know at several points Again, it's independent of t it's the same thing at oh at x equals one right The direction field is Gonna be zero. I mean the directions are gonna be horizontal, right? What happens in between like if x is in between zero and one the right-hand side is positive, right? And you can see it's it's the maximum pause. It's It's positive. What's the maximum here is I think it's a quarter So right when x is a half a half times a half is a quarter And that's the maximum it can actually be so the slope the steepest slope is a quarter in Slope, I don't know what that angle means but let's say it's like this, right? Okay, and finally Well an intermediate are kind of smaller right and smaller. I mean less deep less steep and again less deep above You can see how inefficient it is to do By hand obviously Also, when it's when you're above one what happens with the slope it's actually gonna be Negative because that's where the right-hand side is when x is greater than one is negative, right? so Sometimes we put this pluses and minuses to indicate the sign of the right-hand side Right whether you have increasing or decreasing and then decreasing below zero again And by the way, this is kind of steeper and steeper as you go below, right? so the question is Can we actually well we can fit this with a computer we can fit the solution Curve and you saw it, right? You saw it on a computer, but the question is can you? You know is there something? Explicit you can say so for instance effects starts here. I don't know at one point It's clear that it's gonna go up, right? But how do you know it's going up all the way? I mean where is it stopping? Well, obviously you won't be able to go above one because above one things are The trend is to go down, right? but How do you know that you know so how do you know maybe I should start with this if you start with one well Because the slope is zero right Horizontal line fits that direction field Yeah, so in other words the function x equals constant one solves this differential equation, right? x equals one makes this zero and Being constant makes the derivative zero Right the same with x equals zero So these are called the steady states, right? So the steady states or equilibria solutions x star, right? Such that or our points. Let me say our points such that x is Constant x star is a solution. Okay, and that means That the right hand side at x star must vanish right since the derivative of a constant in Time is zero right, so in our case The right hand side is x times one minus x. It's nice because it's it's Factored so you could get x equals zero or x equals one, okay? So these are the steady states meaning that a solution starting at that value stays stays for all times at that value, right? So this is going to be kind of one thing that we're going to be looking at is is When you have a system and not just one equation, but a system of equations It's to identify where are the part where are the possible steady states? and then What happens with the solutions that don't start at a steady state? So as I was saying before if you start let's say at a point this this point x Obviously the trend is that is going to be Increasing, but how is it going to be increasing? Where is it going to be going to eventually and so forth? Okay? Can you trust the computer always and the answer is no if you've seen it repeatedly today? But where is it going right? How high does it does this value go? Okay, now of course from the computer from that Did I show that? Yeah, so from here, it's clear that This is this is that equation, but with the different constants so take R to be By the way in this code you can change This are the parameters right? So if I change R and K to 1 then and then I have to change this The window so I can see it right so how how do we know that it actually goes towards one? Well, there's no Well, there are ways to see this but at this point for the logistic equation we know how to solve it exactly Okay, so analytic solution or Exact solution Can be found Because this this equation is what's called kind of equation is this if you have to solve it by hand separable right so So you separate the variables This is separable and Then you integrate right so into you have to integrate This rational function 1 over x times 1 minus x and It's not Too hard To do it by partial fraction right but in case you forgot that partial fraction decomposition Then this is how it would look like right Then how do you find the constants a and b right so? you could Do the standard way and just you know find the common denominator and then identify the coefficients get a system of equations, right? But how I like to say it is is you just solve visually You kind of cook up those those those Cough those constants now That's not a way to you know teach how to do partial fractions, but If if somebody faces you and says isn't that clear that a and well a is one and B is one Satisfies this well again it takes some Common denominator, but you can see it That numerator it becomes exactly what you need which is one right so Now how you do this as I said you have to do it through you know if it's not obvious you have to do it through the methods that That you know But I'm just going to use this so right now. It's going to be 1 over x plus 1 over 1 minus x dx Equals integral of dt is just t plus a constant. So this is natural log of x Minus natural log of 1 minus x in absolute values t plus c so so you've actually solved Right you've integrated this equation because now there's no more integrals And now if you if you can do if you can find x that's great and we can but You probably remember how few well There aren't many examples where you can actually Proceed with this computation until you find x explicitly so so let's see what what is a You exponentiate both sides right so you get x one minus x is a constant e to the t Where C is could be positive or negative right? Or even zero or even infinite so the first thing here to notice is That this computation doesn't quite make sense if x is one right, but if x is not one then you can do this and Now you can solve For x makes it a linear equation. So it's x 1 plus c e to the t as c e to the t so finally x is C e to the t over 1 plus c e to the t Okay, and what is this? C is any real number and of course or There's also the solution with x is as I said equals one Right that was kind of lost in this computation But this is a general solution of that of that logistic equation. Is that right? so now Well x cannot equal one in this form But x equals one is a solution as we saw before so because we lost it We assume the x is not one so we can divide by one minus x Then it doesn't mean that x wasn't could not be equal to one right? So that that's why you have x equals one as a edit, but this is You know like if you start with a half Right one can find the constant so that this thing is at time zero so Given initial condition x at zero is x naught You can find the constant right so you get x Not is C over one plus C Yep, so you can find the constant C to be What do you get C is x naught plus x naught C? So C is x naught over One minus x naught right okay, so for instance, let's think about We're talking about what happens with solutions That start in between zero and one like started one half right if x naught is a half what is C There's a half over a half. That's one Right, so what is x as a function of t is e to a t over one plus e to a t Yep, so that the graph that you saw there for x equals a half starting with x equals a half I think you can clear these There's a way to clear all of this clear figure I clear the whole figure There's a way to just clear the the solutions only okay, so So again if you are to Between I said one half so this is the point where I want to start and this is the solution right Well, this solution is exactly that function Or there's the graph of that function right how can you see this well as Well one thing is to plot this function, but The the key thing was as t goes to infinity where is this thing going? Okay, so you can see it's going to in this case to one right I mean one way to see this is is to Divide by e to a negative t so e to a negative t plus one right and You know that e to negative t goes to zero as t goes to infinity So that's why the limit is one right and again you can do this for also for in general so in general So for general x not we said x of t as c e to a t over One plus c e to a t so that's the same as one over one over c plus Excuse me one over c e to the minus t plus one And what was one over c? Well, c was x not over one minus x. This is one over x one minus x not over x not Right so you can see the solution You can rewrite the solution as one over see one plus One minus x not over x not e to the minus t so now what do you? What do you conclude if x not is Well if x not is zero this this is not not a good way of representing right but if x not is zero the solution We know it's zero if x not is between zero and one this quantity is positive So this thing goes to One over one which is one right if x not is above one This would be negative, but this is still going to zero right so all the solutions Actually eventually go to That value one right The only thing that's concerning Some concern is what if x is negative x not is negative. Yeah, yeah, true You see the graph shows you know see everything goes to one Unless you're starting below zero in which case you go to negative infinity right so Can we see it that this goes to negative infinity this thing should go to zero Which means this thing should go to Negative one And I'm not seeing that but okay. Well, anyway, I mean the point is this is an explicit solution That tells you you know given the initial condition. That's what x is gonna be At x is given x zero. This is why the solution will look as a function of t right It should be It should be obvious, but I don't see it right now that it goes to negative infinity. Okay, when x is not this is negative all right, so Again, what I'm saying here is this is kind of a rare case That he can solve explicitly The equation right and then he can match with it with a picture okay, so This is what happens when you have one one variable one one state variable You can actually relate a dynamical system or the dynamics the equation describing that with With a with a with a direction field and you can analyze, you know what happens as time evolves You can you can identify what are the steady states and so forth But certainly one day is not enough so You could have two-dimensional or several dimensional ones and the Easiest example is Is what's called a pendulum non-linear pendulum in which in which? So the system that you're describing is actually you know plain old Pendulum that's fixed at one end and it's it's kind of oscillating in the other end right and the Newton's law, you know if you have some friction Newton's law of motion the acceleration is related to the forces So assuming this has some mass Well ends up being like a second order equation like that right and it's a non-linear Because of this term okay, so how do you? Solve how do you try to solve this system? I mean it's a it's a second order equation right, but actually it doesn't have an exact solution You cannot write theta is this function of t Okay, if you didn't have these terms if you didn't have the sign if you had something Like a theta just instead of sin theta then you could solve for for theta But because it's non-linear you cannot solve it so The the typical way to study this system is or this this physical system is to convert a second-order equation to a first-order system and There there's not a unique way in general to do this but One standard one is a standard one is to call the derivative of the variable Theta to be you know the new variable a second variable, so that would be the momentum and then Write the The rate of change or the derivative of the moment of the second variable in terms of both variables, right? so this is just of course, this is just the Second rate of a theta so it's minus sign That up minus K Omega, right? Right, so now you see a basically a system of two equations Which brings the question of how do you study systems? I mean is there something related to? similar to the case of one dimensions and The answer is yes, but it is going to be a little bit more complicated So I'm gonna I mean I give you that example. I can show you the picture that comes out of this system, but This is what it boils down to I have now a differential a system of differential equations where X is You know, let's say it has two variables doesn't have to be even more Start with the two two variables X X one X two and F could be F1 F2 Right, so literally I'm looking I'm looking at D X1 Equals F1 and DX2 equals X2 F F2 yeah, and the question is If if there is such a system, how do we study it? Well, there is Think about it as a similar concept as it was for the one dimensional a direction field But this time I have to take into account that The X1 X2 are Interconnected so this the solution so the solution Will be X of t which is X1 of t and X2 of t okay think about Plotting this Well to plot it you need basically the X1 X2 plane versus T right so You imagine that I have a solution that starts at time zero at this point Okay, and again, we're gonna consider it to be Autonomous, so it doesn't really matter So we just always gonna start our things at time equals zero. That's the advantage of autonomous systems Okay, and then this is gonna have to fit some sort of a direction curve right a Direction field, excuse me So at each point At each at each moment of time. This is gonna have some Well, I don't want to call them slopes, but there's gonna have a direction right There's gonna be a slope in the x1 direction a slope in the x2 direction, but Imagine what happens in the in the? In the XD in the X1 X2 plane Well, this is over this is in time right by the projection sort of with this trajectory is gonna describe some curve in the X1 X2 plane all right, so that's That's how I would like to understand now how I would like to think about this because Soon we're gonna be run out of a dimension that we can visualize Right if it's if I have three variables, I cannot even do this plot, right? all I'll be able to do is kind of see the trace of the Trajectory in that state state space So that's that's why even into when I have two variables. It's best to think about it as a So focus on instead of this versus time Focus on what's called a phase plane in which case? I'm just looking at the X1 X2 and Now I can talk about directions in the X1 X2 plane as being So this is gonna be DX1 Dt equals f1 and DX2 Dt is f2 so So at each point I'm gonna have to plot this Direction field again, but it keep in mind that it's different than than the one where I have one variable and time Okay, so for that Let me show you this There is another code called P plane Which again has thousands of lines of code. So you just Want to copy and paste Save it here. I think we can just quit this Okay, so here's an example. I'm gonna take the pendulum here and you probably don't like this, but it says theta omega omega theta and so forth and The first thing that's gonna do is gonna plot this Direction field in the phase plane Now take a look at this. Okay, so what are these errors? These errors are no longer slopes of I Mean, they're not slopes of the of the solution, right? so we stop talking about slopes of of the actual of the actual Directions But instead at each point So it's saying that if the solution were to hit this point, you'd have to follow this direction, right? And so forth, right? So again, you ask the computer to find sort of Given an initial condition find that The trace of the solution, right? So this is not I mean you don't really see the solution here as As a function of time Right, if you if you were to plot this as a function of time you'd have to start there and then do this If time is going this way, right? Instead you just see the state at as time evolves like the states that have been that been visited right and Of course this this arrow is also indicate like in which direction it actually is is described that that trajectory, right or orbit now This is the pendulum. So this is all this is saying is that it's Different initial conditions correspond to different trajectories, right and Because it's non-linear You get all kinds of interesting behaviors You can also get this What appears to be a repetition in theta, but The fact that it kind of repeats itself This has nothing to do with anything except that theta is an angle. So once it passes to pi So this is zero and then this is To pi right so in a way in a way the face Porter just should stop Like between negative pi and pi right depends on how you measure the the Okay, and then you just draw conclusions now. What's one thing that needs to be? Where do you start this analysis? Well, of course if you have such a tool and you draw a nice picture It's not it's not enough, right? so One thing to do is to say find a steady state or an equilibrium point and Guess what the computer will find Lots of things lots of information about this equilibrium point and we're gonna talk about a lot of these things But this is just that I zero and omega is zero meaning the pendulum is sitting Straight down right and with no initial momentum But this is not the only one. There is another critical part. There's another equilibrium which is when That I spy so this is it sits Like on top again with no moment. No initial momentum Right, and I think this is the only two and then then they keep repeating by a period of two pi And so so that's kind of the one of the tools, but certainly One has to talk about and we're going to talk about this Start talking about steady states steady states Or a equilibrium and Go from there. I think I've posted the next homework assignment, so I'll ask you to go through the first example in the In the chapter four four point one I don't have a code for that because it's not anything that you should code. It's basically just Illustrating the steady states for a System of two equations with two unknowns Okay, a concrete it well a more concrete example, and we're going to go through this on Monday, but you can have a head start and Then we're going to go and talk about the actual codes You know for not just steady state, but time dependent Dynamics Okay, thank you