Search code examples
maxima

Maxima: Assign value to a variable, by addressing it in a matrix


I had a complex problem which is solved. Now i would love to automate it. In doing so, I do address a position in a matrix. This positions does contain a variable. I want to assign a value to this variable, by its position in the matrix. Here is a simple example of what I want to do:

    (%i1) M:[a,b,c];
    (%o1) [a,b,c]
    (%i2) M[1];
    (%o2) a
    (%i3) ev(M[1]):3;
    (%o3) error: assignment: cannot assign to ev(M[1])
    (%i4) float(a);
    (%o4) a

I would love the variable "a" to be 3 now. But ev() is clearly not the right function for this.

My question is: is what i want even possible? does anyone know how to do? I looked the whole day and I am really depressed now :-(


Solution

  • I think what you want is the :: operator, which evaluates its left-hand side and assigns to that.

    (%i1) M : [a, b, c] $
    (%i2) M[1] :: 123 $
    (%i3) a;
    (%o3)      123