Why do people participate in meaningless activities such as politics, education, mathematics, philosophy and such when either we are all going to die so it won't matter what we have done, or maybe our existence and/or this world is all an illusion so it doesn't matter what happens because it's not real?

I'm not sure I understand what it is for something to "matter", if it isn't shorthand for mattering to someone or other. As Richard Heck points out, something a person does might matter to other people after her death. And certain things I do matter very much to me right now–or will matter to me later on–even though I know that I will die someday. Perhaps there will come a time when there's no one left in the world—at that point, "nothing will matter" in the sense that there will no longer be anyone to whom anything could matter. But it doesn't follow that the things we do now matter very much (to ourselves or to our descendents). I also don't see how the possibility that "the world is all an illusion" should affect the issue. Perhaps if this possibility were actual, then many of the things that I assume will matter to other people will not really matter, since in that case no other people would exist. (Though there may still be things that matter to me.) For example, one might argue that...