0

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]
m_goldberg
  • 107,779
  • 16
  • 103
  • 257
GambitSquared
  • 2,311
  • 15
  • 23
  • http://mathematica.stackexchange.com/a/92889/5478 – Kuba Jul 08 '16 at 10:34
  • @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. – Mr.Wizard Jul 10 '16 at 23:34

1 Answers1

3

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]]]]
m_goldberg
  • 107,779
  • 16
  • 103
  • 257
  • 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. – Mr.Wizard Jul 10 '16 at 23:49
  • @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? – m_goldberg Jul 11 '16 at 01:12
  • 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. – Mr.Wizard Jul 11 '16 at 01:18
  • @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. – m_goldberg Jul 11 '16 at 01:30
  • 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. – Mr.Wizard Jul 11 '16 at 01:31
  • @Mr.Wizard. Not feeling any pressure since I haven't agreed to do anything so far. Email forthcoming. – m_goldberg Jul 11 '16 at 01:36