1
$\begingroup$

enter image description here

The TableForm[] is a trig table which shows sine, cosine and tangent values for integer angles from 0 degrees to 90 degrees in steps of 3 degrees.

I want to recreate the exact same table using Mathematica. I need to use TableForm[].

This is what I have so far:

TeXForm@TableForm[
  Select[
   Flatten[
    Table[
     {angle, sine, cosine, tangent},
     {angle, 0, 90, 3},
     {sine, N[Sin[0 Degree], 4], N[Sin[90 Degree], 4], angle},
     {cosine, N[Cos[0 Degree], 4], N[Cos[90 Degree], 4], angle},
     {tangent, N[Tan[0 Degree], 4], N[Tan[90 Degree], 4], angle}
     ],
    1
    ],
   IntegerQ[#[[3]]] && GCD[#[[1]], #[[2]]] == 1 &
   ]
  ]

I'm trying to manipulate code that I used for making another table so the last line:

IntegerQ[#[[3]]] && GCD[#[[1]], #[[2]]] == 1 &

Might be completely irrelevant. For the lines that show sine, cosine and tangent, I tried to start at 0 degrees, show 4 numbers (leading zeros don't count hence the values for angle 3 for sine and tangent), go up to 90 degrees, and I want it to go up in increments of 3 degrees.

Thank you for any help.

$\endgroup$

2 Answers 2

4
$\begingroup$
columnheadings = {"angle", "sine", "cosine", "tangent"};
vals = Table[{angle, N[Sin[angle Degree], 4], N[Cos[angle Degree], 4],
     N[Tan[angle Degree], 4]}, {angle, 0 , 90, 3}];

t=TableForm[vals, TableHeadings -> {None, columnheadings}]

enter image description here

TeXForm[t]

$\begin{array}{cccc} \text{angle} & \text{sine} & \text{cosine} & \text{tangent} \\ 0 & 0 & 1.000 & 0 \\ 3 & 0.05234 & 0.9986 & 0.05241 \\ 6 & 0.1045 & 0.9945 & 0.1051 \\ 9 & 0.1564 & 0.9877 & 0.1584 \\ 12 & 0.2079 & 0.9781 & 0.2126 \\ 15 & 0.2588 & 0.9659 & 0.2679 \\ 18 & 0.3090 & 0.9511 & 0.3249 \\ 21 & 0.3584 & 0.9336 & 0.3839 \\ 24 & 0.4067 & 0.9135 & 0.4452 \\ 27 & 0.4540 & 0.8910 & 0.5095 \\ 30 & 0.5000 & 0.8660 & 0.5774 \\ 33 & 0.5446 & 0.8387 & 0.6494 \\ 36 & 0.5878 & 0.8090 & 0.7265 \\ 39 & 0.6293 & 0.7771 & 0.8098 \\ 42 & 0.6691 & 0.7431 & 0.9004 \\ 45 & 0.7071 & 0.7071 & 1.000 \\ 48 & 0.7431 & 0.6691 & 1.111 \\ 51 & 0.7771 & 0.6293 & 1.235 \\ 54 & 0.8090 & 0.5878 & 1.376 \\ 57 & 0.8387 & 0.5446 & 1.540 \\ 60 & 0.8660 & 0.5000 & 1.732 \\ 63 & 0.8910 & 0.4540 & 1.963 \\ 66 & 0.9135 & 0.4067 & 2.246 \\ 69 & 0.9336 & 0.3584 & 2.605 \\ 72 & 0.9511 & 0.3090 & 3.078 \\ 75 & 0.9659 & 0.2588 & 3.732 \\ 78 & 0.9781 & 0.2079 & 4.705 \\ 81 & 0.9877 & 0.1564 & 6.314 \\ 84 & 0.9945 & 0.1045 & 9.514 \\ 87 & 0.9986 & 0.05234 & 19.08 \\ 90 & 1.000 & 0 & \text{ComplexInfinity} \\ \end{array} $

An alternative with dividing lines:

tt = Grid[Join[{columnheadings}, vals], 
  Dividers -> {All, {True, True, False}}, Frame -> True, 
  Spacings -> {1, .5}]

enter image description here

TeXForm[tt]

$\begin{array}{|c|c|c|c|} \hline \text{angle} & \text{sine} & \text{cosine} & \text{tangent} \\ \hline 0 & 0 & 1.000 & 0 \\ 3 & 0.05234 & 0.9986 & 0.05241 \\ 6 & 0.1045 & 0.9945 & 0.1051 \\ 9 & 0.1564 & 0.9877 & 0.1584 \\ 12 & 0.2079 & 0.9781 & 0.2126 \\ 15 & 0.2588 & 0.9659 & 0.2679 \\ 18 & 0.3090 & 0.9511 & 0.3249 \\ 21 & 0.3584 & 0.9336 & 0.3839 \\ 24 & 0.4067 & 0.9135 & 0.4452 \\ 27 & 0.4540 & 0.8910 & 0.5095 \\ 30 & 0.5000 & 0.8660 & 0.5774 \\ 33 & 0.5446 & 0.8387 & 0.6494 \\ 36 & 0.5878 & 0.8090 & 0.7265 \\ 39 & 0.6293 & 0.7771 & 0.8098 \\ 42 & 0.6691 & 0.7431 & 0.9004 \\ 45 & 0.7071 & 0.7071 & 1.000 \\ 48 & 0.7431 & 0.6691 & 1.111 \\ 51 & 0.7771 & 0.6293 & 1.235 \\ 54 & 0.8090 & 0.5878 & 1.376 \\ 57 & 0.8387 & 0.5446 & 1.540 \\ 60 & 0.8660 & 0.5000 & 1.732 \\ 63 & 0.8910 & 0.4540 & 1.963 \\ 66 & 0.9135 & 0.4067 & 2.246 \\ 69 & 0.9336 & 0.3584 & 2.605 \\ 72 & 0.9511 & 0.3090 & 3.078 \\ 75 & 0.9659 & 0.2588 & 3.732 \\ 78 & 0.9781 & 0.2079 & 4.705 \\ 81 & 0.9877 & 0.1564 & 6.314 \\ 84 & 0.9945 & 0.1045 & 9.514 \\ 87 & 0.9986 & 0.05234 & 19.08 \\ 90 & 1.000 & 0 & \text{ComplexInfinity} \\ \end{array}$

Another option would be to adjust the formatting in TeX.

$\endgroup$
4
  • $\begingroup$ thank you so much!! this is a really dumb question but what about the borders and column bars? is there a way i can add it? $\endgroup$
    – user130306
    Commented May 20, 2019 at 4:55
  • $\begingroup$ also how can i make it show 4 digits like for last value under sine column making it 1.000. and taking away the period in the first value under sine column? $\endgroup$
    – user130306
    Commented May 20, 2019 at 4:58
  • $\begingroup$ @user130306 Oh sorry, to show 4 digits you can use, for example, N[Sin[angle Degree], 4] as you had it. $\endgroup$
    – MelaGo
    Commented May 20, 2019 at 5:05
  • $\begingroup$ @user130306 Regarding borders/divider lines - you can make a table with full control over grid lines using Grid; I will update the answer accordingly. However, I'm not sure how it carries over in TeXForm. $\endgroup$
    – MelaGo
    Commented May 20, 2019 at 5:26
2
$\begingroup$

As in your image, this gives four significant digits except integers are kept exact.

nf = NumberForm[N@#, {6, 4 - Ceiling@Log10[N@#]}] &;

Off[NumberForm::iprf]

Framed[Grid[
  Prepend[
   Table[
      {a, Sin[a Degree], Cos[a Degree], Tan[a Degree]},
      {a, 0, 90, 3}] /.
     x_?(NumericQ[N[#]] && Not[IntegerQ[#]] &) :> nf[x],
   {"angle", "sine", "cosine", "tangent"}],
  Dividers -> {All, {False, True}}],
 FrameStyle -> Thick]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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