Question

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 ?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top