Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to put the solutions of the equation $y = (x + 3)/(x - 3)$, where $x$, $y$ are integers, into the form $(x,y)$. For example, $(2, -5)$ instead of $\{2,-5\}$. When I evaluated

{x, y} /. Solve[y == (x + 3)/(x - 3), {x, y}, Integers]

I got

{{-3, 0}, {0, -1}, {1, -2}, {2, -5}, {4, 7}, {5, 4}, {6, 3}, {9, 2}}

How do I get $(-3,0),\,(0,-1),\,\ldots$?

share|improve this question
2  
Can you please explain why you'd want that? Is it purely to display the list "nicely"? –  Pinguin Dirk Oct 3 '13 at 8:11
1  
In my country, the pair of solution must be formated like that. After Mathematica out put, I use TeXform to convert them. –  minthao_2011 Oct 3 '13 at 8:50
add comment

4 Answers

up vote 7 down vote accepted

I assume you know (1,2) will result in an error while interpreting by FE and that form you need is for output/presentation purposes:

StringForm["(``,``)", ##] & @@@ {{-3, 0}, {0, -1}, {1, -2}, {2, -5}, {4, 7}, {5, 4}, 
                                 {6, 3}, {9, 2}}

{(-3,0),(0,-1),(1,-2),(2,-5),(4,7),(5,4),(6,3),(9,2)}

share|improve this answer
add comment
StringReplace[#, {"{" -> "(", 
    "}" -> ")"}] & /@ (ToString /@ {{-3, 
     0}, {0, -1}, {1, -2}, {2, -5}, {4, 7}, {5, 4}, {6, 3}, {9, 2}})
share|improve this answer
    
+1, notice that StringReplace automatically threads over list so you do not have to Map with it. –  Kuba Oct 3 '13 at 12:25
    
@Kuba thank you, should have known but always nice to learn –  ubpdqn Oct 3 '13 at 12:27
add comment

You could use Row to predefine output format and again to display it as you want with ", " as the separator between Row elements

Row[Row@{"(", x, ", ", y, ")"} /.Solve[y == (x + 3)/(x - 3), {x, y}, Integers], ", "]

(-3, 0), (0, -1), (1, -2), (2, -5), (4, 7), (5, 4), (6, 3), (9, 2)
share|improve this answer
add comment

You may only obtain it if you agree to have the strings of the desired form, since otherwise the "(" and ")" parentheses are reserved for a different purpose. Try this:

This is your list of solutions

 lst = {x, y} /. Solve[y == (x + 3)/(x - 3), {x, y}, Integers]

(*
{{-3, 0}, {0, -1}, {1, -2}, {2, -5}, {4, 7}, {5, 4}, {6, 3}, {9, 2}} *)

and this makes the string of solution:

Map["(" <> ToString[#[[1]]] <> "," <> ToString[#[[2]]] <> ")" &, lst]

{"(-3,0)", "(0,-1)", "(1,-2)", "(2,-5)", "(4,7)", "(5,4)", "(6,3)", \
"(9,2)"}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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