 Now let's go on to an example problem. Now I'm doing this problem again in iPython notebook using Sympi as my extension to Python You can watch the lecture series on an introduction to Python for for mathematics That is one of my playlists You needn't use Python like this. You needn't worry about the coding here iPython notebook is fantastic in as much as I can show you What the results are without you understanding what the code is for those who want to get involved with the code I'm just importing Sympi as this abbreviation SYM. I'm also importing from Sympi It's capital I which is the The imaginary number I I'm doing pretty printing by calling Sympi.init printing And I'm sitting a few symbols the symbol t alpha and beta I'm sitting those t alpha beta there and I am sitting the variable x and y to the Functions x and y and I'm going to define them as functions of t So here we have an equation on the left hand side I'm going to have the first derivative of x with respect to t and on the right hand side I have x plus 2y so first of all let's just run that nothing will happen I'm just importing all of that. Let's run this block of code and There's my first equation and here's my second equation as I say you can pause and look at the code There's various ways to do this what is important here. We have a system of first-order ordinary differential equations It's x prime and y prime there They are x prime is x plus 2y and y prime is negative half x Plus y Important that both x and y are functions of t here. So we're dealing with a plane We're dealing with a vector field in the plane. This is a system of equations. I need to solve them together Now I'm going to define my matrix a let me show you how easy this is of course if you use something some computer algebra Systems specifically Sympi which is fantastic for this you can see immediately My matrix a is going to be one and two and negative a half and one So there that's how I define my matrix. I am giving it a variable name uppercase a that's one and two and negative A half and one that is my matrix a and then I'll just print a to the screen So there is my matrix a one and two negative half and one I'm using the dot notation so that I'm sure that these are seen as flooding point values not as integers now we can use the method of Calculating the eigenvalues and then the eigenvectors so so simple in in Sympi I'm just going to say it's why I'm referring to some pie dot matrix a dot eigen valves open close parentheses if I do that Boom out pops my two eigenvalues. I see I have two eigenvalues one day and one day The first one being one minus negative i and one being one plus positive i so those are my two eigenvalues Just to remind you let's just use the first one. We'll call that lambda sub one That means alpha. There's my alphas one and my beta is negative one So let me just print that to the screen if you don't want to follow the the code I have alpha equals one and beta equals negative one. So that's the that's the eigenvalue I'm going for I can also just do the eigenvectors very simply without having to do it by hand Of course, if you're not doing this in Sympi you're doing them on pen with pen and paper Use the eigenvalue eigenvector method and you'll get These values so for the eigenvalue one minus i I Get one eigenvector and it's two i over one and for the eigenvalue one plus i I get one eigenvector. It's negative two i and one of course the complex conjugate there Remind you of the following then to solve a system of first all ordinary differential equations I'm gonna have this b sub one and b sub two b sub one is going to be the real part of the first eigenvector and b to the Imaginary part of the first so if we look at this first eigenvector, I can use either of them But let's stick with this one. It's going to be Zero and one is going to be the real part because remember this two i is Zero plus two i so the real part is zero the real part here. This is one plus zero i So the real part there is one And here we have zero and one being the imaginary part and negative two zero being the Zero and one being the real part and negative two zero being the imaginary part So just reminding you what b1 and b2 is I'm just defining a bunch of variables as symbols in this piece of code here Needn't worry about that. Let's just run that so that I have this now remember how we get this is in We have two unknowns x and y two functions of t x and y remember that x sub one is Beta sub one times the cosine of beta t minus b sub two sine of beta times t times e to the power alpha t Remember we chose alpha to be one and beta to be negative one our first eigenvalue there So that's where I'm going to plug in alpha and that's where I'm going to plug in beta and remember b1 Will now just be the image real part of k1 and b2 will be the imaginary part of the eigenvector k1 So let's just run this block of code just to show you there We have x sub 1 x sub 2 then remember is is b sub 1 sine of beta t plus b sub 2 cosine of beta t to the power times e to the power alpha t So let's just run this There's my b1 and there's my b2. That's what I said if we look at k1 This is our k1 and zero and one and two and zero Zero and one and two and zero is my b sub one and b sub two I know how to construct x sub one and x sub two now and I can just plug in all my values and I will remember that in the end Right in the end. It will be I'll have a x Equal summing and y equal summing remember. It will be x will be This b sub one and b sub two is a column vector. So the first Element will be the x values and the second element in other words row two In other words, so that will refer to x and this will refer to y that will refer to the x and that will refer to y and I just have to remember I have to put the c sub ones and c sub twos in so if I Do all of that combine them I will have one equation with a c sub one and c sub two for x of t and one equation With a c sub one and c sub two for the y of t Do that I'm just going to Run this piece of current just to import the matplotlib.pyplot as plt and I'm just going to export it on in in the As part of this notebook So if I were to do that and I were to do the following if I if I set the x of zero to be two and the y of zero to be zero I Can then solve for c sub one and c sub two in other words I'm going to get final value for x of t and a final value for y of t So x of t is going to be e to the power t cosine of t and y of t is going to be negative e to the power t sine of t Here's a bit of code so that we can just do a plot of that This is to a plot of that and when we start at time equals zero now I can't use x and y my code here because I have to find them as symbols so I can't use them as variables I'm just doing x value and y value just thumbs up two variables And I've got this little step size of 0.1 and I'm just going to run this loop while time equals less than two My x value is going to be two times Exponent t and again, I can't use t t as a Symbol, so I'm using the variable time times the sine of cosine of t Now, let's just let's just correct that I say let's just do That shouldn't be a two there this is correct that I said if I do that Let me just see if I did get my answers correct. No, there is a two times there Two times let's check it. So if I just change this code here, that will be twice that Let's check for yourself that that is correct It's twice times e to the power t times the cosine of t and negative e to the power t sine of t then I plot my Point because now I've got one point in one point I'm plotting that m is red dots and I'm adding 0.012 t and this will carry on carry on carry on until until such time as t is no longer less than two And it will escape and I'm finally just going to plot that And there we go