0
$\begingroup$

I need to generate the result given by

List = {"0", "\!\(\*FractionBox[\(\[Pi]\), \(\[Tau]\)]\)", 
  "\!\(\*FractionBox[\(2  \[Pi]\), \(\[Tau]\)]\)", 
  "\!\(\*FractionBox[\(3  \[Pi]\), \(\[Tau]\)]\)"}

but with help of Range command.

How can I do this?

Thank you!

$\endgroup$
4
  • $\begingroup$ How about Range[0, 3] Pi/tau? Btw, don't use List as variable! It's a used symbol in Mathematica. $\endgroup$
    – halirutan
    Commented Mar 17, 2015 at 6:00
  • $\begingroup$ Thank you, but I need list of strings, where Pi and tau are fixed characters, but not variables. Any alternative? $\endgroup$ Commented Mar 17, 2015 at 6:24
  • 1
    $\begingroup$ ToString[#, StandardForm] & /@ (Pi Range[0, 3]/\[Tau])? $\endgroup$
    – Kuba
    Commented Mar 17, 2015 at 6:57
  • $\begingroup$ This is not I want, because the result depends on value of Tau. I need string with Tau literally without substitution. For example if I set: Tau = 1; the result will be different from the desired one. $\endgroup$ Commented Mar 17, 2015 at 10:02

2 Answers 2

0
$\begingroup$

Not too pretty, but handles non-integer steps:

If[#==0,ToString[0],("\!\(\*FractionBox[\("<>If[Numerator@#===1,"", 
ToString[Numerator@#]]<>"  \[Pi]\), \("<>If[Denominator@#===1,"", 
ToString[Denominator@#]]<>"\[Tau]\)]\)")]&/@Range[0,3,1/2]

enter image description here

$\endgroup$
3
  • $\begingroup$ Hm.... I will try it. But is there a shorter and more simple way to do it? $\endgroup$ Commented Mar 17, 2015 at 10:24
  • $\begingroup$ This statement produces the result I want. Is there a way to simplify this piece of code? Thank you! $\endgroup$ Commented Mar 17, 2015 at 13:11
  • $\begingroup$ @AndreyKazak: If your range is only integer values * pi/tau, just remove all the If stuff and keep the first ToString. Other than that, no really simpler ways come to mind. $\endgroup$
    – ciao
    Commented Mar 17, 2015 at 21:57
1
$\begingroup$

If you need strings, then you can just create the symbolic list first and transform every entry into a string afterwards:

ToString[#, TraditionalForm] & /@ (Range[0, 3] Pi/τ)

If you have assigned a global value to tau and you can, as Marius already pointed out, use Block to localize the variable

τ = 4;
Block[{τ},
  ToString[#, TraditionalForm] & /@ (Range[0, 3] Pi/τ)
]
$\endgroup$
4
  • $\begingroup$ This is not I want, because the result depends on value of Tau. I need string with Tau literally without substitution. $\endgroup$ Commented Mar 17, 2015 at 10:01
  • $\begingroup$ Put it in a Block where you localize [Tau], then the global value does not matter. $\endgroup$ Commented Mar 17, 2015 at 18:57
  • $\begingroup$ Didn't get your point. Can you provide an example please? $\endgroup$ Commented Mar 17, 2015 at 19:27
  • $\begingroup$ Block[{\[Tau]}, ToString[#, TraditionalForm] & /@ (Range[0, 3] Pi/\[Tau])] $\endgroup$ Commented Mar 17, 2015 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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