1
$\begingroup$

I have two functions as numeric[x, t] and exact[x, t].

I want to create a table including 5 columns as follows (table formatting doesn't matter) and to export it to LATEX:

enter image description here

I use TeXForm or ExportString[.., "TeX"] but I can't get good results since the table includes exponential terms:

\[Rho] = 0.5; numeric[x_, t_] := 0.03125 (1 - 4 Sech[0.25 x]^2) + 0.0078125 t Sech[0.25 x]^4 Tanh[0.25 x] + 0.0078125 t Sech[0.25 x]^2 Tanh[0.25 x]^3 + 0.00012207 t^2 (-2.25 Sech[0.25 x]^4 + 2.25 Sech[0.25 x]^6 + 1. Sech[0.25 x]^8 + 4.5 Sech[0.25 x]^2 Tanh[0.25 x]^2 + 20.25 Sech[0.25 x]^4 Tanh[0.25 x]^2 - 22.5 Sech[0.25 x]^6 Tanh[0.25 x]^2 - 13.5 Sech[0.25 x]^2 Tanh[0.25 x]^4 - 16.5 Sech[0.25 x]^4 Tanh[0.25 x]^4 + 7. Sech[0.25 x]^2 Tanh[0.25 x]^6); exact[x_, t_] := 1/8 \[Rho]^2 (1 - 4*Sech[\[Rho]/2 (x + 1/2 (\[Rho]^2)*t)]^2); t1 := Table[numeric[x, t] - exact[x, t], {x, 0, 2, .5}, {t, 0, 2, .5}] TeXForm[t1] ExportString[t1, "TeX"] 
$\endgroup$

1 Answer 1

4
$\begingroup$

You can use DecimalForm to format your table:

\[Rho] = 0.5; numeric[x_, t_] := 0.03125 (1 - 4 Sech[0.25 x]^2) + 0.0078125 t Sech[0.25 x]^4 Tanh[0.25 x] + 0.0078125 t Sech[0.25 x]^2 Tanh[0.25 x]^3 + 0.00012207 t^2 (-2.25 Sech[0.25 x]^4 + 2.25 Sech[0.25 x]^6 + 1. Sech[0.25 x]^8 + 4.5 Sech[0.25 x]^2 Tanh[0.25 x]^2 + 20.25 Sech[0.25 x]^4 Tanh[0.25 x]^2 - 22.5 Sech[0.25 x]^6 Tanh[0.25 x]^2 - 13.5 Sech[0.25 x]^2 Tanh[0.25 x]^4 - 16.5 Sech[0.25 x]^4 Tanh[0.25 x]^4 + 7. Sech[0.25 x]^2 Tanh[0.25 x]^6); exact[x_, t_] := 1/8 \[Rho]^2 (1 - 4*Sech[\[Rho]/2 (x + 1/2 (\[Rho]^2)*t)]^2); t1 = Table[ DecimalForm[numeric[x, t] - exact[x, t], {10, 9}], {x, 0, 2, .5}, {t, 0, 2, .5}] TeXForm[t1] 
(* \left( \begin{array}{ccccc} 0.000000000 & 0.000000005 & 0.000000079 & 0.000000401 & 0.000001268 \\ 0.000000000 & 0.000000156 & 0.000001285 & 0.000004448 & 0.000010807 \\ 0.000000000 & 0.000000269 & 0.000002173 & 0.000007399 & 0.000017689 \\ 0.000000000 & 0.000000321 & 0.000002575 & 0.000008702 & 0.000020650 \\ 0.000000000 & 0.000000313 & 0.000002495 & 0.000008390 & 0.000019808 \\ \end{array} \right) *) 

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks for your answer. It is an alternative but I still need an exponential form of the error for journal articles. Because I get sometimes very small errors such as 10^(-18). Decimal form is useless in this case. $\endgroup$ Commented May 26, 2021 at 16:16
  • $\begingroup$ Take a look at the ExponentFunction option of NumberForm. $\endgroup$ Commented May 26, 2021 at 18:43

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.