Suppose I would like to define an expression, containing and array or matrix of symbolic elements.
Like this
p[x_, y_] := Sum[Sum[a[[i, j]]*x^i*x^j, {j, 1, 3}], {i, 1, 3}]
But if I try to evaluate this function, I see, that indexing is not symbolic:
Not only it swearing, but also returns incorrect result (zero).
So, is it possible to force Mathematica to know, that a
is symbolic matrix of 3x3 containing no defined values. I.e. a[[1,2]]
should evaluate to itself.
UPDATE
Some more detailed example
In[55]:= (* our system of equations with single solution *)
y == x*10 + 1 && y == -x*5 + 12
Out[55]= y == 1 + 10 x && y == 12 - 5 x
In[56]:= Clear[x, y]
In[57]:= (* solving a system *)
sol = Solve[y == x*10 + 1 && y == -x*5 + 12, {x, y}]
Out[57]= {{x -> 11/15, y -> 25/3}}
In[58]:= (* assigning found solutions *)
x = (x /. sol)[[1]]
y = (y /. sol)[[1]]
Out[58]= 11/15
Out[59]= 25/3
Now suppose we want to compose x and y into single vector
Using "functional" approach
In[60]:= Clear[x, y]
In[61]:= sol = Solve[x[2] == x[1]*10 + 1 && x[2] == -x[1]*5 + 12, {x[1], x[2]}]
Out[61]= {{x[1] -> 11/15, x[2] -> 25/3}}
In[62]:= (* assigning found solutions *)
x[1] = (x[1] /. sol)[[1]]
x[2] = (x[2] /. sol)[[1]]
Out[62]= 11/15
Out[63]= 25/3
In[9]:= x[1] /. sol
Out[9]= {1/2, 1/2}
In[10]:= x[2] /. sol
Out[10]= {-(Sqrt[3]/2), Sqrt[3]/2}
Unfortunately, x is not a vector now
In[65]:= (* we can't type it *)
x
Out[65]= x
In[66]:= (* we can't calculate it's length which should be 2 *)
Length[x]
Out[66]= 0
Now will try to use list approach
In[68]:= Clear[x]
(* and we fail just in the beginning *)
sol = Solve[x[[2]] == x[[1]]*10 + 1 && x[[2]] == -x[[1]]*5 + 12, x]
During evaluation of In[71]:= Part::partd: Part specification x[[2]] is longer than depth of object. >>
During evaluation of In[71]:= Part::partd: Part specification x[[1]] is longer than depth of object. >>
During evaluation of In[71]:= Part::partd: Part specification x[[2]] is longer than depth of object. >>
During evaluation of In[71]:= General::stop: Further output of Part::partd will be suppressed during this calculation. >>
During evaluation of In[71]:= Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information. >>