user1503057
user1503057

Reputation: 75

How to pass list as variable arguments function in Maxima?

In Maxima there are some function accept variable arguments like diag_matrix( a1,a2,...,an), which is used to create a diagonal matrix with diagonal elements are a1,...,an

However, currently I have a list of [a1,a2,..an] and want to create a diagonal matrix from it. diag_matrix cannot accept the list directly; Is there anyway to utilize diag_matrix to create the matrix ?

Upvotes: 5

Views: 1636

Answers (1)

Robert Dodier
Robert Dodier

Reputation: 17576

In general, the expression apply(foo, [a1, ..., an]) applies the function foo to the list of arguments [a1, ..., an].

In particular, apply(diag_matrix, [a1, ..., an]) applies diag_matrix to [a1, ..., an]. I think that's what you want here.

Note that apply evaluates all of its arguments, even if foo quotes its arguments, or foo evaluates to something other than itself. Therefore there is an "apply defeats quoting" idiom in Maxima, which is often useful.

Upvotes: 6

Related Questions