 Hello, I'm Simon Benjamin and this is the second of my lectures on Fourier series Fourier transforms a little bit of that and PDEs partial differential equations So in this lecture we'll build on what we found out last time, which was essentially what it what is a Fourier series? What's the idea we'll extend it first to Understand how to deal with a Fourier series when we have a function with some period p Instead of 2 pi so we sort of said previously we just make it 2 pi for simplicity But in the real world things don't have a periodist e of 2 pi necessarily So we need that little extension and we'll talk about the simple the simplification that comes if we're trying to do a Fourier series of an even or an odd function and then it's on to examples, which is maybe the exciting bit because That's where we'll find out if all the maths we've been working out actually works so we'll look at square and Square wave and triangular wave as examples and the triangular wave is the one where in the last lecture I just typed in some numbers that I knew would work to Mathematica and we saw that A simple cost series started to take on that triangular form But where were those numbers coming from well this this lecture we find out so I'm going to start by writing out the equations that we came up with last time and Just to remind just as a reminder of what they look like and then we'll extend them to work for any periodicity So here I've written it all out to because just I'm a bit slow at writing things. So this is quicker So given a period 2 pi function Which we can of course write as f of x plus 2 pi is equal to f of x And here I've just scribbled some random crazy looking thing and but it is periodic because I just copy pasted the scribble I'd written and so you can see that from here to let's say here the X equals zero line and out to here. We've got a repeating function. So what we would be saying is that this This is 2 pi here Someone has given us this function Doesn't have to look crazy, but it could then if We can write that thing we can build it using a sum of Cosines and sines Then those must be the coefficients and that includes The coefficient for a zero because when we put zero into our cos nx We make n is equal to zero then that just becomes one and That also works and that was why we cheekily put this little factor of two in our definition So that we would be able to so compactly write out our constants and not have a separate line just for a zero at the In the last lecture, I believe we ended up using subscript m here here and therefore of course over here But that again is just a dummy variable in the sense that n is you know some integer and it just appears on both sides We used m because as part of the derivation We were using both n and m and then it was important to tell the difference But once we've got to our final line of definition, it doesn't matter what symbol we use and you know when you have a Line where you just need a single Integer that can take any integer value. It's conventional to use n. So I've Reverted to just using n here. Hope that's not confusing Anyway, that that was pretty neat But of course, we haven't actually proved that it works in that all of this has been based on If if it's possible to write our interesting periodic function in this way, then these are the coefficients But it maybe it isn't possible So that's a topic that we will at least learn more about in this lecture because we're actually going to try it for some particular particular interesting periodic functions But the question of whether it will always be true or are there periodic functions that we could write down that won't work Well, we'll say more about that. I think in the next lecture Anyway, there we are. So the first job that we have today is to extend this because I Might have a problem in the real world that has a dimension to it like length and it has some periodicity to it maybe and this is something we might look at I have a stack of two different kinds of metal and Then and their sheets and then the z direction can be thought of as a periodic function because let's say the Concentration of metal one goes from a hundred percent to zero to a hundred percent to zero to a hundred percent to zero In the z direction, but it will have some periodicity, which is the thickness of a sheet and not too pie So we need to understand how to convert a problem which has some general period Into essentially our two pie case or in up equivalently to just write down the equivalent of these equations But for a general period P Now we don't really we can do this without really thinking very much about Furious here is specifically all we need to do is to think if someone gave me a periodic function with period P How would I convert that? Into a periodic function with period to pie then I solve my problem using my nice elegant equations here And then I convert it back again That might be quite a nice way to work because then I would never have to keep dragging around the details of The period of the function through the mathematical analysis, so let's go ahead and do that What we want is well someone has given us a function Which has some general period and we'll call that period actually we're going to use the symbol not P But capital L just to be consistent with my notes and remember that the notes are always available here at Simon B. Info if you're finding trouble Getting hold of the mouseware So we've been given some function G with the property that if you add L to it You get back the same value again now. We don't want that. We want a function F So we'll define a function F like this we'll define a new function F and It's equal to G Except now I'm going to scale what I feed into G So let's write it like this with a gamma symbol and we ask ourselves. What should this scale factor be? Now I want it to be the case that F has period 2 pi so as I change x from Nought to 2 pi I Want this scaled thing that I'm feeding into the G function, which is Gamma x to go from naught to P. Oh, sorry L. We're using capital L as our symbol So what does that mean? It means that our gamma must be equal to Just the factor that will make this happen from these two lines So we're going to times it will be L. Excuse me over 2 pi question mark and I Hope you can see that if if gamma has this value then it will perform that rescaling for us And we can quickly confirm that works But just to sort of make our definition explicit. So what we're saying now is that yeah, I'm defining a new function F of x as being L over G of L over 2 pi x fair enough So now What is F of x plus 2 pi going to be? So it takes a little bit longer to sort of write it out Even than it does to say it but by choosing this factor by which we stretch or compress The variable x we're able to have a new function that has the periodicity that we want So having tied it up. We have this but and of course we can it may be helpful to sort of you Translate one way or the other so the other way to write this Is that if we were focusing on what we would rewrite g of x as? We would say g of x is equal to f of x and then we just need to reverse this factor to translate back the other way So that's how we would translate from g into a function that we might find more convenient to work with and then at the end translate back again so using that principle if we come to the line above and rewrite Explicitly we don't need to remember our defining equations in terms of the general period Because all we need to do is remember this conversion trick, but still just for the sake of it Let's write out now What we will get if we if we choose to write the gen the fully general version of the Fourier series So now the Fourier series for some function g which has period capital L It's going to be defined like this g of x is equal to again. We have our constants there we go Plus the sum from n equals 1 to infinity of a n cause Now this is where we need to watch it because of the way we've defined the relationship between g of x and f of x if we look if we're working from This line up here, which was giving us the expression for f F being periodic with 2 pi then we now need to do the substitution and To put in 2 pi over L as an additional factor So we're going to get cos n times 2 pi over L times x and Then we'll have our bn sign term, but again the sign will pick up this same factor 2 pi over L x So that's okay. It's just a bit more Sort of complex looking then our nice elegant expression for f, but that's all right. We can do it Now what we'd like to do is to convert our expressions for these unknown constants or rather for The values of the constants that at the beginning of the last lecture were unknown, but we pin them down We need to convert those expressions if we are going to write things in the natural way for our period L function called g so we need to take the lines above and just Substitute so we know that a subscript n for example is cos nx times f of x But now we need to substitute. What is f of x? It is g of L over 2 pi x d x now Because x is in any case just a dummy variable here for clarity. Let's Do change of variables and we'll change to a new variable u which is Equal to L over 2 pi x or in other words x is equal to 2 pi over L u those are obviously the same Those are obviously the same statement So let's see what happens when we do that conversion. We'll get 1 over 2 pi now When the old integral goes from naught to 2 pi then in terms of u will be going from naught to L We can write cos nx and we substitute of course. So that is cos of n 2 pi over L times u and G however now just becomes g of u and We have d x. We're going to pick up this factor 2 pi over L D u and neatening that up What we are going to get unsurprisingly is something that was very similar to the original expression But now all the 2 pies have turned into L's They would if I would write it neatly and let's see how good we can write this cause we could write it as 2 pi n over L I suppose u D u So that's our expression for a n and our expression for b n would convert in exactly the same way now because This variable u is just a dummy variable. We can use absolutely any symbol for it. We like of course We could now write that line with x Just a dummy variable and forgetting you know that we previously introduced two Symbols because we needed to explicitly change a variable to keep track of what's going on now We've got the final line. We can use any symbol we like and so we wouldn't use u because that just looks a bit unusual To the eye we go back to using x in our sort of summary definition. So let's do that now We'll come up with it all on one screen. So we'll need to copy down our statement about the Fourier series in terms of Gx we'll put that at the top of the new page and Strain out a bit perhaps Okay, and we'll say then that Working in terms of this g of x thing we can say that the constants a n are equal to 1 over L the integral from naught to L of cos of 2 pi n over L times x as I warned you I'm just Using now just so that it looks nice and conventional. I'm just using w dummy variable x and The n is of course going to be the analogous thing but in terms of the sign So those would be the equivalent Set sir. In fact if you want to just memorize one thing. Oops, I didn't go If you want to memorize just one thing then that would be the one to memorize because It gives you the completely general case But I wouldn't memorize that I would memorize this version which I find to be Much more pleasing when I'm about to highlight and pink here Because these ones I understand where they came from They just have these the most simple form. They can have Um, and then I would just remember or Rederive is pretty easy that if we want to scale a function. We need to use this line here But really doesn't matter which set of expressions we use they they do the job and By the way, we can verify here that if we do put in L is equal to 2 pi We just get back the original expression as we must because this orange highlighted set is Complete general doesn't say it's not 2 pi just says that it has period L Okay, let's move on to a quick and pretty easy topic helpful one Which is what if the function we've been told to analyze and create a Fourier series for? Happens to be an even function or what if it happens to be an odd function? That should help us we would expect because we've already defined or Derived the expressions which work in general So if we're now adding in a special Constraint, then if anything that should make those expressions simplify and it will now So let's write it out. I'll switch over to a different color. Let's do black for a change. So We need to figure out what are these? Constants a n and b n in the case that our function is Even or odd. Let's take the case that f of x is odd first. Let's say then what what what are the helpful implications for us the answer comes from Looking at our expressions and Changing them so that they do go from minus pi to pi rather than from 0 to 2 pi now You remember in the last lecture the way we got these expressions was just by Integrating over one complete cycle. It wasn't important that it was 0 to 2 pi It could have been from any point k to k plus 2 pi right we can As long as we sweep out one complete cycle all the arguments in the last lecture would have worked Now what did we say to consider first? We're first. We're thinking about what if f of x is odd Well, then I want to ask what do we have for this? product the cos times the f of x the complete integrand in this expression It's now going to be some kind of even function actually Pause times some kind of odd function our function What do we get if we multiply together and even or not that that that function which is the product of those two things? Is it even is it odd is it neither? Well, it's all about what happens when we change the sign of x right? So if we change the sign of x inside cos It doesn't care cos of minus x is cos of x if we change the sign inside of our f of x It does care So what we're saying when we when we say that f of x is odd What we mean by that is that f of minus x is equal to minus f of x Remember as we introduced in the last lecture so that means that What will happen if we change the sign in that product is the whole thing will pick up a minus sign Because of the f of x element and so the whole thing is odd So the product of an odd function and even function itself is an odd function But we know that when we integrate an odd function between two symmetric limits either side of the origin It must be zero Hooray, and so we just don't need to do those integrals. We could they'd come out at zero But why do an integral when you know it must be zero? So you're kind of just wasting your time and and risking making a slip Maybe you won't get zero, but that's because you made a slip. It must be zero and similarly For exactly the same so what we're saying is if f of x is odd the an Coefficients are all zero, but the bn are not in general zero some of them might be zero But that's that those are the ones that will be doing all the work if we have an odd function And remember the bn coefficients are the ones in our expression which Actually control the sine terms So really we're saying very something very intuitive Which is that if our for if the function we're trying to build is odd We only need the odd Building blocks that is the sine building blocks We don't need the even building blocks and remember that a constant is actually an even function So a zero over two here is also even so we're saying an odd function can be built purely out of the odd Components all the even components should have Coefficient zero we won't know we won't need them and it won't surprise you to realize that Exactly the same thing is going to be true if we reverse the question and say what if If f of x is Excuse me for writing a messy way is even If f of x is even Then all the arguments that we've just made to go through we're now going to inspect the bn terms We can as we've proven write that from minus pi to pi it will be sine and x times f of x, but now f of x is even But now that will be because sine is odd. That's still odd times even and Same argument it must be equal to zero So if we have an even function f of x, we won't need any of the sine terms Their coefficients must all come to zero. We'll just need potentially that a zero constant and the cos terms So to say it one more time An odd function is going to be entirely made out of a Fourier series of sine terms and Even function is going to be entirely made out of a curve of a Fourier series of a constant and cosine terms Great simplifies our work, right? It reduces the amount of stuff that we need to do by perhaps a factor of two in that I only have to do one of two different integrals now with all that said It's clearly high time for us to do some examples and actually see if it all works It's all been very provisional up to now We've derived expressions for what these weights should be if it's possible to write it in that way at all And we've gone on to say oh, by the way, I can make it have period L if you want and By the way, if the thing that I've just given was even or odd that will simplify my expressions down But we still haven't seen it in action, so it's time to do that Let's do that right now and we'll start off with The one that will be the simplest to integrate I mean that all the examples that I'm going to work for are pretty easy to integrate But the simplest of all is going to be if we consider a square wave The square wave goes from goes between zero and plus one and it goes instantly from zero to plus one And we said we want to have period 2 pi How can we write so that's a diagram of it? That's a sketch. How can we write it as a How can we define it mathematically as an expression we would say f of x is equal to plus one if x is let's say Greater than equal to zero but less than pi and It's equal to zero if x is greater than pi But less than 2 pi my pie symbols continue to be slightly off and of course We just impose its periodic function with our usual notation x plus 2 pi f of x plus 2 pi is equal to f of x that will do the trick in terms of defining our function mathematically now I've tried to be a bit careful here and not accidentally define f of x to be Both plus one and zero at a particular point at the switch over points So I made sure to say that it's plus one only Up to but not including pi and then it becomes zero from pi But then up to but not including 2 pi because we know 2 pi must be back and be the same as zero So strictly speaking we need that definition otherwise will have accidentally defined a 2 value function Now we need to do the integral, but this is going to be a really nice integral to do because the Interground is either one or zero. So let's let's now also having just talked about odd and even functions We look at this thing Is there a trick we can do because I don't have to do more work than I need to this function is Annoyingly not odd or even it doesn't have the property that for Some negative value of x the function is just the same or the same up to a sign as the positive value of x So I could just go ahead and say oh tough it wasn't It wasn't odd or even but I I'm lazier than that And I like to spend a little bit of time thinking about a trick if the trick will save me having to look at two integrals And I only have to look at one of them. What could I do here? To make this to translate this function into an odd or even one or in other words to solve a problem that is odd or even and then in solving that problem, I'll easily see that I've solved this problem that I've been given well How about if I just shift things a little bit? Be more careful. There we go. So if I move up like that that Function now is an odd function. It goes between plus a half and minus a half and it has all the properties that we require of an odd function so actually just to save a bit of time and You know do the slightly Cheeky shortcut method. I will go ahead and define a new function Here we go based I'm just erasing all the references to F and changing them to H and I'm also going to have to adjust the limits of course from To go From plus to minus a half. So in other words the relationship here, of course is that my H is Just equal to f of x Minus a half and I'll need to remember that to translate back at the end But now it's an odd function. Good. So because it's an odd function all the arguments we just made So I can write here H of x is An odd function and that means that I will not have to work out any of the a Terms I only need to go and get my expression for BN Let's copy it down and work it out. You should do it Copy that. So this this I do need to work out Because a of n for all values of n is just zero for free So that was worth it. It was worth just shifting my function up to not even have to look at that integral Oh, it would be easy to do anyway, but you don't have to look Let's see what we get now. So we're gonna say one over pi the integral from naught to two pi just write it out I guess of Sine and x But now we have this Plus a half minus a half type of thing, right? So Rather than trying to write that out all in words. What I should do is split up my integral into those two parts So it's going to be a part which is from naught to pi and There it is equal to the f of x is equal to plus a half DX and then From pi to two pi Sine and x again, but now it's going to be minus a half DX Okay Fine fine fine This looks like it's That looks to me like there may be some further simplifications to be had here But I'm just going to not do any more tricks and just evaluate one of these It I'll just go ahead and evaluate it. So it's not very hard at this point, right? so I can see that I Can take out a factor of a half here so I can say well that's going to be equal to one over two pi and Then I'm just going to go ahead and just write these things out because it's just after all. It's just I'm just integrating Sine, which is pretty easy. I can't make it much easier than that So the integral of sine is minus cos But because of that n factor in there, I also need to divide by n from naught to pi and Then over here. I had a minus sign Which came from the minus a half factor. Let's just do it So the same thing from Pi to two pi Right, it seemed that that should be too bad. I just have to think what those things are. So one over two pi Hmm So cause of zero is one So that's easy and cause of n pi now. What is cause of n pi? Well, let's just I tell you what let's take it slow So I can see that there's a factor by the way of one over n n is just a constant as far as this Integral is concerned. It can't be zero by the way because this is the b n coefficients We're working out and there is no b 0 so I'm perfectly safe to take out n in front And must be at least one and it's just some integer and now I can go and head and write out what we're talking about So minus one is is one of the limits, but that's at the minus. Okay, so let's let's do it properly We've got minus cause of n pi and then minus Let's put the whole thing in Another set of brackets perhaps to make it very clear. So we've got minus cause of n pi minus One because the limit at x is equal to zero is just one and then over here. We've got minus And there was a missed off sign there. So that turns into a plus and that is going to be cause of two n Two pi n Minus cause of n pi All right We've got to close up a lot of brackets like that No, okay it's an unusual sort of Expression maybe compared to most integrals that you might have met in the past But in fact, it's a very simple one all we need to do is to simplify it as much as possible and then replace Our cause n terms with what we know Cause n pi terms with what they know they must be so I see that I've actually got If I note that this is the first one to pick on cause of two n pi Well cause of zero is plus one and when I add two pi Or any multiple of two pi onto cause I just I don't change it. So it must always be plus one So that is just a one And I see that I have another one if I note the minus minus So that's going to be two And then it's going to be minus two cause Of n pi is that as neat as I can get it? No, I can keep going Because what is cause of n pi? This is now interesting Let's try and write out our cause Using my very limited sketching skills. Yeah, and they're off to a wonky start as usual And I can I can go in a negative direction a bit So there's cause Now let's mark on what we're talking about. So that's pi That's two pi That's not really room for it, but that's three pi and so on What can we see? n is equal to zero not that that's actually one of the n values we'll be considering We would have Plus one n equals eight one. We have minus one then plus one then minus one So what we can see is that cause of n pi Is equal to plus one if it's if n is even and minus one If n is odd, but there is a neat way to write that We can just write it as minus one to the power of n Because then again if n is even that's just going to give us plus one Right as that the smartest we can write it. So let's see where we're up to We're writing this now as we can cancel out a couple of factors of two So that's one over n pi and then this will become One minus minus one to the power of n Is that the neatest we can write it? Well, that is a Pretty compact way of writing it, but what what is one minus minus one to the power of n again as we let n So if if we think about n is one two three and so on Then this quantity one minus minus one to the power of n is going to be equal to what well um, it will be equal to Two comma So and when n is equal to one that's two But when n is equal to two that's one minus one which is zero And then it will be back to two and it will be zero and so on So in fact what we've got is that our integral comes to either That's a finish writing out just two over n pi if n is odd Or um zero If n is even And here I just I don't mean odd or even function, of course, and it's just an integer So I simply mean if that integer is um even There we are. So we've now completed our integral And we're ready to write out our Fourier series Because we found out that quite a lot of the terms Are zero namely all the a n terms. They're just out zero And uh half of the b n terms are also zero But the other half are not zero and they're obviously gonna be doing all the work So we can write our Fourier series our Fourier series was if we remember um f of x was equal to Um an a zero term that we don't oh, I'm excuse me. This is h of x we've built h of it x is equal to no a terms at all including no constant But just the b terms And we only want to sum over the odd values of n. So I can just write odd n equals one to infinity So it's clear what I mean by that is just don't bother me with n is two or four or so in my sum And then I can just go right ahead and put this expression in Two over n pi like I may have We'll see what happens two over n pi of um sign of nx So that's actually a pretty compact Fourier series Uh, not bad. There's no reason not to take that Part of that factor out in front So we can write two over pi. We'll just bring that out in front of the sum symbol And now again, we'll write odd n from n equals one to infinity of just Let's write it like this sign of nx over n. It's pretty neat. That's it That's our whole Fourier series because so much of it just turned out to be zero But let's just uh, just to completely finish the story because otherwise it will be a bit unsatisfactory to to miss off one line of it f of x of course Uh, if we go back all of this that we've been solving cheekily is for the adjusted function to make it into a non-function But f of x based on our definition here f of x is equal to h plus a half So we just need to add in that half factor. So if we say a half And then write, uh, the line above we really will have finished it completely The only other thing I might want to say before we switch over and have a look at this to see if it works Is the following Is there another way if we don't what if we don't like writing our sum symbol with this sort of odd only Rule just written in words It's fine actually and and you would find that in a scientific, uh, publication People write special constraints underneath the sum symbol just like that because sometimes that's the most elegant way to do it However, if we don't want to if we do want to run over all possible values of n There's another trick we can do which will just be Uh, completely equivalent. So let me write it out What we can do is we can run over Absolutely all values of n starting from let's say n is equal to zero and going to infinity if we Take those Values of n that are being generated by the sum rule And double them and add one That would be the trick here Uh, and so where we had n in the line above We'll now write two n plus one and I think you can see that when n is equal to zero Two n plus one will become one and so on so these two things are completely equivalent And it really is just a matter of taste as to which one you write down They are as it were both full mark answers But now it really is time to switch over to Mathematica and by the way in the notes um What we're about to do is shown in uh lines of code that work in map lab Which is another alternative and there are many other maths packages that are meaty enough to do This job, which is really rather a simple job. So here we are with Mathematica. Let's try out that I honestly Don't know, uh as i'm deriving it through. I I wasn't checking so We're going we're about to find out whether that factor of two over pi. I think it is right, but we'll see Maybe I made a slip We'll find out so um So a half that's definitely correct plus two over pi. That's what we derived And now the sum mathematics will could we'll just perform a sum for us by when we type in sum Of a bunch of sine functions We'll do that trick of doubling an integer and adding one to generate only the odd integers And then we have to divide by exactly the same odd integer Uh and now we need to tell Mathematica over what range we'll go n from uh, I don't know zero We have to start from zero because that when we do two n plus one gives us the first element one But we'll go up to five and uh So if we execute that we get what we expect um Here is our sum of for example terms like sine five x over five But we don't need to see that every time so I'll put a semicolon in here so that it hides it What we really want that's hiding it now is to plot f. Let me make a bit of space so it's easier to read We want to plot f for some range of x. Let's go from I don't know minus seven to seven And we'll see if it looks about right or not Now I'm it looks interesting. Let me just scale it a bit so that it doesn't take up too much space on the screen Now we're scaling it Um, yeah Not bad not bad It's not it's not there yet. But of course, we're only doing five terms not an infinite series of terms We can see it's trying to build that switching function for us It has the period that we expected we can see it there switching from uh Over the range of naught to two pi it spends half the time at one and half the time trying to be zero What's not inevitable So it's good to see it is that it indeed builds the correct switching function that you know, we could have Messed up the derivation and then it wouldn't be constructing it Still it's not there. It's not ideal. All right. So we could ask what will happen If we increase the number of terms And I want to paste it and we'll have a we'll actually have a second function Well, it's put two on the screen at once. So let's call them f and g And f will be from naught to five But g will be from naught to 15 And we will just compare them To really see what we're dealing with here Okay, and we could zoom in let's zoom in on Just a little bit negative And negative one and a little bit outside the two pi range So let's indeed go to seven like that. So yeah That's the effect of increasing The number of terms nice How about if we went to a more serious serious number after all Mathematica is powerful software And it's running on a remote machine. That's pretty powerful. Let's go to a hundred terms Boom that was quick Now It's getting really good There you can see we could even zoom in actually between let's go So we see there in the big picture. It's getting very much like our switching function But let's zoom in and see exactly what's happening Near the origin. So let's go from zero to 0.2 that's home right in interesting so I remind you that from zero onwards it should ideally be exactly one The blue line that's made of only five terms is still working its way up at this stage doesn't It is just about gets to get still and goes above one by the naught point two point the orangey brown line with its hugely larger number of terms is able to get Get up there to the to the plus one region much more quickly But there's an interesting effect which is still overshoots and let me show you If I think if I go out just a little bit further to point three, we'll see something interesting Now the amount that it overshoots by is about just less than Point one right it should be ideally stopping at one and it's overshooting to one point one And that's the same amount of overshoot that we got with the much cruder approximation Now it it's still I For any practical purpose. It's much better to take the orange Um function here the one with a hundred terms because it's it's getting much closer to the ideal But it's still kind of interesting that it overshoots just as much albeit it almost immediately corrects back What would happen if we tried five? Let's make something that will still be Um visible on this range. Let's go up to 300 terms and evaluate that Okay, it's still overshooting by the same amount But of course even more correct Quickly it corrects back. So in terms of uh, how important that defect would be if we were doing some numerical calculation It's getting more and more trivial and so it you know, it's it's a tiny and tiny error But it always overshoots by the same amount and that's actually been studied by mathematicians And it has the name the Gibbs phenomenon the fact that it doesn't go away It still overshoots albeit That overshoot would be less and less of a problem for any practical purpose Now if we do zoom out Back to our what were we doing minus seven to seven? And have a look at this Extremely large series of 300 terms. Well, we we see those tiny spikes which Mathematica is plotting for us But we see that it's it's really getting extremely close now to the switching function we asked for Let's just whack in a crazy number. I'll just add a zero on here And that took Mathematica a tiny fraction of time to actually work out But that overshoot is let's let's home in and see if the overshoot is still there. Let's go from naught to I don't know 0.01 There it is we're incredibly zoomed in now Um, but it's it's still there. It's still making it nearly up to 1.1 before correcting back So, uh, that that is, you know, that's the answer it works In the infinite limit, it would still shoot up to 1.1 But now with zero width the width of that little overshoot would vanish And we would by any reasonable measure say that we have converged To the function that we wanted now, let's quickly go back And we can go a bit faster this time and work out the triangular wave as a quick second example Because for that one, uh, that was the very example that we started the first lecture with and we said, oh look Uh, cos terms add up to something interesting Let's now see if we can derive what the what the expression that I was using when I just typed in The uh, the interesting example. So let's switch back and finish that What we need to do is draw a triangular wave We, you know, we could draw a bunch of things that are essentially versions of the triangular wave. It's up to us. We're, um How it aligns in terms of uh, what value it has at the origin and so on, but I will go for this one Which might be the easiest certainly the first thing to think of And uh, one of the reasons I'm drawing this is that this is obviously going to be An even function and that's as we found out going to make it just a little bit easier to Not so much easier just quicker to do the work. So, um, I want my triangular function by the way to go from pi um, because again, that's going to keep things nice and easy in terms of the constants because I can I could have chosen plus one. It's going to go from some value, right? uh to um Zero the complete cycle is two pi and so of course the point here is pi and minus pi and so on So that's the function I now want to analyze. I know my Fourier series expressions But I also know that because this is an even function I there's no point in even thinking about the sine terms. They must come to zero So the bn are equal to zero for all values of n and only the an need to even be talked about And for them, it's the integral from naught to well over one complete cycle It's the way we like to say it. So it would be the uh, we can certainly integrate from naught to um Two pi if we want but as we were discussing before we can make that from minus pi to pi if we like and in fact I do like to do that in this case so As is generally the case when we're trying to exploit the properties of even and odd functions to make our integrals as quick as possible So now I would say that that is the integral um of cos n x times our function f of x I suppose I should really Not just define it by a um a diagram, but make a little bit of room and just think how would we write that? mathematically So there we are that's the definition of our function. Let's get back down to what we were doing Which was actually working out these constants. How are they going to come out? Well, okay So it's an even function times another even function. So this integral in particular the the integrand here Is a product of two even functions cos is even and we know our f of x is even Two even functions their product is also an even function because neither of them care about the sign when you feed Minus x in they give you the same thing as if you fed in plus x and so their product also has that property So now it's the integral of an even function between symmetric limits And because of the mirror like property of even functions that we saw in the last lecture That means that all we have to do if we want is to integrate Let's say over the positive half of that range Ignore the negative half and just times by two because the negative and positive integrals must be Equal to each other so that we would do that trick to save a little bit of time So what we just write down is that it's two Times the integral from zero to pi of cos nx and then we only need to take the function definition for that positive range And that's the whole job that we need to do What have we got? Uh, we've got a good old, uh, normal Cause so let's separate it at this point into two expressions cause of nx dx Mm-hmm. Now I can see what that's going to do Which is to say it will come to nothing, but we'll work it out minus two Uh integral x cos of nx dx Well, that one looks like it might be the slightly tricky one. Let's do the first integral and As promised, I think we'll find that this will come to zero. So let's get the two pi out in front integral of cos is sine of nx divided by n between nought and pi Um, so that is two pi Uh, take the n out sine of n pi minus sine of zero, which is zero but Sine of n pi what is that n is an integer to remember. So, uh, Sine of pi sine of two pi sine of three pi sine of four pi all of those are zero because that's exactly the points where the sine function crosses the x-axis. So that whole thing is zero. So we only care about the second term. Let's uh focus on that one So we're saying that a of n is equal to uh minus two times This second integral, which we'll do this one here We'll do that integration by parts. If you don't know what integration by parts is then Well, that's an interesting thing to to find a lecture on but I I guess I'm not trying to teach integrals here But the trick is it's a product of two functions. So we can do We can choose one of those functions and integrate it and the other one and differentiate it And so we will integrate the cos to make it into sine So that will become x times sine of nx over n Between the limits and then we need to subtract off a new integral that Has the differentiated function x, which just goes to one and then also of course sine of nx dx now, uh, this first term is going to give us zero For exactly the reason that we had above which is that um when we have sine of n times pi It will be zero. So that first term is going away And we are left with only the second term and when we, uh, cancel the sines Yep, I was worried about the sine, uh adding because I I recall that the answer here should come out positive a bit positive But it will because we have minus two minus one over n which gives us two over n But when we integrate sine Uh, that gives us cos but minus cos And that's what I was failing to remember momentarily And that is from naught to pi. So what we end up with is, uh now going to be two over n squared And then, uh, the zero Is going to give us a cos of zero which is one and then minus cos of n pi But we already discussed that cos of n pi is actually minus one to the power of n And so what we have here in the end is that the an constant Is going to be equal to two over n squared times two. So actually four over n squared That will be the case when n is um odd because then it will be this term here will be one minus minus one Which is two on the other hand when n is even it will be one minus one, which is zero So we need to write that it's four over n squared if n is odd But it is zero if n is even And that is now, uh, we're now ready to write down our Fourier series using that rule Except that um We uh Need to be a little bit careful. There's a trick here Our expression for an that we've been working through faithfully here Works for all values of n including n is equal to zero however I when I was rushing through this uh It was all legit until We needed to integrate the things that involved cos of nx And we ended up dividing by n which of course is not correct if n is equal to zero That would give us an infinity and the reason that's gone wrong Is that really for n is equal to zero we should be writing cos of nx is just One so we need to do that as a special case, but fortunately, it's a super easy special case So we can fit it in this little space at the top for a zero We should be integrated. Uh, in fact, we can still uh use this line here Because that's before we tried to integrate cos of zero x um So that would be from null to pi of simply one times pi minus x d x And uh, so that is the integral of just a constant is the first term there and then the integral of minus x So we can simply do this. It's going to be um Just a pi squared And then the minus x term is going to give us minus x squared So let's just write that that that one we can write I think that's going to be minus x squared over two From uh, null to pi But that will just give us minus pi squared over two. So in fact the result is Pi squared over two. So that is a little bit of a tricky fiddly element there Almost a downside to the compact way that we're writing our a n coefficients So that the special one the a n where n is zero, which gives us the constant term in our Fourier series It's still within the same prescription But then we need to watch it that we're sometimes going to be integrating cos of n x and n might be zero in which case Cos of n x isn't actually a function of x. It's just the number one So we need to splinter off that case and do is it as a special case Um, and then then we're fine. So a n a zero is equal to pi squared So uh, that's um, you can add that down to our special cases here. In fact Just summarized it at this point So we are saying that it's pi squared over two if n is equal to zero and then these other two cases that we'd already figured out There we are. So now we can write our Fourier series and what we're saying is that f of x Is going to be equal to well that constant term We just talked about plus and then only the causes and only the causes which have a an an um odd So cos one cos three x cos five x and so on an odd multiplier of x So we can do our trick if we like of saying let's go from n equals zero to infinity, but write cos of uh two n plus one x And then we do need to divide by that That integer squared So that's the same trick we did before where we just generate only the odd numbers by doubling it adding one That's it. That's our Fourier series. That's our proposed answer to uh, the challenge of coming up with our triangular wave And now uh, we can just zoom over to mathematical to see if this works So I'm just going to stare at this to memorize it Yeah, pi squared over two Oh, and I missed off. Excuse me. We do have a factor of four that can come in front there That was from the fact that it was actually four over n squared So I'm memorizing that I'm coming gonna come over to Mathematica So are we doing that correctly? Yes, it's what we are asking for because we've got uh, cos Three x over nine cos five over 25 seven over 49 and so on It's probably looks pretty familiar compared to the triangular wave we constructed last time But nevertheless, let's see if we've actually got everything scaled correctly. So it will work out So we no longer need to see that we'll put in a semicolon and we'll just write plot f for x, um, I don't know minus seven seven like we did before And see what we get and we'll need to And there it is. It's certainly a triangular function. Let's um, scale it. So it's a bit, uh, that's gigantic And we can fit everything nicely on the screen. There we are now So it looks persuasive. It's dropping down to zero at pi and at minus pi. It looks good Looks like the triangular wave we were seeking But I think that's enough for this lecture. So thanks a lot for listening and remember that if you would like to hear a slightly We'll see a slightly different explanation Then look in my notes the examples I've focused on here I've tried to make them consistent with the notes So they just slot right in there, but the narrative around it will be expressed a little bit differently Thanks for listening