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


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."

  • 5
    $\begingroup$ 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. $\endgroup$ – Nasser Dec 24 '17 at 7:40
  • $\begingroup$ 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.. $\endgroup$ – 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}];    

{{t, t^3}, {t}, {2, 1}}

  • $\begingroup$ Thanks a lot for your response.. $\endgroup$ – atanu Dec 28 '17 at 5:50
  • $\begingroup$ @atanu, my pleasure. Welcome to mma.se. $\endgroup$ – kglr Dec 28 '17 at 6:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.