 Let's see, we've kind of had quite a long excursion in this topic of optimizing and then optimizing just functions, optimization problems, then we talked about dynamical systems, right? And we've used all along, you know, the computer for helping us. Lately, we have developed some kind of merge between the two. So we optimize certain things in a dynamical system. So I want to go back and talk a little bit more about pretty much simulation of the dynamical systems that we talked about, a continuous and discrete. But as you'll see, even the continuous dynamical system that we're going to be, we've been talking about when you ask it on a computer, it's actually discretizing it. So in a way, think about this chapter as being the connection between continuous and discretization of the continuous dynamical systems. The first example, well, maybe I should say what I mean by that. So let me talk a little bit about discretization of continuous dynamical systems for the purpose of simulating them on digital computers. And certainly, so this will require numerical methods and not symbolic methods. Okay, so the whole thing is we'd like to pretend that we don't have any symbolic capabilities and we just ask computers to solve our problems, well, to help us solve the problems, similarly the dynamical system. So if I start with a continuous time, dynamical system, that means, well, an autonomous system, dynamical system, and of course it's continuous, what does it mean, continuous? Good try. It means that the variables continuously depend on the variable which is on the time, the independent variable, right? So it's a continuous function, well, I guess the word continuous comes from the fact that it runs over a continuous range of times, right? Now, this can, I mean this, you know, you can get philosophical about it, but a lot of our processes that we observe actually run continuously in time, right? But when we observe it, or we make observations or experiments, we can never do this in a continuous fashion, right? So we always have to think of it as discrete times. So, and of course when you put it on a computer, you also need to only simulate discrete times, okay? So the main question is how to discretize time and, well, in time, okay? So if I'm talking about, let's say two variables, let's say x is a function, has two components, two variables, then what you have is, let's say if you have a trajectory, you have an initial condition here and you have some curve that fits the direction field, okay? And the direction field, again, is, so capital F here has its own, has two components, right? We don't necessarily put arrows, maybe F and G or F1 and F2, okay? So for the continuous problem to solve this, it means that we follow a curve that is tangent to this vector field, right, given by the right-hand side. And this is if it's autonomous or non-autonomous. The difference between these two cases is if it's autonomous, then the vector field is just fixed for all times, right? So you can see it, well, in two-dimension, three-dimension, and so forth. If it's non-autonomous, it's going to change in time, so, but still your curve is just fitting that direction vector field, right? But as I said, what you do when you do, you know, when you simulate on a computer or something, then you just, you can only kind of record a discrete amount of times or time described, so you can start with time t0, t1, t2, and so forth, right? So the question is, the big question, which, I don't know, a million-dollar question is, how can you ask the computer to actually jump, you know, so solve from, let's say you've solved until time t1. How can you guess the state of the system at, you know, another time, t2, which is greater than t1? So how can you guess that value, right? And in general, you cannot. I mean, unless you solve it somehow explicitly, then you won't be able to find this exact value, right? You'll find an approximate value. So there are various methods, and you've seen some of them. So what we'll talk about one or two today is, so at the end step, you're trying to find an approximation. I'm going to use capital X sub n that approximates, right? Can I get away? Can I stop putting errors? I'm going to stop doing errors. Otherwise it gets too messy. So that approximates a solution at time tn, right? The question is, what should be an approximation for the solution at time tn? So a simplest method, and of course the most kind of least effective, but it's the simplest to write, is the Euler's method. Okay. So you've probably seen it in for a single equation, ordinary differential equation, but for a system, it's exactly the same thing. So the idea is the following. I'm going to blow up this. So the idea is, if I know the solution at some time, let's call it tn, of course we don't know this. So I drew this line, but we don't know the exact solution. We're trying to find out the exact solution. So the idea is that you can follow. So let's say this is what f at xn looks like. So this is the vector representing the right hand side of that system at xn, right? Then the idea is to take a fraction of this and call this xn plus 1. So I'm going to use this xn here, and this is xn plus 1. Okay. And what fraction of this vector are we going to take? So, well, here's the, in words, sorry, dx dt, and put a time tn. We're going to approximate this with just a finite difference, or a different quotient, difference quotient. So this is x tn plus 1 minus x of tn over tn plus 1 minus tn. Okay. So first we're going to pick the time step. So this is going to be the, we're going to decide at what times we're going to make the approximation. And let's say it's a constant for all times. So in other words, there's going to be t0. The next one t1 is t0 plus h. What's the next time step? The next time is going to be t2 is t0 plus 2h, tn is t0 plus nh, right? Just to simplify this a little bit. So then the dominator here becomes h and the numerator becomes what it is. So here's the idea is to approximate the differential equation, or the solution of the differential equation using this scheme. So xn plus 1 minus xn divided by h equals f of xn. And again, I'm suppressing the errors. So let's say why is this formula kind of giving you that picture, right? So obviously you can rewrite this xn plus 1 to be what, xn plus hf of xn. So then you see that the point xn plus 1 is obtained from the point xn plus this fraction of the actual vector f at xn. So that's in any number of dimensions. You can have x being the vector of any size, of any number of variables. Now you've probably seen this in one dimension. So just to connect it with what you've seen in one dimension in 1d. So that's x is just a function, I don't know, a little x of t, right? One component. You can actually do a better job at representing this scheme by plotting x versus time, okay? So let's say t0 is here and let's say you've done t1 and now you're at tn and you want to do tn plus 1. So all of these are equidistant if you want. So same, same, same, same way. So I didn't talk about the, well, I didn't talk about initial conditions there. But obviously you have to start with something, some initial condition x0. And then you just iterate that process. So it's the same here. Let's say that x0 is, you know, this is the value at time t0. Then at time t1 is this much, right? And then you have found the value xn at time tn. And again, this doesn't have to go in a straight line obviously. So maybe I'll just force this to go down and then up and then whatever, right? So the move from xn to xn plus 1 is done such that what happens? The slope of this line is, I guess I can write this even, instead of capital F I'm going to write it as little f, just one component, right? So it's f at xn, right? So it's a slope and how far does it go? Well, you know what tn plus 1 is. So it goes up to this value and then that's where we find the xn plus 1, okay? But I think to me, I think it's better to think in two dimensions or three dimensions, you know, because it just, you know, it's better to think of it as a moving in the direction of the vector field. But at a fraction of the actual vector field and the fraction is this time step, okay? And by the way, if you want to find good approximations for our continuous solution of the continuous system, h has to be small, right? So that the derivative gets a good approximation with that difference quotient. Okay, so that's kind of how you derive, say, the simplest discretization of that continuous dynamical system. And if you look at it as knowing what h is, if you look at that equation, then you see exactly a, what do we call this? It's not linear because f is still the same, we haven't done any linearization. It's an iteration. Just an iteration, so it's just a discrete dynamical system, right? Right. But it has that little extra h there, which is, which needs to be given priori. So, okay, so basically the discretization of a continuous dynamical system leads to a discrete dynamical system. Of the type that we've studied, so when I write this delta xn equals f of xn, this is a discrete time dynamical system where h is taken to be one. If h is not one, so in general, you would just have this. You would have delta xn over delta t equals f of xn, right? So h is delta t. Okay, and I should mention that of course this is not the only scheme. So there are other much better discretizations, methods, and let's see. So there's a so-called implicit, there are many, I'm not going to talk about most of them. Most of them, there's implicit Euler methods. Implicit Euler is saying that to compute the new state or the value of the solution, or approximate solution at the new time step, you do this. So you start with the old one and then you solve sort of an implicit equation. So instead of going in the direction of the vector field, a fraction of the vector field at xn, you go at the fraction of the vector field at xn plus one, which you don't know, right? Because you're trying to solve. So this equation actually requires you to solve a nonlinear equation for xn plus one. Possibly a nonlinear equation for xn plus one. That's why it's called implicit, right? How would you solve this equation for xn plus one? How would you, how would you instruct a computer to knowing xn? So let me show you the picture on, on just one dimension. So in one dimension you, so you know basically, well, you know where you are at, you are at time tn, right? And you want to figure out what you need to be at time tn plus one. So you see, you basically have to shoot for a point where what happens, where the slope of the direction field matches with this, with this line, right? So to, to contrast with the explicit, this was explicit because the, oops, here you were, you knew where you were at time tn, you knew what the slope, you know, you knew the direction to go and you just went there, right? Whereas here you don't know the slope that you need to take, right? So you have to kind of, who knows, maybe the, the slopes are arranged like this, right? Then you have to kind of probe and see which direction can I, can I go. Now, again, this is implicit so it requires solving, solving nonlinear system at each iteration. But, but, and this can be quite scary, right? I mean, first of all, you may not be able to do it explicitly for sure. On a computer, what can you do? How do you, how do we solve nonlinear systems? All, all this is, I mean, all I'm saying is I have some sort of, and g may not be the, you may have seen g in different contexts. But all I'm doing is I'm, I'm having an expression involving xn plus 1 and xn, of course, but xn is known, right? How do you solve for xn plus 1 from such an, from such an equation? I'm not asking the question, right? So, let me give an example here. Let's say you want to solve, well, if I give an example, it's going to be very explicit. I don't know, let's, let's take 1d, one dimension, right? So I'm having the following, I'm giving you this x prime equals f of x, what, 1 minus x squared. I don't know, okay? How does it look on an explicit Euler? So it's just a simple Euler method. Or maybe not, maybe, maybe x minus x squared. Let's, let's do this. It doesn't really matter. Okay, what's the Euler's method? What's the instruction to give the computer to solving the Euler's method? Say xn plus 1 equals xn plus h times xn minus, I'm going to put subscripts here, minus xn squared, right? And you can, you can just see through this, right? How about implicit Euler? It would be xn plus 1 equals xn. Well, let me just say 2.5 here, so it doesn't look like, you can solve it by hand, right? So xn plus h times xn plus 1 minus xn plus 1 to the power 2.5. So now I give you x naught, and I'm asking, find x1. How do you find x1? Or I'm giving you xn. How do you find xn plus 1? You have to use some sort of numerical technique for solving. You're trying to find n plus 1 itself. Well, you're trying to solve a nonlinear equation, right? Yeah. So what do we do? What do we say we have to do? I mean, unless we have some symbolic, no, powerful symbolic capabilities. But except that case, this you'd have to do a Newton's method or something, right? So, so it's not, it's not impossible. And keep in mind that Newton's method, for instance, for approximating, you know, a zero of some nonlinear function like this, right? You put everything in one side, you call that the function g, and then you apply Newton's method to that. And you run, you don't have to run like a million steps, right? It can be just, well, you have to have a good guess, right? But the point is that each time iteration, at each n, at each time iteration, you're going to have to do something significant, okay? Like doing 20 steps of a Newton's method, right? And starting sufficiently close to the solution. And that's, keep in mind, that's just to find how to move from xn to xn plus 1. Okay, but there are other advantages. So this is a disadvantage, of course. But there are other advantages that actually make this, make this scheme, you know, just a possible, possible scheme. But implicit methods are typically required, this extra step in between time steps. Okay, and there are others, there's so-called improved Euler. Yeah, we're going to get there in just a second. So you've heard of this, and again, if you've seen them on systems, then you don't see anything new here. And if you didn't see them from systems, these are just the same tools as you did for single equations. Yeah, exactly. First order of single equations. So this improved order, for instance, is the following. So it says take the current value xn and then do like an average. So h times, but instead of now taking the, just the either f of xn or f of xn plus 1, you can do f of xn plus, and here's the, you could do f of xn plus 1, but this would give an implicit scheme, right? That means you'd have to still do something in between time steps. So instead of that, so instead of xn plus 1, what could you do here? You could put xn plus hf of xn. So you would, okay? I mean, of course, when you just write it down, it's hard to see that it's doing anything good other than making an average between two values of the vector field. Okay, but it turns out this is actually better, and of course I should say tn. It's always the case that tn plus 1 is tn plus h. So these are fixed time steps, fixed time step methods. But they're also with variable time step, okay? And rangucata, of course, are the more popular type of discretizations here. And let's see, so there's a second order rangucata. So these are names of two mathematicians. So let's see, so this is going to be done in two steps. So first step is, I'm sorry, and sometimes I put the superscript, sometimes subscripts. I'll try to stay with superscripts. So xn plus 1 half h f of xn. So you go like half the time, and you compute something with an explicit scheme, right? So this would be the original orders method, but with only half the h. And then you call this something, no, traditionally you call it n plus 1 half, because you're like tn plus 1 half. So you just give it a name, you store this value, and then you compute the true value xn to be, excuse me, xn plus 1 to be xn plus the value, excuse me, h times f, that's capital F at xn plus 1 half. And again, I'm only doing this for autonomous systems. So it doesn't have any explicit time dependence, but of course there's something with time dependence, too. I mean, if f would have time dependence, then there would be a time tn plus 1 half going here. Let's see, I think one of the homework questions I have for you asks you to look at this fourth order rangakara, which is kind of the most popular one. And in fact, p-plane, the one you've been playing with, by default has that fourth order rangakara. But in order to rewrite a rangakara, fourth order rangakara, let's rewrite the second order as follows. So think about what are the steps required to do that jump from time n to time n plus 1. So you can split it, or you can systemize it, making it more systematic as follows. So here's the following. It's h times f of xn. So you compute this quantity, right? This is going to be a vector. You agree? So f was a vector, so it's going to be a vector, times h. So that's basically that fraction. Then what you're going to do is you're going to take k2 to be h times f at xn plus 1 half k1. It looks a little bit weird that we do it like this, but it helps for the next one. And then the scheme is xn plus 1 is xn plus k2. So again, it doesn't make much sense to write like this. But the fourth order rangakara now is going to become, so fourth order is going to become more clear when we write like this. So we write k1 equals hf of xn. k2 is hf at xn plus 1 half k1. By the way, this is also in your book, so the fourth order. So you can put pages on. It's in the homework part. So page 214. h3 is h times f at xn plus 1 half k2. So notice that the second and third steps are different. I mean, it's not a repetition, right? You need to compute k2 before you compute k3. And also you need to compute k3 before you compute k4, which is hf at xn plus k3. So this is just kind of two, yeah. I have a question about what you did just a little bit about that. Would you re-wrote? Oh, you mean? Well, okay. So I didn't show you how this method, how this second order rangakara is derived. I just don't see how you went from n plus 1 half to also n plus 1. Well, forget the n plus 1 half. Just put it a star there. So that's just kind of a quantity. The first line just defines a quantity that actually is fed in this second one, right? So in essence, you could just forget that it's n plus 1 half. Just take that quantity and put it inside f and just read that line, right? You didn't take x to the n plus 1 half and derive the next one. You just used that result in the second equation. Yes. So I didn't... It looked like you somehow changed 1 half from times h. If you did some sort of algebra... I didn't do any algebra. This is the scheme. It's not part of the... In other words... In other words, here it's just basically this. Sn plus 1 is xn plus hf of xn plus 1 half hf of xn. All there is. Okay. But again, we split it like this so that you can... You see that when you start looking at the fourth order, it's... I still haven't told you what xn plus 1 is, right? So now I need to tell you what xn plus 1 is. It's xn plus 1 6th k1 plus 2 k2 plus 2 k3 plus k4. So all these quantities are computed previously. Yeah. Exactly. So I haven't really derived these schemes, but you can see some oddities. There are some coefficients here. You know, this is like 1. This is like 1 half, 1 half, and the one above is 0, right? And then there is this 1 6, 1 3rd, 1 3rd, 1 6, right? So these are not by only the only ways you can actually create these creasations. But these are... They're not the most popular ones, right? I mean, most commonly used ones. Now, so again, I'm not going to talk too much about... I mean, a numerical core sort of goes into the derivation of these things. This has something to do with trapezoidal rule. If I mean I could... If there's a big demand, I can actually go through this if you want, how they get derived. So maybe just I'm just going to say one word here. So the idea is that you take this and you write it as an integral equation. Instead of a differential equation, you write it as... You integrate it basically. T naught. Let's say T naught is 0, just to be... Then it's f of x of s ds. And then it's basically using the approximating an integral with trapezoidal rule, Simpson's rule, or numerically basically integrating this term. That leads to expressions like that, right? Weighted averages of values of 8. But right in the end, the k is... You see the k1, k2, k3, k4 are just values of f, right? So you can see that it's still not very clear why you have to do it like that. But again, that's the idea coming from. Okay, so that's one of the most popular one. And again, if you haven't noticed in P-plane, that you should definitely go back and check this, that you can actually choose different methods. I'm not sure if P-plane has it or... No, P-plane doesn't have it. You see P-plane, I think by default it uses... Or you can change it somewhere. Okay, so let me just take a thunder pole or something. Okay, so you see this? And options here? Yeah, thank you. So there are other ones. Run-kikata 4 is kind of right on top here. So I guess by default it uses dormant prints, which is also a popular tool. But you see, I think 1.0.d.2.3, that's run-kikata 2. This one, okay. And again, it doesn't show you. And of course you have to kind of tweak things around. But it doesn't show you what the scheme does, but that's what implemented in the code. So what we're going to do in this chapter is basically get used to... I mean, try to think of this method for systems. Okay? If you've seen it for single equations, now it's thinking about... It's looking at it for systems. So if you look at, for instance, this code, which is whale problem, let me just show you where the code is, the relevant code. So first of all, we're talking about... I don't know if you can see. We're talking about competing species, right? And again, this is just to see the direction field. And remember, this direction field is not... It's scaled already. I mean, so to see anything, you know, these are not the actual length, right? It's an indication of where things go. You can do, you know, equilibria and all this. And what we want to do is we want to simulate this for final time 200, right? Initial condition, 5,070,000. So 5,000 blue whales and 70,000 fin whales. And the time step is what you have to pick, okay? Now, we picked to be equal to one so that, well, we're just comparably small to 200 years, right? So this is this, we're talking about 200 years. So let's say H is one. So if you pick H1, you can run and see what happens, and then you change H, right? So this is the loop, basically, where we use the explicit Euler, right? Now, keep in mind, X is a vector. Two components, right? So right-hand side is going to be a vector, right? Nothing symbolic here. Okay, alpha is given as a number. And you just plot. Now, this in MATLAB to plot, basically, to connect the previous one with the new one. That's probably you've seen this command already, so. And then in the loop, it just, it doesn't remember the previous values, right? The values that are computed. It kind of always overrides. So the only thing that's left out of this is the plot, okay? And of course, the final value. When it's done, the final value. And I think we have the plot here, so you can see it. Okay, so it's kind of small. We can run this code. But so what's the significance of these points here? At the end of each year, or after each, so at each time iteration, it has gone in the direction of the vector field by that fraction, right? Now, the smaller the h, the better it's going to be the fit as a continuous curve to the direction field. So it's going to be the better and better approximation for the continuous problem. And let's see, so. And it should, right, so, exactly. So the question is, where is this thing going? Well, being a nonlinear system, it's kind of various things can happen, right? But we can see, right, from the simulation, that it's actually approaching. Well, you can zoom in there and see that it's actually getting closer and closer to some steady state, right? In fact, you can find the steady state. You have the right-hand side set equal to zero, right? So it's just like in the continuous system. And you can see that that's a stable equilibrium. So asymptotic is stable, in fact. So if you're getting, you know, close enough to that, then you're going to be sucked in there, right? And there's another plot that's kind of important to make, which is versus time of both species versus time, okay? Remember that previous plot doesn't show you the evolution versus time. It just shows you the evolution of one species against the other in time. But it doesn't say, like, you don't know how long it takes unless you count the dots, right? How many dots, how much time it took to get to, I don't know, to something, right? Remember that's the face portrait. It doesn't show you the temporal evolution. So, but of course, and this is kind of ridiculous that I did another loop there. Of course, you can do everything in one loop, but I just wanted to... So in this second loop, we do the same thing, but except now, instead of writing over the old values and just leaving the plot, what do we do here? We actually store everything, right? So of course, once you store... So what's this x equals xx? x is a column, right? The little x. Capital x is actually going to be a column after the first iteration is going to be two columns, then three columns and so forth. So it's basically just augments, right? Little x, two by one. Two by one and then it's going to keep adding the columns, which are the computed values of x. So in the end, you just have everything. So you can plot the first row of that two by whatever, and the first row, plot it against time, is going to give you the blue well, right? And then the thin ones. Now, why do I pick 200? Well, you kind of try, right? It's like plotting. When you plot, you choose a window size, right? So here, 200 is irrelevant because of what reason? You know, this thin population was actually stabilized. Much looks like... It just found its peak like around 100 years, right? But you see the blue well is still kind of going up. So, I don't know, maybe it should have gone 300 and since it's kind of plateau, yeah. Again, depending on the problem, you might need to augment this by some factor which would scale this. So if you look in the quiver, help for quiver. And one of the solutions that I gave, right? I couldn't make it myself. So it depends on the problem, typically. Oh, me here, yeah. Sure, that too. Yeah, but if M is too large, it's going to look like a force. Look, the reality is you don't even have to plot these things. I mean, in the end, if it's three-dimensionally, you're not going to want to plot vector fields in three dimensions, right? But you need to know where it comes from. So if it looks pretty fine, if not, that's still fine, right? So we're not, okay. So keep in mind that this is also an essential kind of feature in this is seeing, you know, besides just what happens with one species against the other, is what happens with each species in time, okay? Let's see if I can show you this one really quick. So this one is a RLC circuit, and I'm going, I don't remember how much we spent on this a little bit. We have an example. Yeah. So, okay, so basically just look at these two lines, and this is the system, right? So the system has a parameter C with capacity, whatever. So this is actually the vendor pole, right? It's like the vendor pole that I showed you earlier there. X1 minus X1 cubed minus X2 and X1 over C. It may be a little bit different values, but, yeah, see? So you can actually use this different values for M and put a C here, and you're going to get the same picture, okay? Oh, by the way, sometimes if the direction field doesn't look right, with errors, try with lines. With lines, you're going to lose the directionality. So, okay, so that's what I have here, and of course that's what this one is to, right? So again, what are we doing here? We're trying to, well, instead of just blindly use p-plane, right? Which does exactly the same thing as we do, but in much more efficient way. And by the way, it uses variable time step. So it's much more optimized so that when it doesn't need a small time step, it doesn't use a time, but when it needs a small time step, a sharp, you know, turn or something, then it would actually change that. So, right, so again, look at the code. H was chosen to be 0.1. Capital N is what? Well, it says there. Number, okay, is number of iterations, right? So it's, and it's computed as taking the final time divided by the time step. The floor is just making an integer, okay? But again, the key line is this one, right? Which is explicit Euler, okay? If you feel like really powerful, you should change the line to do like an implicit Euler, which of course is going to, right? Instead of one line, you're going to have to do something at each run of this iteration. Or improve the Euler or something, right? Or Rungekata, you can just take that line out and put four or five lines, right? And it will give you Rungekata. I think that's one of your homework. Not necessarily for this code, but, okay. So that's kind of the basic of discretizing. Let me show you something interesting. I mean, this is actually more interesting. So I'm going to pick on the RLC. So if I take this code and I just put it in MATLAB, RLC Euler. Ooh, oh yeah, okay. Okay, so you see it's better than that published version. Okay, so I just want to show you what happens if you take a larger time step, right? So point one is it turns out that it's actually producing that cycle, right? So remember in that, well, you have no way of knowing, but you saw it in the P plane. There was something like a cycle, right? That's the oscillating behavior. But if you do this with a course, with kind of a big time steps, like big jumps, you start at the same point. But you see, you follow that bigger fraction of the vector field, right? So you're like, from the get-go, you're too far from being approximating the continuous problem. And of course, because the first step was so bad, you know, everything's bad. So there's a lot of, I mean, it's a huge field, of course, for a very simple and good reason is that with a computer you cannot, you know the state at this point, you're trying to find the state in two seconds. If you don't solve it exactly, you know, if you don't follow that trajectory exactly, how can you know how to advance? So these methods are actually, you know, trying to do a better and better job. Of course, everybody would say to make the approximation better, just make h really, really small, right? If you make h really small, you're going to make n really, really big. So this, you saw it took more longer time to run this, right? Of course, you could say, well, I'm just going to do 100 iterations. But if I do 100 iterations and I'm making h really small, what's going to happen? You're just going to go a little bit, right? So there's always trade-offs here. And you ought to take my other course, which does numerical solutions of PDs to see how much more hair it gets there. But it's the same thing. It's like, do I want a really fine, you know, resolution in time for a good solution? Not always, because then you're going to wait forever to get a solution to be doing anything significant. Okay, so that's what I wanted. And I had a third code that I'm going to show you and maybe just finish early today. Oh yeah, so, I don't know, you probably saw how many different possibilities, you know, modeling situations you can encounter just from what we've talked so far. But this one, I think, is the first example in Chapter 6 is something like a war problem. It has basically, gosh, my typing is terrible, right? It's not dynamic, it's dynamic system. So this code, and again, if you look at the example, basically you have two armies, red and blue, I believe. Each is measured by a number of soldiers or something, right? And then there is some sort of dynamical system, but it's a discrete dynamical system from the beginning. So we're not doing anything, just providing some continuous dynamical system, right? This basically says that the change in, so it's a bit, maybe I should write this down. So C, well, and RLC examples for Euler's method. Okay, and the last one is basically a simulation of discrete time dynamical systems. And by the way, this was also near exam, if you didn't notice. If you've noticed, okay, good, that's good. Now, of course, you had something else to do there. I mean, it wasn't really simulating this thing. So you do kind of analysis of the discrete dynamical system, but here it's saying, and again, there's going to be some parameters. It's just saying that, is it each day? No, each hour, each hour, right? So it's like an hourly update. It says the change in the red army or blue army, I forgot which one is the X1, is red army, okay? So the red army kind of decreases proportional to the blue army, right? And then there is some sort of, also some sort of interaction between the two armies. So there's a term modeling that, same with the other army, and the possible parameters. So the parameters have some meaning. So they're considered to be positive, okay? So I'll let you kind of look through this. And of course, they can be uncorrelated, but I think one assumption early on is that A1 is a constant multiple of A2, of lambda times A2, and B1 is lambda times B2. And let's see, what was the meaning of lambda? Let's do the efficiency of one or the other armies, but that doesn't quite, it's not so important at this point. So basically what you have is you have a discrete time dynamical system with an initial data, so X1 and X2 at time zero is given. And then the question is, analyze the dynamics of the system for different choices of the parameters, okay? And that's what this code does. So let's see, so if you follow my example, everything's kind of in one big loop, but you don't have to do it like that. So for instance, the values of lambda are all chosen in this array, in this row, right? So it's 1, 1.5, 2, 3, 5, and 6. And then this is one big loop, basically for each value of lambda it does the same thing. It has some fixed values for the other parameters, right? And then it just kind of plots things and then computes things. So what's the only peculiar feature in this code is there's a wild loop, what is a wild loop? It's basically testing when, for the condition when both in this case are positive because if one stops being positive it means it's gone. And then it stops. There's no reason of pursuing in the other quadrants, right? So that's basically this thing, but you see here it's just basically, this is the one key line again, okay? And then at the end of this, it says if X1 is the one that is positive while the X2 is zero, then the winner is, and so forth, right? So let's see what comes out to this. It comes out to be. So there are all these runs, right? Lambda equals one gives you this run. And you see it has n runs, I see nine runs, I mean nine iterations. In the ninth iteration the blue army goes negative, right? For different values of the parameter, it may take longer, but still the blue army is is losing after 10 iterations, 11 hours, right? Whatever. 12 hours, 18 hours. So Lambda has this meaning of? Slows the attrition of the blue army, right? And the blue army was the second one, so Lambda came in the first one. Right. The longer in hours, you mean? Right. But it's true that the blue army, the red army wins, but with less survivors, I guess. And then you see for Lambda equals six, it actually switches to the other one. And visually this is, you have them in the book as well. There's a problem with the book, the plots. The plots that you see in this chapter are like, you'll find plots three pages after the problem is over. So you're talking about all different problems, but you're seeing the old plots. So it's kind of confusing. So just kind of look at this, and I think you can start working on the homework. I have to mention the first problem in the homework. It deals with this war problem. And it asks you to do kind of a run for two different types of parameters. So you'll have a Lambda which has six values and a W which has six values. Okay, what does that mean? It means you're going to have 36 runs. Please don't make a pen print out of that. So I'll mention more on Wednesday, but just don't print it yet. I want to just tabulate. I mean, just in a table say who wins, depending on the, yeah. No, no, no, no, no, yeah. Thank you.