I want to construct the following matrix $M$ of dimension $(N+1)\times(N+1)$ with the following rule (for arbitrary N). Below, in the subscript, as usual, the 1st index gives the row and the second one the column. The subscript indices go from 0 to $N$.

$\begingroup$Is this homework? Why are are using Mathematica for your problem?$\endgroup$
– gwrJan 29 '16 at 16:20

1

$\begingroup$It's not a homework per se. For our research, I am solving a book's problem (which uses MATLAB) one by one. And we decided to do everything in Mathematica, so we're sticking to mathematica. Now and then, I can't solve a problem. We are even worse in other programming languages, so we are sticking to mathematica.$\endgroup$
– StudentJan 29 '16 at 16:24

1

$\begingroup$Although your matrix is not sparse, perhaps you could still construct it using SparseArray and rules, then converting the SparseArray object to a Normal matrix.$\endgroup$
– MarcoBJan 29 '16 at 16:24

1

$\begingroup$Trust me, I am trying for a long time and I will keep trying. But if someone comes along, and does it in 5 minutes, then I have nothing to complain.$\endgroup$
– StudentJan 29 '16 at 16:26

1

$\begingroup$As you should know, Mathematica list indexes start at one, not zero. At least you may have converted your expressions that way.$\endgroup$
– Dr. belisariusJan 29 '16 at 16:37

$\begingroup$Okay, this one I just checked and it works!! I will understand the code now. Thanks Andre!! Yes, the other one was giving a wrong answer. Yours is correct.$\endgroup$
– StudentJan 29 '16 at 17:52

$\begingroup$+1. I though that indices for matrices in general start with 1? (Just to start one of those religious discussions... :)$\endgroup$
– gwrJan 29 '16 at 16:45

$\begingroup$@gwr Eh, some people may disagree there: Edsger W. Dijkstra's article "Why numbering should start at zero". I have also heard the argument that, for a base $b$ the first $b^N$ non-negative integers are represented by exactly $N$ digits (including leading zeros) only if the numbering starts at $0$, so that's the convention that makes the most sense on computing systems. I, for one, don't care either way :-)$\endgroup$
– MarcoBJan 29 '16 at 16:57

$\begingroup$That's the zeroest time I hear about this. ;-)$\endgroup$
– gwrJan 29 '16 at 17:04

$\begingroup$@MarcoB: Actually there are probably some mistakes. First of all, I think in the definition of c_i that you wrote, it will be i=1 as the first condition instead of i=0. Also, for the [i,j] component, both are c[i]. Even though I corrected them, the problems are still there. For example, for n=1, it's a 2X2 matrix with M_{12}=-1/2 and M_{21}=1/2. Using the code you wrote, I am getting -1 and +1 respectively.$\endgroup$
– StudentJan 29 '16 at 17:50

$\begingroup$@Student Very possible. I suggest that you amend the definitions in your original question by taking into consideration that Mathematica's array indices start at $1$. That will make it much easier to troubleshoot my code.$\endgroup$
– MarcoBJan 29 '16 at 18:02

For instance, FullSimplify[chebmat[5, ∞]] quickly generates the matrix in andre's answer. However, a more appropriate demonstration of the use of the differentiation matrix would be to use it for what its name is implying. ;)

$\begingroup$I upvoted both the answers and accepted them. I will run, check and understand them now. But I am really grateful to see so many people gave some thoughts to my question. Thank you.$\endgroup$
– StudentJan 29 '16 at 17:24

$\begingroup$@Student. I fixed my solution. (It had the same problem as MarcoB's.)$\endgroup$
– marchJan 29 '16 at 18:32

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.