Quilt Plot for n - variable functions

Quilt plots

Quilt plots are plots that describe the small scale change of a function through linear approximations of the graph by small quadrilaterals. 
In class we saw MouseOver.
We want to generalize this to n-dimensional functions.

Objective

Given an n-dimensional function F(x) and k<l<n, we want to find the quilt plot of the function with respect to x_k and x_l.

Implementation

We can generalize most parts of the program into n variables. When we construct the polygons, we take into consideration only the coordinates of the component functions we are interested in.

QuiltPlot[n_,k_,l_,F_List,X_List]:=Module[{iX,grid,dX},iX=Do[Sow[Evaluate[ToExpression["ix"<>ToString@i]]],{i,n}]//Reap//Last//Last;
dX=Do[Sow[Evaluate[ToExpression["dx"<>ToString@i]]],{i,n}]//Reap//Last//Last;
SeedRandom[1];
indices = AppendTo[(UnitVector[n, k]+UnitVector[n, l])/. {{1->All,0->1}}//Last, {k, l}];
(*This is the index of the endpoints of the polygons*)
Do[dX[[i]]=(X[[i,3]]-X[[i,2]])/X[[i,4]],{i,n}];
grid=Table[Do[Sow[X[[i,1]]->X[[i,2]]+iX[[i]]*dX[[i]]],{i,n}]//Reap//Last//Last,##]&@@(Do[Sow[{iX[[i]],0,X[[i,4]]}],{i,n}]//Reap//Last//Last);
grid=Map[(F/.#)&,grid,{2}];
(*grid is the table of values x_i gets sent to at the small interval endpoints xmin_i+ix_i*dx_i*)
polygoncoords={{0, 0}, {0, 1}, {1, 1}, {1, 0}}+ConstantArray[iX[[{k, l}]],4];
t=Table[{RGBColor[Random[],Random[],Random[]],Polygon[(Indexed[Extract[grid, indices],#]&/@polygoncoords)]},##]&@@Transpose[{iX[[{k,l}]],X[[{k,l},4]]}];
(*This is the table of polygon endpoints, along with the random colors, for x_k vs x_l*)
Show[Graphics[t],Frame->True,AspectRatio->1]];
DoubleQuiltPlot[n_,k_,l_,F_List,X_List]:=GraphicsRow[{QuiltPlot[n,k,l,(#&@@@X),X],QuiltPlot[n,k,l,F,X]}]

We can then find the quilt plot for say, a 4-variable function with respect to x_1 and x_4 as shown below.

DoubleQuiltPlot[4,1, 4,{2 x1-3 x2+x3+x4^2,x1+2 x2+x3-x4,5x1+x2-x3^2+x^4, x1^2+x2+x3+x4},{{x1,-1,1,4},{x2,-1,1,5},{x3,-1,1,5}, {x4,-1,1,5}}]