 Okay, so this morning we will continue with representation of numbers. Let me just get back to where we were what we did in the last class. We saw that computational fluid dynamics that we are going to solve equations, differential equations that come from fluid mechanics. The solutions to such equations are functions and these functions in order for us to be able to solve these equations, both the differential equations and the functions have to be represented on a computer. That is the idea. So to that end we decided to represent various mathematical entities on a computer. We started the way that you have learnt calculus that we started by saying that let us try to represent the real line on the computer. And what we have basically done now is we have tried fixed point. We have done integers. We have finally come down to floating point. I have asked you to look up IEEE 754 standard. I gave you what is used for what is the format that is used for single precision, single precision or a float or in fact I asked you to look up this file on your computer, locate where it is and look up this file on your computer and just to recollect for a float or I have used the word now single precision as opposed to double precision. So we have indicated that the first bit was the sign bit. We used the next 8 bits 1 through 8. We used them for the exponent. Again I remind you that please go look up Big Endian and Little Endian. Then the remaining how many are the 23 bits going from 9, number, 12, 31. Please remember we started the count at 0. The remaining bits are typically used for the mantissa. It is possible that if you have come across something called the NAN not a number you will see that maybe there are 22 bits and you look up the standard and you will find out about it but I am not going to really talk about this now. So we have 23 bits which are the mantissa. To this end I had asked you to try out an experiment in which I hope that you guys have tried which is to ask the question is there a positive what is the smallest positive epsilon, smallest positive number such that is epsilon 1 plus epsilon, smallest positive number such that 1 plus epsilon is different from 1 okay. I had also said that there is an alternate definition. You can also look for the largest positive number such that 1 plus epsilon equals 1. Is that fine? So that is a possibility. So we had written a piece of code for pseudo code for this. I had asked you to try this out. So you let epsilon, epsilon in fact I think yesterday I had used a different symbol for this. I had used that okay. Epsilon equals 1 as a start and you can say while 1 plus epsilon this is a candidate epsilon is greater than 1. So it is not equal to 1 or you can also say not equal to 1. Divide epsilon by 2. This is something that I had suggested that you do. Try it out. If you have tried it out you will see that you will have a variety of experiences that you guys would have had. Some of you possibly for float double and long double right. You may have got different answers for these but depending on your experience some of you may have got the same answer for both of them. So you have to ponder why the epsilon sometimes comes out the same for both of these and what does it mean with respect to what is the accuracy with which we can calculate make our calculations. Is that fine? So this is single position. You try to relate this to the size of the mantissa that we have. So that is what we are really measuring here. When we do this epsilon what we are essentially doing is we are asking the question with respect to 1 what can we resolve and what we can resolve is given by the size of the mantissa. So you please check the epsilon that you get and compare it to 2 raise to the power minus 24 and I have explained you why it is 24 yesterday and see what is the relationship between what you printed out and what you have got here. So what is the next deal? So before I go on with discussion since I have got that up there let me just tell you that there is a double which uses 64 bits. This is double precision in Fortran or real star 8 depending on what you are used to I usually say real star 8 double precision is much longer to type. So we would like I mean we would have liked it if the 32 bits that you added here had been added directly to the mantissa unfortunately that is not happened. So what happens in this standard is that you have the sign bit just like you had in the single precision and 11 bits 11 bits 1 through 11 are set aside for the exponent and the remaining how many would that be 52 bits remaining 52 bits 12 to 63 are set aside for the mantissa. So this would be double precision is that fine okay. So now that I have told you this let us step back and ask ourselves the question if we are performing computations using single precision or double precision and associated with it there is an epsilon what are we actually doing what is the computation that we are actually performing. So let us go back to the real line that we had yesterday and zoom in on around 1 what is it that we are actually doing. So this is 0.0 this is 1.0 well in fact I would not indicate 0.0 0.0 is somewhere there right I mean it is far off I am going to really zoom in and this is basically epsilon right. So this is minus epsilon 1 minus epsilon and this is 1 plus epsilon and what we are essentially saying here is any number in this any number here right basically maps into 1 that is essentially what we are saying that is if you give me an epsilon if you give me a sufficient epsilon if epsilon sufficiently small any number that would actually fit in here ends up being 1 that is essentially what it says that when you say 1 plus epsilon is 1 what you are effectively saying is you give me this epsilon and it is going to turn out that when I add it to 1 I am still going to get 1. So any epsilon this neighborhood is actually it is like a mush factor that I have mush area that I have here the 1.0 that I 1.0 that I use on the computer as opposed to 1 that I use when I talk mathematics the 1.0 that I am talking about here actually represents an interval this represents this chalk does represents the idea of 1 this chalk does here represents the whole interval 1 minus epsilon to 1 plus epsilon. So when we are adding 2 numbers together that is when we add say 2.0 to 1.0 plus 1.0 actually what you are doing is you are adding 2 intervals there is an interval associated with this number 2 there is an interval associated with this number 1 and we are actually adding these 2 numbers together is that fine. So basically the arithmetic that we are doing is not the standard mathematical arithmetic that we do but what I would say is interval arithmetic there is a lot of interest in this interval arithmetic. So you have to ask the question if you have a comma b plus c comma d what would that turn out to be if you had a comma b plus c comma d what would that turn out to be. So a comma b plus c comma d will turn out to be a plus c comma b plus d in a similar fashion in a similar fashion if I were going to go with subtraction instead of addition so you try these operations mathematical operations please try the operations minus multiplication and division with intervals instead of actual numbers and that gives you an idea as to what is the nature of the arithmetic that we are doing. So if you say that I have if I have 1.0 you now have an uncertainty as to actually what the original number was you do not know whether it was one or it was something else that became one. So we now introduce for the first time an error associated with an error associated with we now introduce for the first time an error associated with this representation I will call the general error since we are talking about representations on a computer we will call the general error representation error okay. The representation error is the difference between a mathematical entity and its representation on the computer okay so that is a very general expression so if you have any mathematical entity and you want to represent it on the computer the difference between the mathematical entity and its representation of the computer would be representation error. So in this case if you had some number that was actually of the order of 1 plus epsilon it would be represented by 1 that is what we are saying it would be represented by 1 and the error that you have is of the order of epsilon is in fact epsilon in this case if it were 1 plus epsilon. So this error for numbers is called round off error so it is a particular type of representation error called round off error okay. So round off error is a problem that we have so now first we know when I say that I am representing numbers I am actually representing intervals that when I perform arithmetic I am actually doing arithmetic of intervals and if I say that I add 2 numbers a plus b to c plus d it is very likely that the result is actually more uncertain possible more uncertain than what we started off with. So there is this uncertainty associated with these numbers that we have and if I just take a number just represent the number then there is an error associated with it which is the round off error. In the last class I have already indicated that on the binary system even 1 by 10 even 1 by 10 is recurring right. So 1 by 10 because 1 by 2 though it can be represented exactly 1 by 10 has a problem because 1 5th is a recurring number and if you truncate it to 23 bits in the mantissa then somewhere along the line you are going to stop the end off. So you are going to end up with what is called round off error so I hope that is quite clear. So we have this thing now so we have known that we cannot represent the real line exactly and we know that we have made a selection of what are the points on the real line that we are going to represent. However it seems that associated with that decision there is associated there is a connected round off error and we have to deal with that connected round off error okay fine. So this is as far as representing numbers goes on the computer let us see what else we can do what are the mathematical entities are we interested in we are interested in vectors for instance. So if you want to represent vectors okay as I said I am not going to say much about computer architecture and so on. However it is important for us to know that computer memory in our mind the model that we have of computer memory is linear that is that is in you have the zeroth location of memory first location second location third location it is computer memory occurs in a linear fashion it comes one after the other in a linear fashion. So if I wanted to store a vector and vectors in matrices of course is what I told you that I would do at the in the beginning of yesterday's class but however vectors in matrices have associated with them various operations and properties in reality what I am going to do is I am going to represent arrays I will call them arrays just to distinguish from vectors in matrices right. So though I promised vectors in matrices what I am actually going to give you is an array and when I say a vector what I mean is a one-dimensional array. So one-dimensional array AI has one subscript right so I do not care whether it is a column or a row here right now but because memory is linear what I will do is I will represent I will store right so on the computer we will store or your compiler will store the arrangement is made automatically. So if there are n of these since I am using the c notation of starting the count at 0 a 0 through a n minus 1 will be stored in the computer memory linearly one after the other is that fine. So that is a quick way of doing that is quick way of doing vectors right so but as I said there are there is an algebra associated with it which has to be done by you I mean it is not going to be something that is done automatically on most computers okay. What about two-dimensional arrays okay so you wanted matrices but I will talk about 2D arrays so how do we do 2D arrays 2D arrays have two subscripts so they have a I will say i, j just for or if you want a i, j right. So in a matrix that would be row comma column and the way you would store it is you would store it either row wise or column wise in the linear memory what I mean by that is you would store a 0 0 a 0 1 say I am storing that is the first row second column and so on till a is 0 n minus 1 and then go on to the next row which is a 1 0 a 1 1 and so on. So the idea is that in a linear fashion I will store the first row then I will store the second row and then I will go ahead and store the third row so the model that we have of the of the computer memory is linear and what we will basically do is I will store the individual rows one after the other. This process this is how arrays in C for example lot of languages are stored this process is called a row major this is a that is a standard and as one can see if you can store it row wise you can also store it column wise so if you store it instead of the first row as we are done here and then go on to the second row instead of which if you do the first column and then go on to the second column you would get a column major operation is that fine so that would be something like a 0 0 a 1 0 and you will notice for the column is kept fixed a 2 0 and so on till you got 2 a n minus 1 0 and then you go to the next next column right a 0 1 then you go to the next column and then you sweep through the next column you go column by column this is called column major the responsibility to implement either matrix algebra or vector algebra either lies with you or somebody else has done it in the form of a library and you should necessarily use those libraries if you want the associated algebra right. So what we have shown now is integers fixed point floating point floating point of various resolutions so to speak then we have arrays vectors supposedly then we have matrices or 2d arrays if you have the associated algebra you can do matrix algebra so the only thing that we have now is we have to look at functions and how functions can be represented if possible that is the deal okay I am going to put up a bunch of things now you please see what they have what they have in common okay. So I write a bunch of things 3x squared x plus 1 3 well I put this up right up front 3i plus 2j plus k 3 cos theta plus 2 sin theta plus 1 3 plus 2 plus 1 what else can I add 321 comma 2 comma 1 and just for the fun of it 3dx plus 2dy plus dz right or even 3 dou by dou x I am not going to really talk about these but I am just doing it just for the fun of it so that you get an idea as to okay so what do all these expressions have in common what is the what is it that they have in common what is different so you can look at this and you say oh that is a polynomial this seems to be a vector right and this is possibly terms in a Fourier series I do not know that is maybe a clue this is just the addition I mean that is 6 so if you pay attention to this except for this in all of these in all of these expressions that I have written here you would think that I am quite crazy if I actually added the 3 to the 2 so if you ask the question ask yourself the question what role does the I here play your mathematics background will tell you the I is a unit vector that is along the x axis and so on but in reality if you ask the question here at this expression this expression you would add the 3 to 2 in this expression you do not add the 3 to 2 simply because the I and j are there so the I jk here sort of prevent you from adding the 3 to the 2 and that role is played as well by 3 to 1 so in that sense these are quite similar right I mean if I take if I take the combination if I take the combination 3 x squared plus 2 x plus 1 and I add to that 5 x squared plus 3 x plus 2 that really is no different from 3 I plus 2 j plus k and make sure I get the same numbers 5 I plus 3 j plus 2 k so if I add these up indeed I add these respective components here so I will get 8 x squared plus 5 x plus 3 whereas here I get 8 I plus 5 j plus 3 k what is the difference there is no difference right so basically the the summation seems to work just the same as this so this looks like just like this is some point in 3 dimensions you would easily identify this as a point in 3 dimensions this looks like similar to a point in 3 dimensions so it looks like we can actually represent a function deal with a function as though it is a point in space is that fine so we can deal with this function as though it were a point in space of course I should point out that if x were equal to 1 coming back here if x were equal to 1 then indeed you will get 3 plus 2 plus 1 and if x were equal to 10 you would actually get 321 so there is a connection between these two there is a reason why I have written this I already mentioned Fourier series and you can as I said think about this and what it means whether it makes any sense to you it is not something that I want to get into right now but I have just I thought I would just throw that out there if you had a course in differential equations or linear algebra may make more sense to you okay so now we have a big thing what it basically says is that by representing an array see this is a one-dimensional array this is a big deal that we have done here this is a one-dimensional array so I can use this one-dimensional array to represent this vector or to represent this function or to represent that function so that is a great thing that we have achieved here so it is a simple comparison but what it tells me is that it is possible for me to assemble various components right and it also looks like that if I take a function now it is actually a point in some kind of a space some kind of a function space so we are dealing with computers and of course even if you are to do the manipulation ourselves one of the things that we would like to do is we would like to organize any space that we have in a systematic fashion so that we can do searches comparisons and so on okay so that is where we are headed that is our objective so let me then show you some systematic way by which we do it since I started off with vector algebra I will show you how we do it with vector algebra and then maybe in the next class it is possible we will start off with functions and how to represent functions that fine okay so how do we do vector algebra where does it start so how what was the definition of a vector that the earliest definition of vector that you have seen the earliest definition of a vector that you have seen is most likely a directed line segment so if I have a vector A you most probably saw this vector A as a directed line segment so the arrow head indicates the direction the length of the line typically indicates the magnitude of the vector so it is a very geometrical definition so if I have two directed line segments A and B then we have defined the sum of A and B using what you know already as the parallelogram law so the resultant R R equals A plus B is given by the parallelogram law that fine okay so that is all very nice we can do the geometry but the whole point is to get to some kind of an algebra so that we can do the manipulation on paper rather than drawing figures and we will see how we do this then we can get to manipulating things on the computer so that we do not have to draw figure that is the idea okay so how do we get there there is another critical thing that we define which is the dot product A dot B if you go back to your if you go back to your vector algebra the first time that you learnt it is magnitude A this is definition magnitude B cosine of the included angle cosine of theta that angle is theta okay that angle is theta and incidentally this is equal to B dot A if you just look at this multiplication oops sorry about that B dot A okay so A dot B is the same as B dot A how does this help what does this give us well this does something really neat the first thing that I can do is I can say that I can ask the question what is A dot A well A dot A is magnitude A into magnitude A cos of 0 the angle between A and itself which is magnitude A squared okay so this is neat now what we basically have is an expression for magnitude A which is A dot A square root right so previously we were measuring lengths at some point you will actually have to measure lengths or you have to get that magnitude somehow but right now as long as you have the chalk thus you say it is A then the magnitude of A right that is the algebra part is given by square square root of A dot A fine and as a consequence there are neat things that you can do you can define a unit vector and I will use the carrot to indicate that it is a unit vector as A divided by magnitude A right and as a consequence you can have something called a unit vector that is a long A but has magnitude 1 right so clearly the magnitude of unit vector magnitude of A equals 1 is that fine okay so what have we got so far so using this dot product let us try to interpret what is A dot B what happens if I take A dot B hat where B hat is the unit vector along B well that is magnitude A magnitude B cos of theta this is all the repetition of stuff that you guys know so which is magnitude A cos theta which is nothing but the projection of A on to B right so this is a geometrical interpretation that you are aware of but what I really want to do and this is this is the great thing is if I can if I can start off with R equals A plus B I get R from A and B is it possibly for me given R to write them in terms to write R in terms of A and B can I decompose it into A and B is it possible for me to decompose it into components right just like we have done here and as I said this is a rerun of all the vector algebra that you know I am going through this process simply because I propose to repeat this process for functions so you just bear with bear with me for that so the question is if I have R or if I have P I have R so is it possible for me to write R as some R sub A I was going to choose alpha but R sub A A plus R sub B B so this is the component of along A and this is the component along B fine or is it possible for me to write it in terms of unit vectors note the case this is lower case R A A plus R B B so I will start with the second case first because that is a little easier right so what would what do we do well the only operations that we have a vector sums and dot product and we have defined the dot product it is very clear that you can take the dot product here so let us take the dot product of R and A so R dot A gives me R A A dot A plus R B B dot A right and R dot B I take the dot product with B gives me R B B dot B plus I am sorry I am going mad R A A dot B plus R B B dot B lots of B's okay so for those of you who have had fluid mechanics with me you will recognize A dot A B dot A A dot B B dot B as metric tensor for the rest of you it does not really matter so basically what we have had here is what you have is if A dot A is a unit vector this becomes one if this their unit vectors but we do not know what is the angle between them so you are left with this so in fact R dot A this can be rewritten as R A plus R B times B dot A and please remember B dot A and A dot B are the same right we have just said that as part of the definition so this is R A times A dot B or B dot A it does not matter plus R B fine so what we have is we have a system of equations that we need to solve for R A and R B and once you solve that system of equation presumably we can go back and do this representation okay so that looks like a need possibility but of course you know that there is one condition where A and B A dot B or B dot A is 0 and that is when they are orthogonal to each other so if A and B are orthogonal to each other if you go back to the definition I will write if A is orthogonal to B in fact they are orthonormal if A is orthogonal to B A dot B equals 0 right okay so that that gives me R A R dot A is R A and R dot B is R B which of course tells you why we spend so much time trying to get an orthogonal coordinate system as you get along in CFD you will see that it is done very often we desperately try to get orthogonal coordinate systems so that is fine so you have a situation here where A and B are orthogonal so it is R A and R B fine what if they are not orthogonal what if the initial set is not orthogonal so if we constrain ourselves to the board and somebody gives us two A's and B's which are in this fashion they are not orthogonal to each other that is you take A dot B and you discover that A dot B is not orthogonal it is not 0 meaning that A dot B are not orthogonal A and B are not orthogonal how do we do right so clearly they of course they cannot be they you do not want them to be collinear but if they are not orthogonal you will see why you do not want them to be collinear what you can do is you can choose the first vector right so we can use P's if you want so I will use P hat 1 right this is the first vector this vector is going to form the basis for my representation right so I want to look for an orthogonal basis so there when A and B are orthogonal A and B form an orthogonal basis I want to try to get an orthogonal basis from here so I will set P 1 hat to in fact A by mod A maybe wondering why did not I just choose A hat but I will show you why okay what do we do now so how do I get if B is not orthogonal to A how do I get something that is orthogonal to how do I get something that is orthogonal to P 1 hat so what I need to do is from B I need to take out the component that is along A so if I find if I find B dot P 1 the question is what is B dot P 1 B dot P 1 is the component along P 1 of B this multiplied by P 1 gives me the component basically in vector form in fact this would be the component along P 1 right so this is this is the vector along P 1 which is the part of B that is along P 1 and if I subtract from B if I subtract this out right I knock this part out what I am left with is what I am left with is P 2 and this is a vector right not a unit vector vector so the question is what is P 2 dot P 1 if you look at P 2 dot P 1 P 2 dot P 1 gives me from here just take a look P 2 dot P 1 gives me B dot P 1 minus B dot P 1 P 1 dot P 1 which is 1 and lo and behold these two will cancel giving me that P 2 is in fact orthogonal to P 1 hat therefore my P 2 hat is nothing but P 2 divided by magnitude of P 2 is that fine okay so now given A and B that were not orthogonal to start with what we have managed to do is find a P 1 hat and P 2 hat that are orthogonal to each other and from here on we can ask the question given an R is it possible for us to find an R 1 along P 1 plus R 2 along P 2 so that R 1 P 1 plus R 2 P 2 equals R the vector R is that okay right so I think what we have done right now is we have come up with a mechanism by which we are able to generate this in two dimensions what do we do in three dimensions what if I had what if I had one more dimension right what if I had a C that was not in the plane made up of A and B that is not in the plane of the backboard blackboard but C actually comes out of the blackboard so what is it that we do in that case so and it is not orthogonal to the blackboard right so what I had was I had an A just again I have a B A I have a B they clearly not perpendicular to each other and I have a C that is not orthogonal to the blackboard but that is at an angle so what is it that I am going to do in this case so I have already I have I have got my P 1 hat I have got my P 2 hat so from C I need to find out that component of C that is along P 2 and find out that component of C that is along P 1 and subtract them out so it is the same process so I can take C dot P 1 hat plus C dot P 2 hat so this would be that part of C that is in the plane see so if I have if I have a vector that is sticking out of the board then C dot P 1 hat and C dot P 2 hat is the shadow that is cast on the board right so this is the perpendicular part component that is on the board so this combination right if we call it P 3 did I call it P 3 last time what did I call it I did not call it anything okay so I would not call it anything fine I do not want to make a mistake okay and if I subtract this combination out of C I will call this result P 3 and we have to ask ourselves the question what is P 3 dot P 1 hat and what is P 3 dot P 2 hat okay and bear in mind that P 1 hat and P 2 hat are orthogonal to each other so clearly if you go through this process I let you do it for yourself clearly P 1 hat and P 2 hat are orthogonal to P 3 and from P 3 now we can come up with a P 3 hat which is P 3 divided by modulus of P 3 fine and you also understand why it is that I have actually come up with numbers instead of alphabets so it is actually possible for us that if you have multiple dimensions right I will not restrict it to the three physical dimensions that we are talking about but if you have n multiple dimensions it is actually possible for us now to systematically go through each one to get an orthogonal set this is not really numerically if you are dealing with actual vectors a great way to do it but this is called a Gram-Schmidt process this is a Gram-Schmidt process called the Gram-Schmidt process and as I said so it does not matter it is not restricted to two dimensions or three dimensions you can go to as many dimensions as you want so clearly if you go to the fourth one then you would knock out the components that would correspond to the first three and that results in a that results in something that is orthogonal to each one of them so it is a it is a neat process so this now leads us to a situation where we are able to what should I say we are able to construct vectors of any kind so if you want to have an excuse me if you want if you want what should I say so if you want something like 3x squared plus 2x plus 1 that we had earlier and we have 3i plus 2j plus k we just need to ask ourselves the question well I have got I know how I have done it here how is it that we are going to go about doing it here okay so this systematic organization now I am going to do it for functions we will go through a series of series of class of functions next class I will basically start with box functions so what I will do here is I will stop at this point and get back to box functions and so on okay so in the next class what we will do is we will try to represent these functions as a we show representations of these functions of various kinds and what is the relevant accuracy that goes okay thank you