0
$\begingroup$

This question already has an answer here:

This code works fine.

Clear["Global`*"]
f[x_] = x^3 + 2 x^2 - 2;
Plot[f[x], {x, -2, 4}]
guess = 1.4;
iter = 10;
n = Table[j, {j, 0, iter}];
xn = NestList[# - f[#]/f'[#] &, guess, iter];
Grid[Transpose[{n, xn}], Frame -> All]

But when I add NumberForm suddenly Transpose doesn't work anymore. I have no clue why this is and how to fix it. Any ideas?

This is the code with NumberForm.

Clear["Global`*"]
f[x_] = x^3 + 2 x^2 - 2;
Plot[f[x], {x, -2, 4}]
guess = 1.4;
iter = 10;
n = Table[j, {j, 0, iter}];
xn = NumberForm[NestList[# - f[#]/f'[#] &, guess, iter], {∞, 10}];
Grid[Transpose[{n, xn}], Frame -> All]
$\endgroup$

marked as duplicate by Mr.Wizard Jul 10 '16 at 23:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ mathematica.stackexchange.com/a/92889/5478 $\endgroup$ – Kuba Jul 8 '16 at 10:34
  • $\begingroup$ @Kuba Next time you find a duplicate (original) that is itself closed, please Flag the post rather than or in addition to commenting, for moderator attention. $\endgroup$ – Mr.Wizard Jul 10 '16 at 23:34
3
$\begingroup$

Transpose only takes a list of lists as it 1st argument.

Transpose[{{a, b, c}, {d, e, f}}]

{{a, d}, {b, e}, {c, f}}

Transpose[{{a, b, c}, f[{d, e, f}]}]

Transpose[{{a, b, c}, f[{d, e, f}]}]

NumberForm is just another head like f.

Transpose[{{a, b, c}, NumberForm[{d, e, f}, {∞, 10}]}] // FullForm
Transpose[
  List[List[a, b, c], NumberForm[List[d, e, f], List[DirectedInfinity[1], 10]]]]

Just because the head NumberForm doesn't normally print in output doesn't mean it's not there. The work-around is to map NumberForm over the elements of {d, e, f}.

Transpose[{{a, b, c}, NumberForm[#, {∞, 10}] & /@ {d, e, f}}]

{{a, d}, {b, e}, {c, f}}

% // FullForm
List[
    List[a, NumberForm[d, List[DirectedInfinity[1], 10]]], 
    List[b, NumberForm[e, List[DirectedInfinity[1], 10]]], 
    List[c, NumberForm[f, List[DirectedInfinity[1], 10]]]]
$\endgroup$
  • $\begingroup$ I think perhaps this question should be merged with (92885) as it is essentially the same question by the same author. I would likely require some rewriting of that question to include the Transpose case, but I think this would be more useful for future readers. $\endgroup$ – Mr.Wizard Jul 10 '16 at 23:49
  • $\begingroup$ @Mr.Wizard. Are you asking me to do something? I don't understand what merging two questions involves. Further, I ask why the linking of the two questions as duplicates, which you have already done, isn't good enough for archival purposes? $\endgroup$ – m_goldberg Jul 11 '16 at 1:12
  • $\begingroup$ Sorry, let me try to clarify. A merge permanently moves all Answers from one Question to another. To make the "new" answers fit either they (or the question itself) often need some editing. So I was asking (1) Do you agree that a merge would be beneficial? (2) If "yes" to the first are you willing to do the editing? It sounds like a "no" to the first so I'll leave this as it is. $\endgroup$ – Mr.Wizard Jul 11 '16 at 1:18
  • $\begingroup$ @Mr.Wizard. I think I need further discussion before proceeding. I don't do chat very well because I have great difficulty typing at the speed others seem to expect. Could we do it by email? I have an address for you from last year. I will contact you that way if you indicate it would be OK. $\endgroup$ – m_goldberg Jul 11 '16 at 1:30
  • $\begingroup$ Yes, that is fine, and I am happy to discuss it if you like, but at the same time I did not mean to pressure you in any way. $\endgroup$ – Mr.Wizard Jul 11 '16 at 1:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.