 Yeah, so in yesterday's class we looked at box functions right and we saw that we could use a whole set of box functions to represent any given function right. I was originally planning to do hat functions today but first maybe we will look at polynomials and functions as means of generating basis vectors say on a given interval right and see what is the problem with that and then we will go on to hat function is that fine. So the question is the problem that we had with the box function was that even for a straight line if you wanted to approximate the straight line we got because our function is a constant on a given interval. We got a representation which was piecewise constant right and we could get as close as we want to the function that we are trying to represent but then as a consequence the jumps that we get the number of jumps that we get in the function representation increases right. So we are trying to ask the question is not there a way for us to get something that is smoother. We have defined the dot product yesterday as the dot product of f, g as the integral if the functions are defined on the interval a, b as fg dx. We will see what this means if we just take an interval again say 01 or something of that sort and what it means to the standard polynomials that we deal with okay and see whether we can use those to represent our functions. So consider the functions two functions f of x equals 1 and g of x equals x to start with are these functions orthogonal to each other or what is the angle between these functions does that make sense. So once you have defined the dot product we can use the definition of the dot product that we had earlier from geometry where we said that a dot b is magnitude a magnitude b cosine of the angle included angle between them you can use a similar idea and basically say that cosine of the angle between two functions would be the dot product fg divided by the norm of f norm of g right analogous to what we did with vectors you could define a theta in a similar fashion. So the question that I am asking so we have already used actually we have already used the property that theta is pi by 2 is that the two functions are orthogonal we have already done that yesterday. Question that I am asking is it possible for us to find the angle between the functions f and g as given there okay. So what is f dot g what is that dot product integral x let us say the functions are defined on the interval x belongs to the interval 0, 1 let us say we take x from on the interval 0, 1 the function is defined on the interval 0, 1. So it is 1 times x dx which gives me x squared by 2 between the limit 0, 1 which is one half that fine. So clearly they are not orthogonal clearly they are not orthogonal what is magnitude f magnitude f is the square root of integral 0 to 1 dx which is 1 and what is magnitude g the norm of g integral 0 to 1 x squared dx square root which gives me x cube by 3 between 0 to 1, 1 divided by square root of 3 is that fine okay. And therefore of course all of these numbers look familiar because we just dealt with something very similar in the last class and therefore what do we get for cos theta 1 by 2 root 3 and you can consequently find theta. So it is just an interesting exercise you can consequently find theta what does it mean on which side is there a mistake root 3 by did I goof I made a mistake oh I am sorry I root 3 by 2 I am sorry root 3 by 2 it gives a much better number right gives you a much better angle okay right. So but I am not really interested in finding theta here right or I realize that theta is not pi by 2 okay and we have already seen earlier that it is very convenient to have these functions or the basis vectors that we get to be orthogonal to each other right we have already seen that it is convenient to have these vectors orthogonal to each other. So given this we will follow the same process that we did earlier and try to get 2 sets of vectors 2 vectors which are perpendicular to each other from the 1, x so 1, x are linearly independent 1 and x are linearly independent how do I find how do I get 2 vectors so that that angle is pi by 2. So what I do is I repeat what we did earlier so if this is a and this is b right so from a of course I can get the unit vector a little a which is a hat right and I can find the projection of b on a how do I find the projection of b on a I take b dot a okay. So b dot a gives me the projection the component of b that is along a right b dot a gives me a component of b that is along a let me just give it a subscript b sub a b sub a times a hat what is that that is a vector representation of the component of b along a right. So if I subtract this from b b minus b sub a a hat and I call that what should I call that I just call that b prime what is b prime b prime is the vector b with its projection from a removed from it okay. So now the question is what is b prime dot a b prime dot a is 0 so we have managed to construct we have managed to construct the b prime which is orthogonal to a and from b prime from b prime I can get a I will just call it a b hat by dividing by the magnitude of b prime okay. So you gave me a b to start with and I come back with an a prime b prime I am sorry a hat b hat which are unit vectors which are orthogonal to each other okay so you have given me one set of vectors I have now managed to extract from that a hat b hat which are orthogonal to each other. So if I had a third function if I had a third vector c I could repeat this process if I had a third vector c what I would basically do is from the third vector I will subtract out the b hat part I will subtract out the a hat part and I will be left with something that is purely c right if I am left with nothing that means c was linearly dependent on the other two is that fine okay. We will do that now to the functions we will do that now to the vectors 1 and x so back here we asked the question what was f dot g, f dot g was 1 half so this is this times 1 so the function that is along that is the component of f that is along g or g that is along f is 1 half it is g along f right and f is a constant and therefore if I subtract out if I repeat the process b minus b prime a b minus b dot a if I repeat the feed that process what I am going to get is I am going to get x minus 1 half times 1 the basis vector is just the constant function 1 okay and this should be now my new improved this should be now my new improved g prime is that fine okay. So can I make this a unit vector is it possible for me to make it a unit vector g prime how do I make g prime the unit vector so what is g prime dotted with g prime x minus 1 half squared dx on the interval on which it is defined which is x minus half cubed between 0 and 1 and what is this 1 half cubed plus 1 half cubed I am sorry which equals 1 4 to z right into oh I am sorry x by 3 by 3 fine okay and therefore g hat g if you want to call it g prime hat if you want to call put a hat on it just like we did for the other unit vector or I just call it g hat g hat would be x minus 1 half I have to divide by the magnitude in the magnitude is 2 times square root 3 are there any questions it is fine. So now we have the vectors 1 2 times square root 3 into x minus 1 half is that fine these are orthonormal magnitudes are 1 and they are orthogonal to each other okay let me add a third vector into the mix what if I added x squared I want to add x squared so I define an h of x which is x squared if I define an h of x which is x squared and this is still on the interval 0 1 if I define an h of x which is x squared what is g hat dotted with h that is 2 root 3 x minus 1 half into x squared integral from 0 to 1 dx is that fine yeah so what does this integral give me this gives me a 2 root 3 into that gives me a x to the 4th divided by 4 minus x cube divided by 6 between the limits 0 and 1 which is 2 root 3 times 1 fourth minus 1 sixth what does that give me 1 by 2 root 3 so that is the component of h along g hat so we repeat this process so from h that is x squared I subtract out this component so that is 1 over 2 root 3 times what is the basis vector 2 root 3 into x minus half I am repeating the same process that I did here b minus ba times a I am repeating the same process that I did there which of course gives me x squared minus x plus half and there is something wrong we have to okay that is fine so what is the other thing that we have that is x squared minus x plus half yeah that is fine so what do we have now so we have removed the g hat component this is has removed the g hat component so what I will call this is h hat h prime now I want from this I want to get rid of the component that belongs to 1 the function 1 so what is h prime dot f that is integral 0 to 1 x squared minus x plus 1 half times dx which gives me x cube by 3 minus x squared by 2 plus x by 2 between the limits 0 and 1 and that should give me the projection of h prime on f which is nothing but 1 by 3 minus 1 by 2 plus 1 by 2 which is 1 third that is fine and as a consequence if I subtract this out from here I am going to get h double prime which is x squared minus x plus 1 6 minus x plus 1 6 okay if I subtract a third from the half I get 1 6 and I will let you verify you can verify that h hat in fact is 6 times 5th root of 5 x squared minus x plus 1 6 and just check that out find out what the magnitude is if I am taking the no I am taking you are saying do g instead of g prime and whether I take h prime there or h it does not matter you are saying why did not I just do x cube instead of x squared times 1 whatever that is fine yeah yeah the order does not matter the order does not matter what you have to basically do is you have to make sure that if you have a set of vectors that you are subtracting out this and this from x yeah that is true you could what you are basically saying then the expression is a lot easier I did not I did not have to include that x plus half because anyway it is orthogonal that is true yeah yeah because the part that I am subtracting out you understand the point that he is making the part that I have subtracted out here it basically comes from is already orthogonal to f so there is no reason to include that in the calculation is that fine okay yeah are there any questions so you can see you can see that excuse me you can see that now I have I will call them f hat g hat h hat you can see that I can actually generate a whole function a whole set of these functions okay in fact I can just take I can take the set 1 x x squared x cube x to the fourth and so on and I can I can generate a whole set of these basis vectors that are orthonormal orthogonal to each other and the magnitude is 1 right based on our definition of the dot product is that fine okay now why do not we just use this why do not we just use this to represent our functions right why not just use this to represent our functions so that is one question that we have why bother with box functions these are nice and smooth functions why not just use these to represent our functions is that fine okay of course if our function had a cubic variation and we took only the first term first three terms right we are unlikely to pick up that cubic variation properly am I making sense you can see what you can go check to see what kind of an error that you would make and so on the other problem is just like in Fourier series maybe we look at Fourier series a little right now just I am not sure how many of you are familiar with Fourier series there is the issue of how do we when we have when we are hunting remember do not forget why we are doing this why we are why we are constructing these orthonormal functions right just to recollect our governing equations or differential equations the solutions are functions we want to write programs that will systematically hunt for the solution which means systematically hunt for the functions so we are trying to create a set of functions which have some structure in them so that we can search them in a systematic fashion okay so such a set of functions right such a set of functions which have this nice structure what is the distance between functions and so on such a set of functions we will call it a space a function space a space of functions right and we are basically trying to construct a function space that is essentially it okay so let us let let let us see let us see what happens let me we will get by maybe what we will do is we will do Fourier series also we will go along and then see what is the issue with what is the issue why can't we why do not we use this right and we do use it sometimes let us let us see what we get now one of the points that I want you to check out you can try this out now if I take the same functions 1 x x squared and so on I take the same set of functions but now they are defined on the interval minus 1 to 1 does anything change does anything change so what happens to f.g becomes minus 1 to 1 1 times x dx is x squared by 2 from minus 1 to plus 1 and it is 0 they are orthogonal so the orthogonality depends on the interval in which the function is defined the dot product is defined over that whole interval it may be obvious right when you look at it but the number of times students make a generic statement sign sign and cosine or orthogonal to each other and then integrate on the wrong interval right it happens it happens to all of us right so you have to be a bit careful it is orthogonal from minus 1 to plus 1 but not orthogonal on the interval 0 to 1 okay I would suggest that you try to do a few of these on the interval minus 1 to plus 1 just like I I have gone through right so for on the interval 0 1 I would suggest that you try x cubed or something of that sort just to make sure that you are able to get through on that and then do these from minus 1 to plus 1 do a few of them okay and if you have had ordinary differential equations if you had a course in ordinary differential equations before pay attention to the functions that you are getting and ask yourself have you seen them before right you should get a familiar set of functions right especially if you have done a course in ordinary differential equations this interval minus 1 to plus 1 should give you should yield a familiar set of functions right let us look at I am not going to do Fourier series in great detail here so Fourier series the functions that you are looking at are of the form 1 sin cosine sin 2 cosine 2 and so on they are functions of this nature okay so the obvious question from this discussion the obvious question is is are the functions 1 and sin orthogonal to each other right so now you should always remember you have to ask the question on what interval are we talking right what is the dot product definition the dot product and what is the interval on which we are talking so if you say that on the interval 0 to 1 sin of x dx not 0 right on the other hand if you take say on the interval 0 to 2 pi sin of x dx you do get 0 fine so the functions 1 and sin are indeed orthogonal are indeed orthogonal on the on that interval and of course you can figure out how to go about normalizing it and so on so the point of this discussion is that the interval the domain on which we are we are defining the function is important right for our for our idea of orthogonality just as it is important for our idea of the dot product and of course when we are actually solving problems when we get to the point where we are actually solving working on fluid mechanics problems and asking questions and answering questions and fluid mechanics you will have you will know what is the extent of your domain and therefore you will know what are a and b fine so why don't we just use this why don't we just use 1x x squared and so on why not just use Fourier series right to fit so if I give you a function if I give you a graph if I give you some arbitrary graph why not just use these polynomials in order to approximate this function to represent this function why did I why do I go through this headache of trying to find piecewise constants that will approximate the function okay the idea here is that if I have if I have my f hat g hat h hat that I got earlier that I got here if I have the f hat g hat a hat I can try to find a f hat plus b g hat plus c h hat I can try to find the coefficients a b and c in order to approximate this function and then adjusting adjusting these values while I am hunting for the function any change I make to a will translate the whole graph up down any change I make to b will cause the slope to change any change I make to c right will cause the curvature to change everywhere keyword is everywhere right so if I am if I am now if I have this complicated function and I am trying to fit a curve to it every time I adjust one coefficient every time I adjust one coefficient to fit some part the trouble is it is going to get spoiled somewhere else very likely that it will change somewhere else I do not have what is called the property of locality I do not have this power where local changes local changes in coefficients cause only local changes in the function I want to be able to I want to be able to raise and lower this whereas if you take this box function it is possible for me to take this and lower it there independent of what is happening elsewhere I can just change the level of just at one interval right so the box function clearly has this property of locality I can just change in one interval I can change the level I can change the level of that function just in one interval without affecting anything else that is happening elsewhere okay. So this property of locality is very important this property of locality gives me this freedom gives me this freedom for me to adjust my solution as I go along okay without in particular without affecting other parts of my solution that I have already possibly adjusted to my satisfaction right whereas if I do not have locality if I do not have locality then a change any change that I make is a global change right so if I say a sin x if I change a sin x is going to change in fact if you think about it sin x actually defined from minus infinity to plus infinity so you are changing everything from minus infinity to plus infinity just by changing the same right total global change whereas what I would like to do is I would like to keep it local fine okay. So for that reason right now I am going to reject using f hat g hat h hat right having gone through this effort I basically say it is nice I know how to do it but I am going to reject this function okay we can come back later and see whether it is possible for us to use them or not what we would really like is we would like the smoothness that these polynomials bring and the locality that the box function got we would like to have the smoothness that these polynomials bring with tight to the locality that the box functions brought okay and therefore as a consequence now merging these two we are going to come up with hat functions we are going to define this as follows what we realize is if you have some from the yesterday's class we know if the support of two functions is non-overlapping is not overlapping then they will be orthogonal they are orthogonal to each other there is a reason why I repeat this there is a reason why I write this out and repeat this. So it has only to do with the support right remember the support basically means the function is non-zero in that part of the domain right so it has only to do with the support it does not actually have to do with the function value that means that if I have in yesterday I chose functions f and g in a fashion such that the support was non-overlapping this was f that was g and yesterday we basically said that f.g because the support is non-overlapping it turned out that f.g are orthogonal to each other the question is does it have to be a constant there it could be anything as long as it is not 0 right is that fine. So since this is true since it comes from the support what we will do is we will try to pick one of those polynomials to do it and to keep life easy we are going to pick the linear we are going to pick x right we are going to be a bit careful here so we pick x. So let me see if I can construct these functions in a systematic fashion so we have some interval a b that we are interested in right and as we did earlier we are going to break up this interval into sub-intervals I am going to look at focus on one particular sub-interval x i x i plus 1 okay so I will zoom in on that particular interval so what I am going to do is I am going to just zoom in on this particular interval that is x i x i plus 1 and I will define two functions here I will define two functions here one is a function it is basically 0 everywhere and at x i it is 0 and it then rises from x i to x i plus 1 it goes from 0 to the value 1 I will name this function n it is 1 at i plus 1 i plus 1 0 because I am going to define two such functions. The other function is also 0 everywhere right just like the box function the only difference is that it drops from 1 to 0 going from x i to x i plus 1 and since this function is 1 at x i I will call it n i and it is a second function so n i 1 is that fine do you understand what the functions do the blue one n i plus 1 0 is 0 everywhere so it is going to be 0 from a to b everywhere except on the interval x i x i plus 1 where it starts at 0 and in a linear fashion rises to 1 n i is again 0 everywhere over the whole interval a b except at x i x i plus 1 it starts at 1 goes down to 0 fine now clearly if I have two such functions clearly if I have two such functions on two different intervals if I have two such functions on two different intervals if I have one interval here and I have another interval here and if I have two such functions on these two different intervals I have one function here and at the same blue one function here one function there and one function here one function I have two such functions right this is n i plus 1 0 n i 1 this would be n j plus 1 0 n j 1 I have two such functions these two functions are orthogonal to those two functions each of these functions is orthogonal to each of those functions if I define such functions over all the intervals x i x i plus 1 in any given interval one of these functions will be orthogonal to functions in the other interval because intervals are non-overlapping fine so we use the fact that the supports are non-overlapping therefore they are orthogonal that is a good part but what about the two functions to each other the two functions obviously to each other are not orthogonal right they are obviously not orthogonal so what is that dot product what is n i 0 n i 1 I am sorry n i plus 1 dotted with is a function of x n i 0 is a function of x dx the integral it is 0 everywhere except from x i to x i plus 1 what is this function what is this integral so in order to do this we have to get a function form we have to get an algebraic form for n i and n i x okay I have to get an algebraic form for n i and n i n i plus 1 and n i plus 1 n i plus 1 x and n i x okay so we come back here what is n i plus 1 as a function of x x minus x i divided by x i plus 1 minus x i right there is a positive slope there is a positive slope over the length x x i x i plus 1 minus x i it goes from 0 to 1 right so at x equals x i it is 0 at x equals x i plus 1 it is 1 it is a linear function it satisfies it satisfies right again we are hunting even here if you think about it we are actually hunting for functions right I have given you a graph and we hunted and found that function okay and what is n i so if this is some alpha of x if this is some alpha of x I name it alpha of x simply because so what is n i 1 minus alpha of x are there any questions any questions fine so what we do is what we will do now is we will find out what is that what is the what is the dot product what is that dot product so n i 1 dotted with n i plus 1 0 gives me integral x i plus 1 to x i up x i to x i plus 1 alpha of x times 1 minus alpha of x dx what does this turn out to be you can just check that you can just verify that that is true so that fine okay so what do we have now what we have now is I have defined a bunch of functions n i 0 and n i plus 1 these depend of course on the interval so obviously if I go to i minus 1 if I go to i minus 1 this is on the interval i i plus 1 if I go to the interval i minus 1 to i what will I get corresponding functions n i minus 1 0 n i 1 am I making sense if I go to the intervals i minus 2 i minus 1 I will have the functions n i minus 2 0 n i minus 1 1 fine on each of the intervals I will have two of these functions what have we managed to do so far what can we do what can we do with these two functions that we have defined on the interval so first let us just focus on this interval alone we will just look at this interval alone so if I take a i a i or a times n i 1 plus b times n i plus 1 0 as some function f of x defined only on xi xi plus 1 what does this give me for any given a b what does the graph of this look like it has to be a straight line is the sum of two linear elements and if I were to graph it if I were to just graph f of x remember this is the interval xi xi plus 1 if I were to just graph it at x equals xi n i is 1 at x equals xi plus 1 n i plus 1 is 1 the other one is 0 so this is going to be a function that goes from a to b in a linear fashion so if I change my b value if I change the value of b if I were to raise the value of b from here to some value here then I would get a graph that looks like that right so I have a linear interpolant but I also have locality in the sense that if I raise this value a b it affects this interval and we will see if it affects anything else is that fine okay so a i a n i b n i plus 1 allows me to give you a get a linear interpolant in the interval xi xi plus 1 so in general if I had an arbitrary function f of x I should be able to write this f of x as summation i equals 1 through n I will just write it as 1 through n we have to figure out what happens at the intervals elsewhere towards the beginning and end anyway we will go through we have n n intervals i equals 1 through n what am I going to get a i n i 0 plus b i n i plus 1 1 is that fine the intervals are non-overlapping they are orthogonal it should be possible for me to represent any function f of x in this fashion on any given interval the a i b i will give me the straight line interpolant between those two points okay let us take two intervals and see what happens let us take two intervals and see what happens so this is xi minus 1 xi xi plus 1 okay so I have some function I have some function and I want to represent this function using my newly developed right linear interpolants so what I am going to do is I am going to use let me use some colored chalk here on the interval xi xi plus 1 if I take these two values to be a and b I will get a linear interpolant that looks like that on the interval xi minus 1 xi what will my a value be what is a a is the value here and what is b b is going to be what was the a and b xi xi plus 1 interval so in fact though it looks like though it looks like though it looks like I have two coefficient incidentally it is possible we could come up with a scheme just like in the box function if you are willing to allow discontinuities at this interval at the edge of this interval at the interface between the two if you are willing to allow discontinuities then a's and b's can be sub different but if you want the function to be a continuous function the representation to be a which is where we are going right now then the a i corresponding to xi right has to be the b i corresponding to the xi okay so the a and b at this point have to be the same is that okay everyone okay so in fact what you have to do is we have to recombine these so you are saying a i n i b i n i plus 1 so maybe what I should have done here was I should have made this b i plus 1 i plus 1 n i plus 1 okay if I make that b i plus 1 then what does that do for me then I can actually make the statement that a i should be equal to b i allows me to do that so the coefficient here is the same and what are the functions what are the basis vector what are the basis vectors n i n i is that it multiplies this coefficient a i what does it multiply it multiplies this is one or let me let me lower the let us just say this is one it multiplies this function what is this function what was this label n i 1 and it multiplies this function what was its label we have did I switch it around n i 0 n i 1 I have it right the first time around okay fine n i 0 yeah n i 1 I had it right the first time around okay there in the integral okay I made a mistake here okay that is fine yeah you guys should tell me immediately as soon as you catch it I have flipped it around everywhere thank you yeah you should not let me go through with this well fortunately what is going to happen is I am going to get rid of those superscripts okay fine look at the functions n i 0 and n i 1 n i 0 and n i 1 are non overlapping I can actually combine these 2 functions I can add them up I can literally add them up since a i and b i a i and b i are the same a i equals b i equals same this summation summation i equals 1 through n right since a i and b i are the same I have to just shift this so if I go back to when this was i – 1 i equals 1 or if you want me to I can write it out but anyway it is okay if I factor out the a i since the a i and b i are the same I am going to get what I have seen here is I am going to get an n i 0 plus an n i 1 that summation f of x you can open out the summation for a few terms and see that this is true okay it is actually possible for me to factor out the a i since a i equals b i it is actually possible for me to factor out the a for n i 0 and n i 1 these can be added these can actually add and if you add them this is the function that you get okay so this is summation i equals 1 through n a i n i I will rewrite this summation I will rewrite it at the other end. So f of x can in fact be written as summation i equals 1 through n a i n i where n i of x equals n i 0 of x plus n i 1 of x is that fine 0 to n – 1 as I said so we will have to look at what happens through because there is an issue so I leave these we will investigate I just write this just for right so we have to really look at what happens what happens for all these okay. So now for so the end points we look at what happens at the end points look at what happens at the end point you have to be a bit careful at the end okay right so what is this function n i what is the graph of the function n i so if I have x i I have x i – 1 I have x i plus 1 this is n i as a function of x it is 0 it is 0 from a to x i x i – 1 it rises it rises to 1 linearly drops to 0 at x i plus 1 linearly this again 0 okay and because of the shape of the function these functions are called either hat functions or tent functions you can imagine that if you construct functions like this in two dimensions that they look like a tent they are called tent functions or hat functions is that fine okay are there any questions okay so then we will continue with this in the next class.