# Can we modify an element of a defined matrix function?

Let us define a matrix funtion: f[x_]:={{x,1},{x^2},1}} then we wants to modify its elements as following

Part[f[x],1,2]=x^3
Part[f[x],2,1]=x


Can we do this? Actually I had written a program like this and the error shows: "f[x] in the part assignment is not a symbol."

• Do you mean you want to change the DownValues of the function f indirectly? Why? what is the point of this? This produces convoluted code which will not be understood 2 days after it is written. But if you just want to modify matrix entry, then all what you have to do is r=f[x]; r[[2,1]]=x that is all. – Nasser Dec 24 '17 at 7:40
• Thanks for your reply. I need to do this when I need to redefine some element of a matrix where all other elements remain unchanged.. – atanu Dec 28 '17 at 5:55

You can use ReplacePart on DownValues of f to make changes to the definition of f:
DownValues[f] = ReplacePart[DownValues[f], {{1, 2, 2, 1} -> x, {1, 2, 1, 2} -> x^3}];