As I've stated in other posts, I'm working on a trig program bundle, with one of the functions being deg/rad and rad/deg conversion. However, I want to be able to view the coefficients of pi as fractions rather than decimals. For instance, if I type in the deg>rad section, "30", I get pi * .166666666... which, while correct, I want to have it displayed as "1/6." Not sure if it's possible, but I'm trying to make the program look nice. If it helps, I use a TI-84+CSE. and this is the code: (I'm aware the code doesn't work due to the "Goto Z" at the end, but that's because I'm planning to slot the code into the main program, so the error is intentional (for now at least.))


Code:
Lbl CM
Menu("SELECT","DEG TO RAD",DA,"RAD TO DEG",DB,"BACK",DC)
Lbl DA
Degree
Input "ANGLE: ",θ
ClrHome
Output(1,1,"DEGREES: ")
Output(1,10,θ)
Output(2,1,"RADIANS: ")
Radian
θį→N
N/π→N
Output(2,10,"π*")
Output(2,12,N)
Pause
Goto CM
Lbl DB
Radian
ClrHome
Input "RADIANS: ",R
ClrHome
Degree
Rį→D
Output(1,1,"RADIANS: ")
Output(1,10,R)
Output(2,1,"DEGREES: ")
Output(2,10,D)
Pause
ClrHome
Goto CM
Lbl DC
Goto Z


Thanks in advance!
You might be able to use the Frac function on the calculator.
dave1707 wrote:
You might be able to use the Frac function on the calculator.


I tried doing this through the program but all it returns is the decimal output. Iíve tried searching for assembly stuff too, but Iím not sure itís compatible. Itís this:

Code:
Asm(FD360A0CC9)
I found it in a review of the TI-84+CE. All I get when I run it using my 84+CSE is a syntax error. Is it just not compatible?

Also, I tried FRAC-APPROX mode but it didnít print N when I had the mode changed.
If the decimal number isnít close enough to be a fraction, then the Frac function wonít convert it to a fraction. Go to this web site http://tibasicdev.wikidot.com/home and do a search for decimal to fraction in the upper right of the screen. It will give you several pages of routines that you can try.
portal3 wrote:
dave1707 wrote:
You might be able to use the Frac function on the calculator.


I tried doing this through the program but all it returns is the decimal output. Iíve tried searching for assembly stuff too, but Iím not sure itís compatible. Itís this:

Code:
Asm(FD360A0CC9)
I found it in a review of the TI-84+CE. All I get when I run it using my 84+CSE is a syntax error. Is it just not compatible?

Also, I tried FRAC-APPROX mode but it didnít print N when I had the mode changed.

That's not how Asm() works.
Asm() is a token used to run a compiled assembly program, there's no inline assembly support in pure TI-Basic.

You'll want to do a Disp Ans=>Frac or Output(X, Y, Ans=>Frac). If the calculator's Frac support cannot convert to a fraction, then it's probably an irrational number.
ACagliano wrote:
portal3 wrote:
dave1707 wrote:
You might be able to use the Frac function on the calculator.


I tried doing this through the program but all it returns is the decimal output. Iíve tried searching for assembly stuff too, but Iím not sure itís compatible. Itís this:

Code:
Asm(FD360A0CC9)
I found it in a review of the TI-84+CE. All I get when I run it using my 84+CSE is a syntax error. Is it just not compatible?

Also, I tried FRAC-APPROX mode but it didnít print N when I had the mode changed.

That's not how Asm() works.
Asm() is a token used to run a compiled assembly program, there's no inline assembly support in pure TI-Basic.

You'll want to do a Disp Ans=>Frac or Output(X, Y, Ans=>Frac). If the calculator's Frac support cannot convert to a fraction, then it's probably an irrational number.

From what Iíve read >Frac doesnít work with programs. Lovely. I think just converting it to a fraction after I run the program will be my best bet.
Frac does work in a program. Hereís an example that goes from .1 to 1 in steps of .01. Press enter after each display


Code:

