- #1
- 2,020
- 827
I did this for some work I'm doing and I thought I'd offer the program in case anyone might want it. (And one little question.)
It's a Clebsch-Gordon table generator for addition of quantum angular momentums. The TikZ coding is fairly basic, but it's probably my best TikZ work so far, not because it was so difficult to program, but because of the limitations of the TikZ Mathematics engine. (Apparently, you can't calculate (-1)^n, even if you declare n to be an integer variable, because TikZ uses a logarithm to calculate it.) I had to be innovative in a couple of cases!
My question: One of the headaches I had was converting a decimal to a fraction. Now, it's a simple process, but I found out that TikZ does not automatically use a fixed point system, and TikZ does not allow for a while loop.
That's my question. In order to convert a decimal to a fraction my plan was to start with a possible denominator of 2, multiply the number by 2, and see if I got an integer. If so, I'm done. If not, add 1 to the denominator and loop around to do it again.
I did this all the way back in 11th grade when Apple IIs were still a thing. It's not hard. BUT in BASIC I could just simply use GOTO statements to do the loop, and when I took FORTRAN we used a WHILE loop. In TikZ I had to use a FOR loop and you have to set an upper limit on size of the denominator you want to use.
Say we have num = 0.25.
10 d = 2
20 If int(num*d) <> num*dd then d = d + 1; GOTO 20
30 end
or
d = 2
do while int(num*d) <> num*d
d = d + 1
end do
Both give d = 4.
My only solution was to do this:
stop = 0
for x = 2 to 20
if stop = 0 then
if int(num*x) = num*d then d = x; stop = 1
end if
end for
Again, I get d = 4, but if the denominator needs to be bigger than 20 it won't work.
Does anyone have a better solution?
One flaw in the program is that it doesn't print the table in landscape on the output so the table size is limited. I didn't need any large tables so I didn't bother to fix that. And I haven't a clue how to spread this to more than a single page.
Spin inputs are at the top of the "Defined Variables" box.
The TikZ code is in the next post.
-Dan
It's a Clebsch-Gordon table generator for addition of quantum angular momentums. The TikZ coding is fairly basic, but it's probably my best TikZ work so far, not because it was so difficult to program, but because of the limitations of the TikZ Mathematics engine. (Apparently, you can't calculate (-1)^n, even if you declare n to be an integer variable, because TikZ uses a logarithm to calculate it.) I had to be innovative in a couple of cases!
My question: One of the headaches I had was converting a decimal to a fraction. Now, it's a simple process, but I found out that TikZ does not automatically use a fixed point system, and TikZ does not allow for a while loop.
That's my question. In order to convert a decimal to a fraction my plan was to start with a possible denominator of 2, multiply the number by 2, and see if I got an integer. If so, I'm done. If not, add 1 to the denominator and loop around to do it again.
I did this all the way back in 11th grade when Apple IIs were still a thing. It's not hard. BUT in BASIC I could just simply use GOTO statements to do the loop, and when I took FORTRAN we used a WHILE loop. In TikZ I had to use a FOR loop and you have to set an upper limit on size of the denominator you want to use.
Say we have num = 0.25.
10 d = 2
20 If int(num*d) <> num*dd then d = d + 1; GOTO 20
30 end
or
d = 2
do while int(num*d) <> num*d
d = d + 1
end do
Both give d = 4.
My only solution was to do this:
stop = 0
for x = 2 to 20
if stop = 0 then
if int(num*x) = num*d then d = x; stop = 1
end if
end for
Again, I get d = 4, but if the denominator needs to be bigger than 20 it won't work.
Does anyone have a better solution?
One flaw in the program is that it doesn't print the table in landscape on the output so the table size is limited. I didn't need any large tables so I didn't bother to fix that. And I haven't a clue how to spread this to more than a single page.
Spin inputs are at the top of the "Defined Variables" box.
The TikZ code is in the next post.
-Dan