warpy code maths blog

BlitzMax Forums/BlitzMax Beginners Area/warpy code maths blog

Warpy(Posted 2009) [#1]
Hi everyone, I've set up a blog at warpycode.wordpress.com to answer questions about maths programming. The idea is that I can keep all my answers organised together so I can refer back to them when a problem comes up a second time.
Email me any problems you have at christianperfect@... and I'll set about explaining them!


QuickSilva(Posted 2009) [#2]
Great news, I`ll send some problems through to you later today when I get a moment.

Thanks again for taking the time to set this up. I`m sure it will turn into a great resource for us all.

A basic Trigonometry tutorial would be a great start. Sin,Cos,Tan and what they can be used for in a 2D game. For example rotation, enemies wave movements and speeding\slowing of objects.

Edit:
Also I think that a good way to tackle these tutorials would be to have a description of the techniques followed by an example (2D games related) and finally some handy functions that can be used by the readers. The functions can slowly be gathered and put into a separate section of your blog for ease of access.

Jason.


Pete Carter(Posted 2009) [#3]
Cool stuff, i got a book last week "Essential mathmatics for games & interactive applications" it would be cool if i had a maths degree and wanted to make a cutting edge 3d engine. but a few easy to read examples would be great.


Warpy(Posted 2009) [#4]
I find it pretty hard to just do a general survey of, say, trig without a specific problem to solve. So, I won't be doing any "here's all the trig you need to know" posts, but I will use specific questions as starting points for deeper explanation - very often in maths, you need to cover a lot of basics for the difficult stuff to make sense.


Vilu(Posted 2009) [#5]
Bookmarked!

I have a feeling I'll be having pretty tricky math/physics problems for you in the near future. =)


QuickSilva(Posted 2009) [#6]
OK Warpy I see what you are saying. The best way is to start with the basics and then build on them from there.

Maybe you can have different levels of tutorials for example, level 1 Trigonometry could tackle something like,

How can Trigonometry be used in a simple game of Asteroids to rotate and move my ship around the playing area?

Level 2 could build on this and tackle more complex uses for Trig. This way you do not have to stay focused on one topic all of the time making it a better reading experience. Level 2 Trig could come at a later date for example.

These are just ideas. At the end of the day you are the one who knows your stuff so it`s in your hands...

Jason.


ImaginaryHuman(Posted 2009) [#7]
I'd love to see the super ultra easy-to-understand explaination of what matrices are and how they work and why and what they can be used for - you know, the explaination that doesn't exist anywhere in the entire world no matter how hard I look for it? :-)


jkrankie(Posted 2009) [#8]
ditto Imaginary Human. I did matrices at uni, but i forgot it all, and now i can't seem to get my head back into it.

Cheers
Charlie


slenkar(Posted 2009) [#9]
trig for enemy ai would be good, aiming etc.


Warpy(Posted 2009) [#10]
jeremy paxman - email me with specific problems.

ImaginaryHuman and jkrankie - I'm working on a matrices post now.


jkrankie(Posted 2009) [#11]
cool, thanks a lot :)

Cheers
Charlie


Dabhand(Posted 2009) [#12]
If this thread/Warpys blog gets going... It should be as sticky as a wet dream!

Disgusting yes... on a comparison... nothing else would match! ;)

Dabz


slenkar(Posted 2009) [#13]
im not having any problems but I thought it would be a good idea for the blog


jkrankie(Posted 2009) [#14]
Are you planning on giving us some example code in your posts? that would be really cool :)

Cheers
Charlie


Warpy(Posted 2009) [#15]
Matrix maths

No code, because I dealt with it in a pretty abstract way, but I'm keen to do some concrete examples if anyone can think of any. I might have a go at writing a generic matrix library in bmax, for kicks.


Floyd(Posted 2009) [#16]
I might have a go at writing a generic matrix library in bmax


I've thought about this as well but the results would be somewhat unsatisfying.

Try as you might you won't be able to write A = B*C with matrices.


Warpy(Posted 2009) [#17]
Yep, we need operator overloading!


Grey Alien(Posted 2009) [#18]
Awesome, go warpy!


Chroma(Posted 2009) [#19]
Woot cool man. The game I'm working on now is definitely in need of some tricky maths to make the tiles do all kinds of loopy crazy stuff. Thanks!


ImaginaryHuman(Posted 2009) [#20]
Okay, so I read through your blog on Matrices, warpy.

In general, it has a lot more in it explaining various features and ways of calculating matrices than I've seen anywhere else, which is a good thing.

On the downside, though, personally I was lost several times and most of the latter half of your article I could not really follow. I understand this in part may be just my ability and maybe I just need to read it over and over until I get it, but also partly it is because you start throwing in terms and concepts that you haven't explained, and wording your sentences in a way that starts to sound very cryptic. A person trying to learn matrices for the first time is going to get lost I think.

I really do appreciate you taking the time to put together your article and if it can be made even clearer and simpler that would make it so much more accessible to those who are trying to learn this.

Here are some suggestions and areas in which I am confused and would need more clarity. Please don't take this as a criticism, you obviously know what you're talking about, but there are some areas where communicating and teaching this to others has some problems. I don't know if you are trying to target the `absolute beginner`, which is what I thought the purpose was, but at the moment your article is not targetted at a beginner.

I'm going to be very detailed here and it's going to be a huge post, so bear with me. Consider me a total beginner to the world of matrices and I'm going to be really, really dumb about it. I hope this helps make your article even more understandable because, honestly, I have not seen *anyone* explain this clearly enough anywhere and it would really help a lot of people to understand this topic better....

First of all, let me say that all math terminology is scary to someone who is not familiar with it. The whole reason for the need of a clear explaination of matrices is that every single article about it delves into diagrams of math syntax, formulas, wierd sets of numbers enclosed in brackets and all kinds of math stuff with no gentle introduction to why they even exist. You jumped in at a non-beginner level. You didn't cover anything about why you would even want to use a matrix, what a matrix is in relation to something real-world, what it is for, why you'd want to use it, what it `is` in very very simple terms etc.

As soon as you started out mentioning a `scalar`, ie "Scalars are individual numbers - your age is a scalar, the length of an object is a scalar, and so on." I didn't feel comfortable. It may be just the way you built your sentence. Rather than start out with `scalars are`, which almost implies that you mentioned scalars before somewhere (which the beginner has no knowledge of), I would start out saying like `here are some everyday numbers` and `when talking about matrices we refer to these ordinary numbers as a scalar because its a number which refers to a scale, like how your age goes from 0 to your current age on a scale of years - a number that scales/increases/goes through different levels we call a scalar - similar to the word scaler`. Something like that would be better than `scalars are numbers`.

Immediately after that line, you did what *everyone* else has done when trying to explain matrices, and that is that you suddenly started to show mathematical formulas written in official ways. That is so scary to the beginner. When they first look at those things they see nothing but highly cryptic confusing nonsense. `Ordinary people` don't have a clue about formulas or notations. It was also confusing that you gave two numbers as examples (unrelated to anything) and then listed x y and z - like, are we meant to assume that x y and z are like variables in programming, which contain some hidden number and can vary in its value? That's also making too much of a leap without explainanation. It is not obvious. Listing numbers by themselves with no relation or `meaning` in any context does not explain or indicate how they are scalars, the reader could be thinking more like they are constants, and x y z doesn't mean anything.

Then you move on to say "Vectors are like lists of scalars". Provided the reader got a complete grasp of what scalars are, you start out again by throwing in the word `vectors` rather than gently leading up to that terminology. You perhaps could have started out saying something like `when you use more than one number together to represent something like the coordinates of an object on the screen, you normally think of the coordinate as a pair of numbers like x,y or in 3D it would be x,y,z. When you group these numbers together and refer to it as a coordinate, in matrix terms we would call that a vector`. I would almost completely avoid using the official lingo until you've properly prepared the way.

You then present a second diagram where you've introduced a) strange giant-sized brackets, b) no real explaination of why the numbers are listed vertically, c) further reference to the cryptic x y z from before, d) two very strange looking things on the right - an x with an arrow over the top of it and a v with an arrow over the top of it. What the heck are those? There is no explaination of what they are, or why you listed them, or what they mean, or why they're written with an arrow, or what they represent. So I think a beginner would probably be scratching their head and wondering what all this means. I think you need to explain why you're listing the coordinates vertically instead of just doing it. I think you also need to explain why you use those big brackets, and not just `because that's what you do in math`. I think the x y z still needs to be properly explained as to why they aren't numbers. And the things with the arrows over them can probably either be totally omitted from the discussion because they're supposedly purely there for notation/official-ways-of-writing-it purposes that are not useful to anyone, or properly explained in depth. I also don't know the significance of the commas separating each example, or why you have drawn then in your diagrams so close together as if to imply they are connected. A use of larger space between each would be helpful.

In the next part you say "You can do algebra with vectors like you can with scalars." Uh-oh, another math term - algebra. Beginner programmers probably don't for the most part think that they're doing algebra. And even so, a simple comment like `algebra is basically the word used to describe simple math like adding two numbers together, subtracting, multiplying or dividing, and sometimes these are written as a formula like (give examples).` Also the way you start out saying `you can do algebra` totally assumes the reader know what algebra is and does it every day.

Your next diagram then gets even more busy. There is no indication in the diagram that I am supposed to be reading the diagram from left to right, or that doing so is important. You use the equals sign to supposedly mean `the same thing as` by this only makes the diagram more complex, rather than separating it out and saying explicity `this is the same thing written in a different way`. You jumped to putting two values from the two vectors into a matrix together without any arrows or anything showing how they got there. You also didn't indicate that the first row of the first vector should be put with the first row of the second vector, and so on on a per row basis. You then didn't explain that you add the numbers together one row at a time to get the result and that the result then goes into another vector one row at a time. You also followed your diagram with a strange period-looking thing which looks like it possibly means something or is there for a reason, but they're no explaination of it or why you put it there.

You moved on to multiplication before showing an example of simpler subtraction. You didn't say anything about why you would put the 2 outside of the first vector, or why in the `another way of writing it` you put the two in front of each of the x y or z elements. You also didn't explain what 2x 2y or 2z means - there is no mention that you multiply the 2 by the value represented by x, for example, and that you write it as a 2x rather than a `2 * x` because that's more insider math notation that isn't widely known. Also you follow the diagram by that little black dot again, what does it mean, why is it there, who knows?

It would be helpful while you take each step in your explaination, to provide more of a real-world example that people can relate to as to why you would use this. For exmple when you are adding two vectors together, why would anyone want to do that? What can they use it for? Could they use it to move a spaceship's position by movement in a particular direction defined by x and y distances? etc.

You moved on to dot products. No beginner has a clue what a dot product is but you sort of name-dropped it again as if they would have some clue about it. Many people may not know that a `product` is a math term for multiplication - the result of multiplying two numbers - or why the heck it's got the word `dot` in it. Why is it called a dot product?

You said: "You can even multiply two vectors together (their ‘dot product’) but you have to cheat a bit with the notation and write the firstone sideways, for reasons which will become clear when we look at matrices". First of all, for the beginner, this is the first time that you are mentioning the term `notation`. What is notation? Where is your explaination that you are even using any kind of notation (which you assumed) and why you're doing so and what that notiation is or why you would need to use it? Is it math notation? Is there even such a thing as math notation? You also said that you have to cheat by writing sideways. This throws doubt into the beginner's mind - they don't know if they can trust you because now you're telling them to cheat - which is like saying `gloss over something for an undisclosed reason`. You really should explain it right there and then if you're going to do it. `Just doing it` doesn't help to understand why. We have to take your word for it and just do it, hoping that there's some reason, which you may or may not explain.

And then you drop a bombshell. That big long drawn out formula-looking thing. When I first saw that I thought `oh my God, look how long that formula is`. I could not tell that you were writing the same math in several different ways because it was all so grouped together visually. Also at this point I had no clue why you wrote x y z sideways, or what this sidewaysness means, or how on earth you were now going to go about taking something from the sideways elements to combine then with the vertical elements, or why indeed you even wrote them that way or why you put them next to the vertical column. All glossed over. You then gave the formula that you somehow derived from the diagram on the left, without any arrows or any indication or explaination of how you really arrived at the next part of the diagram. Also in the third part of the diagram you put x + 2y + 3z without explaining why you didn't write 1x, or why you changed from saying 1 * x, or why you changed from 2 * y to just 2y - again this is a notation issue that isn't obvious. How would a beginner know that 2y means multiply y by 2? Also once your formula gets longer like it just did, there starts to be concern about order of operations/precedence - reading from left to right sort of sounds okay but I wondered to myself if you do the multiplications before you do the additions. You need to clarify that for the beginner.

Your next paragraph includes the sentence: "Consider a system of simultaneous equations:" First of all, what system? Why are you calling it a system? What is a system? Why are you calling it a system, and what exactly are you referring to AS a system? Why? Also you now throw in the term `simultaneous equasions`. What? What? And you listed three rows with formulas and numbers on the right after the = sign. This implies at first look that there is something about the formula which when calculated produces a result of 10, for example. Why 10? I then look at the formula and I don't see any numbers mentioned, so I can't follow the formula to arrive at 10, so then I am left wondering why the heck did you put a 10 on the end? I now don't understand the formula. The purpose you tried to serve with it was to just give examples of formulas but for a beginner there are assumed unanswered questions that are going to come across their minds, things they are going to `read into` what they're seeing, and you aren't taking those into account to fend off the confusion that will result when they aren't catered for in your explaination.

Then you say "Without explanation, here’s how you write that in matrix form:" and you give a nice pretty diagram of some matrices. Now, if the reader is going to take a leap of faith and just take your word for it that you just simply DO write it like you did, fair enough, and you imply you will explain it afterwards, but you don't. There is no explaination for why you wrote your formulas, which were cryptic to begin with, in the form that you did. Also your diagram appears to refer to numbers from your previous diagram - the 1*, 2* and 3* in the formulas, but you didn't really explain that. You didn't indicate that you took the multipliers from the formulas and put them into the matrix a whole row at a time, one row per formula. There is also no explaination for why you have 3 formulas and 3 rows, or how these correspond to x,y,z. You also wrote x,y,z in a separate vector next to the bigger matrix with no explaination that this means you are `multiplying` the two - again its ambiguous notation. Also since you're using x y and z instead of actual scalars, you again arrive at 6, 10 and 1 without any real evidence to follow as to why you got those numbers. They're numbers you made up, based on fictional values of x y and z, but the reader doesn't know that because you didn't say so, so they're left confused, trying to figure out how to get to a 6 using the diagram on the left. Also our friend the little black dot shows up again. Mysterious! :-)

Where you say next "every equation in the system", you haven't explained yet what a system is or why you're calling it a system or what an example of a system is etc. In that sentence it sounds like you're drawing upon some kind of awareness or `clue` that you had, based on the particular formula's you invented previously, where you realized that each formula had an x, a y and a z, and are now somehow putting them into the matrix in a certain way based on that insight, but it's not clear enough that that's what you are doing. Then you say "So, all you really need to describe the whole system is state what each of those coefficients is" - uh-oh, coeff what? You just referred to the existence of coefficients as if it's plainly obvious to you that you just used them somewhere, but there is absolutely no explaination of what a coefficient is, where the word comes from, what it is used, what it means, what examples of coefficients are, etc. So presumbly to you you've just used some coefficients, but to the reader that had absolutely no clue that you just did that, and even now that you refer to them, they still can't follow you because they don't know what you're talking about. "and what each line was equal to. " huh?

The step you take next, to show an example of a single formula written as a vector, is helpful, but should have come prior to scaring us with a big fancy matrix and unexplained terms and made up numbers. It's still not clear at this point why you just wrote 1 1 1 horizontally again - what the point? Why do you do it? Where are the 1's coming from? And how do we know that writing them in brackets next to xyz in brackets means you're multiplying them? Also again how did you arrive at 6? How can the reader follow where the 6 came from? And again you have the mysterious full-stop. Then you list x + y + z =6 below that, but I'm not finding that particularly helpful.

Then you got excited: "Which is the first equation of our system!" What? Maybe if you didn't call it a system it would help. And the reader has to now refer back two diagrams ago to realize that what you mean is - the first equasion you listed, is represented by the diagram you just gave.

"Matrices aren’t just a quick way of writing down equations though". I didn't know they were? You just again assumed that we know that a matix is used for `quickly writing down equasions`. You didn't say that, though, and we don't yet know that this is one of the benefits of matrices. Yet you worded it to sound like we would know that. You didn't tell us, so we don't know that. You're about to skip ahead to something new without explaining WHY matrices are used to write down equasions, and why it's quick - quicker than what?

"once you’ve got something into matrix form, there are a set of general operations you can perform on them to make finding a solution a lot less fiddly." A solution? to? Solution sounds like a math term, and you haven't tied this in to any real world examples. You haven't explained that you would use a matrix to solve a problem, and what some examples of problems are, or why the matrix gives you answers to those problems. How do you go from a problem, to a formula, to a matrix, to a solution? You've shown how to convert a formula into a matrix but not necessarily that the matrix `does something` to calculate a result. You haven't said that the reader is supposed to do an actual calculation based on some real world numbers, and that the matrix is used for that purpose. You haven't said that you actually have to DO the math on some example numbers using the matrix in order to get a result to solve a problem. Also how does this tie in with computers? How would you write this matrix in a program and how would the computer take the exact necessary steps to perform the matrix `operation` to produce a result?

In the next section "A matrix is like a 2D array of numbers" it would be nice to have a diagram showing how you normally write arrays with rows and columns and how it looks when it's around the other way in a matrix. You also didn't explain why you need to put it around the other way? Are you just doing it to inconvenience us? What's the purpose, other than `thats just how matrices work`?

Then you have this line: "If you want to give a matrix a name, the convention is to use a capital letter so you know it isn’t a scalar, which are always represented by lower-case letters." First of all, now you're talking about a matrix as if it's some kind of object or entity, without really explaining how a matrix might be something you'd use in a program, or that you would even have a need to name it - why would you want to give it a name, what use is that? Also, although it's nice for math-correctness to say that you write the matrix with a capital letter, and now after several paragraphs you let us know that scalars are named lowercase (even though you covered scalars way back), these are not important to the beginner. Your article is trying to be mathematically correct, in a very `math` kind of way, but for programmers, which I thought was the purpose of your article (or am I wrong?) why would they care that there is any kind of official naming scheme, or that they should comply with it? Surely they can name the matrix and scalar whatever they want?

"You can add two matrices of the same size by adding the corresponding entries:" This is sort of okay and the diagram is sort of okay but I would like to see some arrows showing why you took specific elements from each set of numbers and added only those specific elements together. Otherwise the reader has to `work that out` for themelves and they might not get it. And again, that mysterious period shows after the formula. You say "the same goes for subtracting". An example is in order - this is new to the beginner, they need to see everything clearly.

Regarding multiplying, " first of all the second matrix has to have the same number of rows as the first matrix has columns. Multiplying an $m \times n$ matrix by an $n \times p$ matrix results in an $m \times p$ matrix." What the heck is this? Perhaps you should break this down into a) showing example of different sized matrices, a count of their number of rows and columns, and which ones are allowed and which aren't. Also clear diagrammatic representation of why the column has to match the row. b) What the heck is all this $m, \times, n$ etc cryptic stuff that you just added? This is nonsense to the beginner. Why are you suddenly showing dollar signs? Do matrices make me money? And why \times, what does that mean? divide? what does the word times mean? All this n and p and stuff, you need this to be much clearer with diagrams because you skip right on to "To do the actual multiplication" without having clearly shown what you meant in the previous step.

"To do the actual multiplication, start at the top-left entry of each matrix, and read right in the first matrix and down in the second matrix, summing up the products of each pair of entries as you go. T" Waaaaaaaaaay too long a sentence for a beginner to grasp. How about more like: "Now we will do an example of multiplying two matrices, based on the simplest matrices, 2x2 matrices, which have two rows and two columns each (which is why we say 2x2). We start by looking at the top left number in the first matrix. We multiply this by the top left number in the second matrix. But now as we proceed, we take the top right element from the first matrix as we proceed horizontally across the matrix, but we go down in the second matrix to the 2nd row instead of moving horizontally as shown in this diagram (include diagram with arrows showing this simple step). You add together the results of multiplying each pair of numbers, as shown here (show a*j + b*k) and you now store this *formula* in the destination matrix." Something along those lines - simple, broken down in the easiest possible example. Also you need to explain why you are storing combined formulas in the destination matrix. Then once you've done that you need to explain why you're doing that, how the destination matrix would then be used, how you would calculate something using it, with examples, etc. We see matrices listed all over the place with pieces of formulas in each cell and no explaination as to why they are there or what you do with them or in what order. Your diagram with the dotted lines doesn't explain this clearly enough. I won't even mention the mysterios dot at the end this time ;-)

You continue "Now go back and start again at the top-left of the first matrix, and the second entry in the top row of the second matrix, and proceed as before, to get the second entry of the top row. ". Somethis this is just worded strangely, and this is exactly what you needed to be explaining prior to this, and prior to showing that big complicated diagram. It may just be that you're covering the steps but are introducing things in an unnatural order."and so on and so forth. " uh-oh - one complete example from start to end, please. "Very tedious work, but as long as you remember the order to do things in you can do it almost mechanically - read along the first matrix and down the second, then change row or column to get each entry in the result." again I don't think this is worded very well, it's too confusing and unclear.

"I don’t think anyone can get this right first time." Thank God! And kudos to you, Warpy, for even taking the time and effort to write your article!

"Unfortunately, matrix multiplication isn’t commutative, which means it matters which way round you do it. " Which way around you do what? I would prefer a diagram showing how normal multiplication can be done around both ways and showing how it doesn't change the result, then introduce the term commutative (if necessary), so that the reader has the abstract idea of what this commutation thing is and why it matters, and then go on to say how matrices are not like that, how and why. "$3 \times 7 = 7 \times 3 = 21$" What is this notation you're using and how is the reader to understand it? If you were to read it as "3 * 7 = 21, and 7 * 3 = 21", why would you now be reading this as "3 x 7 = 7" what kind of math is that? You haven't explained any of the lingo that you're writing with here. You gave two example diagrams of how matrices give different results depending on the order of multiplying, etc, but this assumed the reader understood your earlier thing about multiplication. Some arrows would help, but it's almost a good example. You also said "the same isn’t always true for matrice" - always? so does that mean sometimes it is true and sometime it isn't? what times are those, and what are the rules governing those times? how can I tell? I have to take your word for it. Is this important information that I need to know?

You said "That’s not even upside-down or reflected, it’s completely different numbers". I think that you are making it more confusing by saying `upside down or reflected` because now the reader has to not only imagine what an upside down or `reflected` matrix would be (and reflected is a too advanced term), but they also now have to wonder if there is such a thing as an upside-down matrix and a reflected matrix, and what are those, and why aren't you covering them? I don't think you need to introduce extra potential confusion like this - just say what you ended up saying - "they are completely different numbers."

"Though you can’t divide two matrices, so that’s one less thing to learn" - is a bit poor English, maybe you should use Although instead of though. And the way you worded it, you're sort of thinking to yourself as an aside. You're also quite seriously glossing over why you can't do division. Readers are accustomed to being able to add, subtract, multiply and divide all numbers. You mention it as though it's of secondary importance and that not having to learn division is of primary importance. I think you should change it to clearly state that you cannot divide two matrices, that the math doesn't work out, or why you cannot divide, showing an exmple of what happens when you try to, and why it's wrong. etc One half of one sentence to say so is not enough.

Okay, so now we have "There are a few special matrices. First, the zero matrix:". I think you'd be better off with a larget seprate heading "special matrices" to help divide up this article into a clearly delimited section. Then you could start off by saying "The zero matrix". You then show a matrix example with four 0's and bunch of weird dotted lines. It isn't very obvious that what you're trying to show is the 0's could fill the spaces in matrixes of any size - you're trying to cover all sizes in a single diagram and the dotted lines don't make that obvious. It would be better to show a few examples of matrices of different sizes/dimensions with 0's filled in all spots. Are the dotted lines another math notation? And why you have that little black dot on this diagram but not the next one?

"is like the number zero - adding zero matrix to any other matrix leaves it as it is, and multiplying any matrix by the zero matrix results in the zero matrix." - This is pretty good but the first part is a bit vague to begin with - and you go on to try to explain how it is like the number zero, BUT, "is like the number zero" might be better phrased "The zero matrix is a matrix-style way of representing the number 0. When you do some math involving a 0 like 2*0 it always ends up as a zero. Similarly a zero matrix, when you involve it in math with another matrix, ends up with the result being 0. So a zero matrix has the same effect as 0 has in normal math" - and then I'd show a diagram of normal math examples resulting in 0, and a diagram of matrix math examples resulting in 0.

"There’s a different zero matrix for every size, but you can always write it as just () without leading to any ambiguity." What do you mean by the different sized zero thing? I think you need to be clearer that no matter how many elements there are in the matrix, all of them can be set to a 0 in order for it to be a zero matrix - and show some different sized examples. Then when you go on to say you `write it as ()` - this implies the reader is interested in writing matrix math on paper or something. Does the reader really care about writing () when they are programmers? Or am I misunderstanding? It is good to know, however, that if you're going to suddenly show () somewhere that we'll know you mean it contains 0's - but for the beginner it would be better to just show the 0's.

"Secondly, the identity matrix:" - why is it called an identity? what does that mean? Again as with the number 0 I think you need to detail why this matrix is the matrix-version of the number 1, how a 1 influences math of various kinds, and how it has a similar effect on matrices, with examples. I also think you interrupted the flow by putting the diagram in the middle of a sentence. Maybe like "Here is an example of an identity matrix". Also you really didn't explain something that I figured out for myself, which is WHY you have 1's in some of the cells of the matrix and 0's in other cells. Based on knowledge of multiplying matrices, if taught clearly enough earlier, I figured that it's because as you proceed across the rows doing your multiplication, putting a 1 in only 1 row and 1 column (in a way) it would make sure that the result is only multiplied by 1 once per element, or something like that. But you did not explain that at all, and I've seen matrices listed with 1's and 0's and other stuff in certain specific cells without telling you why THOSE cells in particular. I think that would help a lot. And again you have your general-purpose unknown dimension diagram - please just put diagrams of example sized matrixes - a 1 x 3, a 2 x 2, a 3 x 2, a 4 x 4 etc filled with the appropriate numbers. And if 1 x 3 does not work in this case, why?

"Multiplying any matrix by an identity matrix (of the correct dimensions)" - the correct dimensions meaning the second matrix has the same number of rows as the first array has columns and vice versa?

From this point in your article onwards you start introducing this "A" thing, and this is where things get even more confusing. You start out "You can also define the inverse of a square matrix". First of all, what is a square matrix and why didn't you ever refer to any matrix as being square before, and what makes it square? That is has the same number of rows and columns? You didn't explain it. Also what is this idea of `inverse`? What is an inverse? Why would you want to inverse something? Why do I care? Your whole sentence is also much too long, including the terms inverse, square, A, matrix A-1, multiplied by A, on either side, result in, and identity matrix. That's too much to digest and needs to be broken down. You just presented the whole idea of inverse matrices without clear explaination, plus you multiplied this mysterious inverse matrix by some other matrix A with who knows what content, and deduced that it ends up being the identity matrix - all in one sentence. I think you need to give an example of a matrix A and what specific numbers it contains. Then you need to explain what inverse means in general terms. Then you need to explain what this -1 has to do with it - is it that if you multiply the matrix by a matrix of correct size filled with -1's produces the negative version of the positive values? I need to see a clean example. You also could presumably say that the inverse matrix is the opposite of the identity matrix - contining -1's in only 3 elements, if that is the case, because you don't say that at all. I want to see clear examples of each matrix, what it contains, how you multiply them together, what you get as a result, etc. You also skip right on to `it results in the identity matrix` - well, I can't tell that, there's no diagram showing it, and I don't see WHY it would result in the identity matrix. I have to take your word for it again.

"So, back to our system of simultaneous equations. " - in other words, "so, lets skip ahead much too quickly to this wierd system thing we keep referring to that has something to do with equasions that are somehow simultaneous but God knows how".

"If we find the inverse of the matrix on the left hand side of our equation, and multiply both sides by that, we are left with just" - what? what? You seem to be referring to some prior equasions - maybe those set of 3 previously which were themselves cryptic? I would reprint them to make it clear. Now you talk about inversing a matrix on the left side of something - the left side of what? What is the left side of an equasion? Then you say multiply both sides by that. Both sides? the left and the right? What? Then you say we're left with a matrix containing just x y and z - how did we get THAT? Then all in the same sentence you skip on to: "so we can read off their values from the result of the right-hand side:" and proceed to give us a large diagram that looks like some joined together biological cells with all kinds of numbers and stuff around them. Somehow you arrive at results on the right hand side supposedly based on what is on the left of the = sign, but I have absolutely no idea what you're trying to show or what it means or how you got there. I *think* that your first line shows an example of a matrix, but why it equals to B I have no idea, and what is B anyway?. I have no idea what your second line shows or why you say A -1 A all on the left of the matrix, what the hell? And why does it produce A -1 B on the right? How did you get that out of nowhere? What does it even mean? On the third line you have an I - I can at least remember that you said this is the identity matrix, and that it represents one, so if you were to write it out it would look like a normal matrix looks (would be better to show it!), but as for the rest of the line I have no idea. Identity multiplied by some xyz matrix produces A -1 B? What. What is all this A -1 B - what does that mean, do we multiply those numbers, what are you even trying to show and how did you get there? As for your last line, no comment. I think this diagram fails terribly. I have absolutely no clue what it's showing based on what you've tried to explain - you totally lost me, and that need not be the case. "Nifty!" doesn't help me to understand it. I'm glad you find this stuff exciting and you are enthusiastic to write about it and enjoy this stuff, but for me the reader there is nothing nifty about being lost in a complicated math diagram that you aren't explaining clearly enough.

"But this is deceptively simple" This is the line I laughed out loud about. THIS previous diagram was simple?!

"because finding the inverse of a matrix involves quite a bit of work. We’ll come back to this, after the last couple of matrix operations." - Okay, but you already tried to explain vaguely that you were gong to do some inversing, but now you are saying that you haven't finished explaining it, and I am left hanging, not knowing what else there is to know, what I missed, or why I would need to know what you are planning to tell me later. Why not tell me now? You haven't finished properly covering inversion before introducing more new concepts.

"The transpose of a matrix is just the same matrix, written ’sideways’ - rows become columns, and columns become rows." I can sort of buy this. If it's just `a word` for changing how you arrange the columns and rows, fine. If it's just that you are basically rotating the rows and columns 90 degrees, fine. But which way does it rotate? Which specific rows become which specific columns and in what order? I need a diagram and example. And why would you transpose the matrix? What is the point? What is that for? You do go on to explain the rows and columns and the order in which you read stuff, kind of, and you end with `Easy!` but this is where you are starting to really get out of touch with the beginner. Your verbal explaination of columns and rows is not easy to follow and does not explain the whole matrix and this really calls for some visual representations. And it is not easy. I kind of feel that as you are getting into more advanced stuff here you are thinking it is easy for you, but it is not easy for the beginner, and I think you are trying to prove to yourself that it's easy for you rather than to accept that this is not easy and the beginner needs a lot of help. I consider this like letting go of the beginner's hand and trying to justify it. Saying easy doesn't make it so. Also after this paragraph you really don't say why anyone would want to transpose a matrix. Why do transposed matrices even exist? What would they be used for? It almost sounds like I could flip the matrix vertically and call it a sandwich matrix and then just leave you wondering why I just did that.

"The determinant of a matrix is a bit like its size, but not really. It’s a scalar, but it can be negative or positive or even zero. What it really does is exactly what it says on the tin - it determine some of the characteristics of the matrix." All of the doubt and confusion in the first of these sentences does not help the beginner. They need to know you are an authority on this and that you know what you're talking about. So.... it's a bit like a size, but it isn't, and its a scalar, but it might be negative or positive, or maybe even 0. That doesn't tell me anything useful. Vague as mud. When in your final sentence you say "determines some of the characteristics of the matrix", that is what you should be starting out with. You tried and failed to explain initially what a determinant is, having dropped another techno math term on us, and then barely explained what that term means till later. This is all back to front in my opinion. You also haven't told me what a determinant is for, why I would use it or want it. You go on to show how in some cases you can sort of calculate it, but it's not easy to follow. Your diagram is cryptic and meaningless to me. The footnote talking about the straight lines does not help me understand it. I don't care if the lines are straight or wiggly. Why do I care about math notation? What difference does this make to me?

Your bullet points starting with "Read along the top row." are moving too quickly. I want to see diagrams of someone's hand covering up part of a matrix. "cover up the row and column it belongs to" is nonense. "multiply that number by the entry on the top row" is nonsense. If you're referring to things like this, the beginner needs to SEE what you are talking about. Top row? top entry? covering up what? You suddenly delve into complicated looking formulas and diagrams in this whole section and totally lost the beginner. You start putting in things like x00 x11 as subscripts with no explaination of what that means or why you're doing it where you're doing it. You don't explain your formulas and you don't explain why you have a second formula below the first one, what is that for? "Another way I’ve been taught is to start with , and then “cycle round” the letters of each row, so you next add , and then . It’s horses for courses, really" - really? Can I Press a button on my calculator to make this work? "cycle around" makes no sense to a beginner. This might be easy for you but this really advanced complicated stuff is exactly what has to be broken down the most and made very very simple.

"We’re almost there!" phew! ;-)

Everything you then went on to say and to show in complicated diagrams, you finished with "That’s handy!" but now I'm thinking, what is Warpy on today? How is THAT handy? I could not follow any of that section and now it's supposed to be obvious to me how incredible useful it's going to be and how it's going to solve all my problems?

"So, the matrix’s inverse is:" - I don't know why you have a number 1 with a line under it and another number 1 under that. What? I don't know what the heck your diagram is trying to show or how it's supposing to result in something near the bottom. It makes no sense and you have stopped explaining.

"We’re done! We can read off that x=1, y=2, z=3" - huh? How on earth did you get through all those complicated diagrams and poor explainations to arrive at 1 2 and 3 for x y z? I have no idea how you got there or why you showed the process in the way that you did. I could not follow it. There are too many assumptions and too much which is not explicity written or shown.

"Now that was a huge amount of faff for something that you probably knew how to do when it was written as a set of simultaneous equations" - so are you saying that all this section which was impossible to follow was for nothing? What was its purpose?

"but think about how you’d get a computer to do it that way. " - we can't think about that. Not only can't we follow your article at this point but we have no clue how this relates to computer programs, why you'd want to do this in a computer program, or what that would look like. YOU should be showing us how to do that and showing us how to turn this thing into a program, or why we can't.

"The matrix method, on the other hand, is very easy for a computer to do - it was just a series of well-defined mathematical operations, with no decisions to be made at any step." - does this mean you just showed us something which was NOT to do with matrices? What was all that you just covered if it wasn't part of this whole matrix thing, and why should I now be discarding it, and which parts, and if so why did you confus me by showing it if you're only going to discard it?

"But you almost never need to solve simultaneous equations in a game! " - hmm, that's useful then. Did we waste time here?

"What are some useful applications of matrices? " - finally way at the end of your article you're now just starting to talk about how we might be practical or WHY we are doing what we're doing. I think you needed this waaay earlier and all the way through. "moving, rotating and scaling. Moving and scaling are easy to do just with vectors" - but not when you haven't shown us how that is the case with a clear example.

"Here’s how you do it with a set of scalar equations:" - okay, but here you introduce some wierd round symbol with a line through it, and you're now putting 0's and 1's next to and below the x's and y's - why? You did not explain that at all. Also you didn't really say anything about the trigonometry you're using - why are cos and sin involved in working out angles for rotation? An example of using some angles and how that converts to a position would help. Also you're assuming multiplications are occuring without writing * anywhere in your formulas, just because it's notationally correct for you, but not easy for the reader. Part of the whole reason that beginners cannot follow mathematical articles is precicely because all this unfamiliar notation is used that nobody explains and you're just expected to know what it means. That makes articles a complete write-off when they could have actually been explained properly. For me, an article that talks about advanced topics in a way that requires you to BE advanced makes it a pointless article. If I were already advanced I wouldn't be needing the article. If the article is useful to anyone, it's useful to people who do NOT understand the subject and want to learn, which means the author has to come down to their level and speak in terms they understand, rather than talking at an advanced level and expecting them to just `get it`. Your article is doing a pretty okay job of making things simpler but it has some way to go, in my opinion.

You went on to say that you drew some graph of sine/cosine in order to work out a matrix. Well, does that mean that I must learn how to draw graphs of trigonometric functions in order to work out how to make a matrix? How can I build a matrix that's useful without having to do that? Also you did not say WHY you put the cos or sin in particular cells in the matrix, nor why one of the sin's has a `-` next to it. It's also not entirely clear that you are trying to multiply the x0,y0,z0 on the right by the rest of the main matrix. Math notation doesn't help explain that.

"What this means is, you can work out the matrix for rotation by a particular angle once, and repeatedly apply that to a vector to rotate multiple times. It’s not obvious you can do that with the pair of equations above.If you find the inverse of a rotation matrix, you can also ‘undo’ a rotation very easily." This is actually perhaps the first practical useful sentence in your article.

Then you go on to gloss over 3D big-time by saying "The matrix method gets vastly more useful when you move to 3d, and you end up with lots of equations and variables to keep track of." - and that's all you say about it. It would really help to see examples of the basic matrix operations applied to 2d objects and 3d objects - ie translation, scaling, and rotation. You also haven't explained why I am supposed to be using matrixes at all, when I could just as easily (presumably) be using equasions like x=x+radius*cos(angle) and y=y+radius*sin(angle). If I can do that, why do I need a matrix? Are matrices faster/slower? Are they better on graphics hardware? Does the hardware do them for you? How are they used in OpenGL? What else can I use a matrix for besides scale/translate/rotate? Also why do we see some really complicated looking matrices which have lots of sin's and cosines and formulas in each element of the matrix, like 4x4 matrices or bigger? What are they used for and why? Also you didn't say anything about whether I am allowed to `compound` one matrix operation on top of another, and what that does to the matrix - like if I wanted to apply a rotation to an object and then translate it some distance - can I do that with one single matrix? How? Does that mean I have to write more complex formulas in each cell? How do I compose them? Is there a limit to how many matrix operations I can do in one matrix? Are there issues with floating point accuracy? And moreso - how would I create and process/code matrices in BlitzMax code in all these scenarios?

I thought you might prefer this critical analysis here rather than on your nice blog, because if you make some of these changes to improve this for the novice I think it would be nice to see your blog be cleaner without all of my rant added to it. Plus people here can whinge about how I write too much. ;-)

Anyway, I hope this helps you make your article more accessible. I'd love to read it through again when it's been improved. Please don't take offence that you did any kind of a bad job explaining it, I am just being extra devil's advocate for the beginner's around here - which includes myself when it comes to this topic. Feel free to pull THIS article apart if you like ;-)

As a final note, you did say you were thinking to write a matrix library for BlitzMax. Well, okay, all well and good. If that library is designed to be used by people who understand matrices, fine. But if it is for educational purposes, that would be the same thing as `just doing it` and not explaining WHY. I don't think that will really help anyone to grasp matrices, except perhaps in the area of how to use them in programs - which is useful, and which you did not cover in your article. I think you need to focus mainly more on explaining why you're doing things.

I hope this helps.


Jesse(Posted 2009) [#21]
Oh my god! I guess you really like writting. I got tired just scrolling down on it. :)


Warpy(Posted 2009) [#22]
ImaginaryHuman, I have no idea how you manage to write so much.

In response to your points - I just wrote down what I know about matrices, using the basic wordpress formatting tools. Writing a comprehensive article about matrices would take days, especially if I went on to cover applications in detail, like 3d rotations. I think it's best to save that for until it comes up in a question.

Matrices absolutely are not something that someone who isn't comfortable with maths, such as you, should attempt to understand. They're very complicated on their own, and they're only useful when you're doing some rather advanced things. I could just write down, "here's the matrix for quaternion rotation, and here's some code implementing it", and I will do when that arises, but this article is just a brief intro for those who are curious.

There is no way to write an absolutely easy beginner's guide to matrices like you want because they rely on a lot of stuff which is itself very difficult. They make no sense outside of "official mathematical notation" - that's all they are.

This wasn't a good post to start with for a beginner's guide to maths, but you asked for it! Maybe come back to it later, when I've covered more of the earlier stuff, and it'll make sense.

Something I don't think you understand, and which I'll try to explain better later, is that notation is incredibly important in maths, which clearly makes it very difficult to read when you don't know how it works. I wasn't sure how much I should cover that, as it isn't used when programming, but clearly I need to so you can follow the explanations to see where things come from.


ImaginaryHuman(Posted 2009) [#23]
Fair enough. I agree the math notation must be covered if you are targetting people not familiar with that notation, otherwise it makes it very hard to follow. But I'm not sure why you think you wouldn't be able to cover basic stuff more clearly, I even spelled out what I thought you would need to do to achieve that. It can be done. I'm not a beginner to programming or necessarily to using math either, but I am not familiar with math notation or topics like this which can be a bit complicated. But I think that just because it's complicated doesn't mean it can't be explained clearly and in a way that even beginners can follow. It's just that nobody's been willing to break it down and to hold the beginner's hand all the way through the process. I will look forward to some of your other articles and hopefully they'll pave the way to this topic.


plash(Posted 2009) [#24]
Cool stuff Warpy! This should be interesting..


Warpy(Posted 2009) [#25]
ImaginaryHuman - glad we agree! It's not that I can't cover the basic topics, it's that I haven't yet, and matrices come pretty much at the end of all the 'basic' things you learn before undergraduate maths.
Holding the beginner's hand all the way through the process leading up to matrices would literally take years, and I have no intention of doing that at the moment.


ImaginaryHuman(Posted 2009) [#26]
That's okay, I mean, I just jumped in assuming that you were aiming it at `people who dont understand` ie beginners, right off the bat, without really clarifying with you what your audience is or how you plan to spread out your teaching over several articles. Sorry about that. However I have to say that critiquing your article did help me personally to understand the topic somewhat better and your article still helped me to have a much better grasp of matrices than before. Thanks.

Part of the reason I'm thinking toward how to explain this stuff to a beginner is because I'm working on a game development book which I hope to be understandable to a beginner/intermediate person, so I was kind of in that mindset when I read your article.

How about a different topic - collision detection?


jkrankie(Posted 2009) [#27]
ah, now i remember! totally forgot you have to multiply all the numbers!

Are you going to be giving some code examples of matrices at some point, or is that beyond the scope of the blog?

thanks :)

Cheers
Charlie


Jesse(Posted 2009) [#28]
I have not gone through your tutorials but I think it should be helpfull base on what I see in your ability to teach. I have seen some tutorials that help beginners but must know a bit of algebra to start of.

I have used this tutorials and have helped me out a lot:
http://people.hofstra.edu/Stefan_Waner/RealWorld/tutorialsf1/frames2_1.html
They go from linear equations to matrix multiplications and inversion.
It's interactive and in my opinion easy to follow.

I don't think matrices are for basic math students. There should be a solid foundation in algebra to even begin to atempt to comprehend them. I believe most books if not all don't begin to teach them until the last few chapters and I believe is for that same reason. I don'think this is the place to start, A class or several at a local community college(USA I don't know if other countries have them) should do the trick.


Warpy(Posted 2009) [#29]
Jesse's link is very good, thanks for that.

EDIT: having had a look at that, they use html really effectively, for example breaking up an equation into a table to explain what each part means, having drop-down forms to test your knowledge, and so on. For some reason I am simply unable to grasp web development, which is why my blog post was so shoddy. Maybe I'll switch to making PDFs for the more mathsy posts, where I can use latex for typesetting and asymptote for helpful diagrams.


Warpy(Posted 2009) [#30]
Just to let you all know there are a few new posts up, about line-box intersections, aiming at moving targets, gaussian kernels, and a little bit of geometry.


Jesse(Posted 2009) [#31]
this is really cool! thanks Warpy.


amonite(Posted 2009) [#32]
Thanks a lot Warpy, very much appreciated !


Vilu(Posted 2009) [#33]
Good job so far, Warpy :)

I wonder if you could make a brief introduction to binary maths, bitwise operations with bit shifts etc? Knowing binary and bitmasking can be a tremendous help in game programming for it's performance and small memory print in storing data.


Jesse(Posted 2009) [#34]
I think a good tutorial to have is on sin, cos, tan and tan2. Most know what they are but few know how to use them efficiently for games. I admit, until about 3 years ago I only used sin and cos to do circles until I started studying others code and found more uses for them.


TommyH(Posted 2009) [#35]
Good suggestion, Jesse!

Stuff like
- orbiting,
- orbiting a moving object,
- homing missiles,
- calculating nose or tail position(s) of space ships to properly place fired missiles or engine particles,
- placing and rotating groups of objects in some formation (space ship fleets, armies in an RTS)

should all be doable using sin, cos and so on.


Bobysait(Posted 2009) [#36]
Hi, nice blog.
I notified a mistake on your blog, check my comment about matrix area.

And if that can help, Here is how I learned to calculate matrix determinant


Matrix.png(bigger)