For(A,.1,1,.01
Disp A,A►Frac
Disp ďPRESS ENTERĒ
Pause
End
dave1707 wrote:
Frac does work in a program. Hereís an example that goes from .1 to 1 in steps of .01. Press enter after each display


Code:

For(A,.1,1,.01
Disp A,A►Frac
Disp ďPRESS ENTERĒ
Pause
End

So I tested it and it works, but is there a way to use it through the Output command?
Same way, i would assume?
ACagliano wrote:
Same way, i would assume?


I tried doing N>Frac then outputting it, as well as doing N>Frac within the output command. 1st returned the decimal, and 2nd returned a syntax error
This isnít the greatest, but it kind of works. To test it, just do sin( and some value) at the input prompt.


Code:

ClrHome
Input A
iPart(A*100)→A
gcd(A,100)→E
toString(A/E)→Str1
toString(100/E)→Str2
Str1+Ē/ď+Str2→Str3
Output(7,5,Str3
dave1707 wrote:
This isnít the greatest, but it kind of works. To test it, just do sin( and some value) at the input prompt.


Code:

ClrHome
Input A
iPart(A*100)→A
gcd(A,100)→E
toString(A/E)→Str1
toString(100/E)→Str2
Str1+Ē/ď+Str2→Str3
Output(7,5,Str3


Doesnít look like I have the toString command. Would Equ>String work?
Thereís a way to do it with the Equ>String command, but I think itís more trouble than just leaving your answer as a decimal number. See my post below. That might work for you.
You might be able to use the eval( function.

eval(A/E)->Str1
eval(100/E)->Str2
dave1707 wrote:
You might be able to use the eval( function.

eval(A/E)->Str1
eval(100/E)->Str2


Dunno if the TI-84+CSE is some sort of obscure version of calc, but I'm not seeing eval( in the catalog. I'm really hoping there's a way I can get it to work.
I donít know what the difference is between the TI84+CSE and the TI84+CE. Apparently the basic code is different.
Both eval( and toString( were added for the CE, and all previous calcs do not have those tokens. Your best bet is probably to convert to a fraction using an algorithm that gets the numerator and denominator, then display the numerator, then a /, then the denominator.
commandblockguy wrote:
Both eval( and toString( were added for the CE, and all previous calcs do not have those tokens. Your best bet is probably to convert to a fraction using an algorithm that gets the numerator and denominator, then display the numerator, then a /, then the denominator.


Thanks for letting me know. My current goal with the conversion program is working to display the fraction as a coefficient, strung out on the same line as the "pi *" string. I found a program that does conversions of decimals to fractions and lists the fraction approximation, and I want to see if I can use it within the code I have for the conversion stuff itself. Credits to Anders Tiberg for what I found in ticalc:

Code:
CLASSIC
ClrHome
Input "EXPRESSION?",Str1
3+int((11+length(Str1))/26→θ
Disp "
expr(Str1→F
abs(F→Y
0→C
1→D
0→E
1→Z
While Y>≠7D
Dint(Y→C
D/Y→D
fPart(Y→Y
If Z/(Y+(Y=0))>2 and E=0
round(C,0→E
Y→Z
End
round(EF,0→J
If D-C>.005D
Then
Disp F
Else
round(C,0→D
While fPart(round(FD,5
D+1→D
End
round(FD,0→G
2+(F<0)+int(log(abs(G→H
Output(θ,1,G
If D>1
Then
Output(θ,H,"/
Output(θ,H+1,D
If 1<abs(F
Then
H+3+int(log(D→H
Output(θ,H,"OR
θ+1→θ
FD-DiPart(F→I
1+int(log(abs(I→G
2+(F<0)+int(log(abs(F→H
Output(θ,1,iPart(F
Output(θ,H,"-
If F≥0
Output(θ,H,"+
Output(θ,H+1,abs(I
Output(θ,G+H+1,"/
Output(θ,G+H+2,D
Disp "
End
End
If E and D>2E and 1=gcd(E,abs(J
Disp "
End
If E and D>2E and 1=gcd(E,abs(J
Then
θ+2→θ
Output(θ-1,1,"APPROX:
2+(F<0)+int(log(abs(J→H
Output(θ,1,J
If E>1
Then
Output(θ,H,"/
Output(θ,H+1,E
End
Disp "
End
"
This works somewhat.


ClrHome
Input A
iPart(A*100)→A
gcd(A,100)→E
Output(7,3,A/E)
Output(7,5,Ē/ď)
Output(7,6,100/E)
dave1707 wrote:
This works somewhat.


ClrHome
Input A
iPart(A*100)→A
gcd(A,100)→E
Output(7,3,A/E)
Output(7,5,Ē/ď)
Output(7,6,100/E)


I guess itís close enough. I noticed that I when I do 2.7777777, I get 27/100, when I should get something like 25/9. Is that due to using the GCD of A and 100? Also, is there anyway this can be put into the conversion program that I created?
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement