5
$\begingroup$

I would like to create a table like the one shown below in mathematica: enter image description here

Here is the code i wrote:

enter image description here

I was wondering if there is more efficient way to writing the code where i don't have to type out individual sin(xt) for each value of x and t.

This is a modified version of the question that is in the book "Hands-on Start to Wolfram Mathematica and Programming with the Wolfram Language, Second Edition". If anyone has the pdf solutions to the all exercises in the book, would you be able to send it to me?

Thanking you in advance

$\endgroup$
6
$\begingroup$
(* create your values *)
rows = Range[10];
cols = Range[6];
vals = Outer[Sin@*Times, rows, cols];
(* make a table *)
tf = TableForm[N@vals, TableHeadings -> {rows, cols}];
(* label it *)
Labeled[tf, {"x-vals", "t-vals"}, {Left, Top}, RotateLabel -> True]

You may want to use NumberForm for a nicer display of the values. E.g.,

vals = Map[NumberForm[#, {4, 3}] &, vals, {2}]
tf = TableForm[N@vals, TableHeadings -> {rows, cols},
   TableAlignments -> Right];

enter image description here

| improve this answer | |
$\endgroup$
6
$\begingroup$

Here is one way:

table = ConstantArray["", {12, 8}];
table[[3 ;;, 3 ;;]] = Table[N@Sin[x t], {x, 10}, {t, 6}];
table[[1, 3 ;;]] = Range[6];
table[[1, 2]] = "t-values";
table[[2, 1]] = "x-values";
table[[3 ;;, 1]] = Range[10];
Grid[
 table,
 Alignment -> Left,
 Frame -> True,
 Dividers -> All
 ]

Mathematica graphics

| improve this answer | |
$\endgroup$
3
$\begingroup$

The title of your question refers to "plots of sin(x t)." You could also add the literal plots as Tooltips to the table headings. Using Alan's answer as a starting point.

(*create your values*)
rows = Range[10];
cols = Range[6];
vals = Outer[Sin@*Times, rows, cols];
(*make a table*)
tf = TableForm[N@vals,
   TableHeadings -> {
     Tooltip[#,
        Show[
         Plot[Sin[#*t], {t, 0, cols[[-1]]}],
         DiscretePlot[Sin[#*t], {t, 1, cols[[-1]], 1},
          PlotStyle -> Red],
         AxesLabel ->
          (Style[#, 12, Bold] & /@ {"t", "Sin[x t]"}),
         PlotLabel -> StringForm["x = ``", #]]] & /@ rows,
     Tooltip[#,
        Show[
         Plot[Sin[x*#], {x, 0, rows[[-1]]}],
         DiscretePlot[Sin[x*#], {x, 1, rows[[-1]], 1},
          PlotStyle -> Red],
         AxesLabel ->
          (Style[#, 12, Bold] & /@ {"x", "Sin[x t]"}),
         PlotLabel -> StringForm["t = ``", #]]] & /@ cols}];
(*label it*)
Labeled[tf, {"x-vals", "t-vals"}, {Left, Top},
 RotateLabel -> True]
| improve this answer | |
$\endgroup$

Your Answer

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

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