Hello Sander,
Thank you so much for your reply and for the time you spent in cleaning up my code.
Here the mathematical meaning of what I need to do:
I want to solve a differential equation (d.e.) through a numerical method which basically transforms the d.e. into an algebraic system in the standard form Kx = b. Once I find K, then I will just need to invert it and get the unknown vector x = K^-1 b.
For the sake of simplicity, I have posted a very dummy example of differential equation. (Please, note that it is a meaningless example since neither the term b nor the boundary conditions are present).
The d.e. of the dummy example reads as follows
w1,1 + w1,12 = 0 (1)
where w1(u,v) is a function defined from a square domain [0,1] x [0,1] to R. In the code that I posted D1w[1, 1] is w1,1, namely the partial derivative of w1 with respect to u, while D2w[1, 1, 2] is w1,12, namely the second derivative of w1 with respect to u and v.
There are several ways to approximate w1. I have chosen to approximate it by means of BSpline basis functions. So I have
w1(u,v) = \Sum{i=0,n} \Sum{j=0,m} Ni(u)*Nj(v) W1(i,j) (2)
where W1(i,j) represent a (finite) set of (n+1)(m+1) control variables, and Ni and Nj are the i-th and j-th BSpline basis functions.
Now, it is easy to take the derivatives of the approximate form of w1 as given in Eq. (2) and replace them into the original d.e. Eq (1).
If one makes the substitution, which is what I try to do with `EqDisc[ic, jc, i, j] := Eq //. sub[ic, jc, i, j]; (see my code) one gets a discretized version of Eq (1), which represents one (approximated) equation in (n+1)(m+1) unknowns.
If now one evaluates this equation in (n+1)(m+1) points belonging to the domain [0,1]x[0,1] (letÂ’s say a grid of points) one gets (n+1)(m+1) equations. A linear system is obtained and, after collecting terms (see command Coefficient), the matrix K of the system is found. So, each row of K represents the discretized equation evaluated in a specific point of the domain, while each element on a row represents the term appearing in the summations over i and j. Please note that a conversion from two-index to one-index is needed since the unknowns W1(i,j) are in the final system arranged in a vector and not in a matrix.
Sorry for the very informal explanation, but I hope this is enough to give you a general idea of what my final goal is.
This is a known technique which works well when I implement it in Matlab environment where I use a more standard programming approach. Now I would like to develop the same technique in Mathematica.
Many thanks,
Enzo