1
$\begingroup$

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?

$\endgroup$
  • 3
    $\begingroup$ Mathematica's default convention is to use braces for vectors; why do you need brackets in the output? $\endgroup$ – J. M. will be back soon Mar 13 '18 at 16:02
  • $\begingroup$ Sometimes, I want to copy the result to Maple. $\endgroup$ – minhthien_2016 Mar 13 '18 at 16:03
  • 2
    $\begingroup$ Your question has nothing whatsoever to do with the equation of a line. Don't you see that? Please write a useful title that will help others find the solution if they have a similar problem, which is only about converting to a Maple format. $\endgroup$ – David G. Stork Mar 13 '18 at 16:26
  • $\begingroup$ Since Maple afaik can import MatLab-expressions maybe this old package (ToMatlab.m) is an option? $\endgroup$ – gwr Mar 13 '18 at 18:22
  • 1
    $\begingroup$ I have now rephrased your title to make it (imho) more sensible - if you do not like this, simply roll back. $\endgroup$ – gwr Mar 13 '18 at 18:28
4
$\begingroup$
StringReplace[TextString[{a, b, c}], {"{" -> "[", "}" -> "]"}]

[a,b,c]

$\endgroup$
3
$\begingroup$

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!

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

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.