1

I am trying to write the result of the equation of the line passing through points pA, pB. My code

pA = {1, 2, 3};
pB = {3, 6, 7};
u = pB - pA;
pA + u t

{1 + 2 t, 2 + 4 t, 3 + 4 t}

How can I get this result in the form [1 + 2 t, 2 + 4 t, 3 + 4 t] which can be easily copied to Maple?

gwr
  • 13,452
  • 2
  • 47
  • 78
minhthien_2016
  • 3,347
  • 14
  • 22

2 Answers2

4
StringReplace[TextString[{a, b, c}], {"{" -> "[", "}" -> "]"}]

[a,b,c]

David G. Stork
  • 41,180
  • 3
  • 34
  • 96
3

Even shorter:

pA = {1, 2, 3};
pB = {3, 6, 7};
u = pB - pA;
result = pA + u t

mapleForm[ mat_List ] := mat /. List -> "" (* // ToString  see comment by Carl Woll*)

result//mapleForm

[1 + 2 t, 2 + 4 t, 3 + 4 t]

And also:

{{1,2,3}, {4,5,6}} // mapleForm

[ [1, 2, 3], [4, 5, 6] ]

"To see the forest for the trees"* - thanks to b3m2a1 for the helpful comment!

gwr
  • 13,452
  • 2
  • 47
  • 78
  • 1
    That's a cute trick. I like it. Even better to hit this at every level: result /. List -> "" – b3m2a1 Mar 13 '18 at 19:53
  • 1
    I would avoid single argument ToString, e.g., consider the horrific output from mapleForm[{1/2, 10^x}]. – Carl Woll Mar 13 '18 at 20:09