0
$\begingroup$

I wrote a function in Mathematica that applies certain construction steps on the "incidence matrix" of a graph in order to obtain a new graph with certain properties. These construction steps can be iterated and here is the point where I fail. If I write something like

Henneberg1[Henneberg1[{{{1,1,1,1}}},a,b],c,d]

I get a weird error of the following form: error when iterating function

Now to the implementation:

Henneberg1[mats_, a_, b_] := ...

The first parameter mats_ describes a set of (incidence) matrices where a and b are only placeholders for variables to be added. If I evaluate Henneberg1[{{{1,1,1,1}}},a,b] I retrieve

$\{\begin{pmatrix} 1 & 1 & 1 & 1 & 0 & 0 \\ a & 1 & 0 & 0 & -a & -1 \\ 0 & 0 & b & 1 & -b & -1 \end{pmatrix}\}$

Directly passing the result as argument for Henneberg1 then works as desired, but I am not able to iterate in the way described above.

The actual implementation of Henneberg1 can be found here, but is quite a mess, so sorry for that. (What it actually does can be found here (1.))

If someone knows where the problem lies I would really appreciate that.

$\endgroup$
  • 1
    $\begingroup$ Henneberg1 get List as the input and outputs MatrixForm. you may want to do Henneberg1[List @@ First@Henneberg1[{{{1, 1, 1, 1}}}, a, b], c, d] $\endgroup$ – Xminer Jun 26 at 11:56
  • $\begingroup$ This solves my problem. Thank you very much @Xminer! $\endgroup$ – bohnanza Jun 26 at 12:10
  • $\begingroup$ you're welcome. $\endgroup$ – Xminer Jun 26 at 12:19
  • 2
    $\begingroup$ General tip: never use MatrixForm in functions that do computations. Only use it as an afterthought (//) to print matrices to your notebook. E.g., Henneberg1[{{{1,1,1,1}}},a,b] // MatrixForm. All functions that end in Form are meant for output formatting only, not for use in intermediate results. $\endgroup$ – Sjoerd Smit Jun 26 at 12:58

Your Answer

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

Browse other questions tagged or ask your own question.