Menu

#197 how to make a matrix part of user defined function

open
nobody
None
5
2025-12-03
2025-12-03
dan hayes
No

for example i want to make a function of a matrix so i define

(fmat(matc):=disp(]matc]),fmat(matb));
And it gives edrroneous error mismatched parentheses.
On another occasion it did not gives this bogus error message but came out with wrong number of indices . What is wrong so how do i make a function of a matrix

Discussion

  • dan hayes

    dan hayes - 2025-12-03

    ofcourse that is just a simple example. the actual desire is to make a much more involved function as is where i got the first error message of "wrong number of indices"

     
  • Stavros Macrakis

    I don't understand what you mean by "make a function of a matrix".
    A Maxima variable can be assigned or bound to a matrix just like anything else.

    Of course (fmat(matc):=disp(]matc]),fmat(matb)) has mismatched parentheses and gives a sensible (not bogus) error message. Surely you meant (fmat(matc):=disp([matc]),fmat(matb)), but I'm not sure why you wrote that rather than say (fmat(matc):=disp(matc),fmat(matb)).

    By the way, writing multiple commands on one line like that is a bit less clear than writing it on multiple lines as e.g.:

    fmat(matc):=disp(matc)$
    fmat(matb);
    
     

    Last edit: Stavros Macrakis 2025-12-03
  • dan hayes

    dan hayes - 2025-12-03

    What i meant is in a user defined function using the entire matrix as an argument of my personal user defined function. I just used fmat(matrix):= .....
    Where matrix could be any matrix. I need to use the whole matrix not just part of it.

     
    • Stavros Macrakis

      A matrix is a value like any other value. For example:

      ~~~
      normmat(M):=
      block([r,c,d],
      r: length(M),
      c: length(M[1]),
      d: determinant(M),
      if d=0 then error("normmat needs det(M) to be nonzero"),
      M/abs(d)^(1/r) )$

      ee: matrix([1,2],[3,4]);
      normmat(ee) =>
      matrix([sqrt(2),2^(3/2)],[3*sqrt(2),2^(5/2)])
      determinant(%) => -1
      ~~~

       

Log in to post a comment.