Hi
I'm relatively new to programming, though I have done very basic programs for my calculator
I'm trying to write a program that returns with the simplification of surds
e.g.
√128 simplifies to 8√2
The formula that I want to use for this is √(a/b)=c which translates into c√b
i.e.
in the above example 128=a and 8√2 is c√b
What I plan to do is something like this:
?->a
1->b
if √(a/b) has no decimal places
then √(a/b)->c
otherwise b++
Then I want it to display is in the form of c√b
Will this work?:
disp a_"√"c_ work
Basically I need help with the decimal places and the display area of this program
Any help is appreciated
Help With A Program For Surds - Fx-9750 Plus
Started by
Deathblake
, Feb 19 2009 03:49 AM
5 replies to this topic
#1
Posted 19 February 2009 - 03:49 AM
#2
Posted 19 February 2009 - 04:57 PM
Hello,
I think you're going to have to factorise the input number in order to find its square factors.
for example, factoring 128 gives 2, 7 times (ie 2^7 = 128). Therefore, 128 = 2*(2^6), so sqrt(128) = 2^3*sqrt(2) = 8sqrt(2)
another, sqrt(90) ?
90 = 2*3*3*5. since 3 occurs twice we have the root as 3*sqrt(2*5) = 3sqrt(10).
For small(ish) integers you could factor by trial division.
I think you're going to have to factorise the input number in order to find its square factors.
for example, factoring 128 gives 2, 7 times (ie 2^7 = 128). Therefore, 128 = 2*(2^6), so sqrt(128) = 2^3*sqrt(2) = 8sqrt(2)
another, sqrt(90) ?
90 = 2*3*3*5. since 3 occurs twice we have the root as 3*sqrt(2*5) = 3sqrt(10).
For small(ish) integers you could factor by trial division.
Edited by Hugh, 19 February 2009 - 04:58 PM.
#3
Posted 19 February 2009 - 07:16 PM
Thanks
This is (basically) the way we have manually been doing it in class.
I've been sleeping on the program, and here is what I have come up with
?->A
1->B
While (√((A/B)-Int (√A/B))!=0
Do
B+1->B
WhileEnd
√(A/B)->C
C_
H_
_ is the little triangle right?
The only problem is that I can only execute it once, because after it returns my numbers it causes a syntax error
EDIT: I've been playing around with it today and this is what I have come up with
[codebox]Lbl 1
?->A
If A=0
Then Goto 2 // The forumula doesn't handle 0 as an input
IfEnd
1->B
While (√((A/B)-Int (√A/B))!=0
Do
B+1->B
WhileEnd
√(A/B)->C // The basic function is now complete, the following is now to calculate how to display
Int (logB+1)->D // D=number of digits in B
Int (lobC+1)->E
22-(D+E+1)->F
22-(D+1)->G
22-D->H
Locate F,6,C
Locate G,6,"√"
Locate H,6,B
Goto 1
Lbl 2
Locate 21,6,0
Goto 1[/codebox]
What do I add to make the Exit key Exit the program and return to normal RUN mode?
This is (basically) the way we have manually been doing it in class.
I've been sleeping on the program, and here is what I have come up with
?->A
1->B
While (√((A/B)-Int (√A/B))!=0
Do
B+1->B
WhileEnd
√(A/B)->C
C_
H_
_ is the little triangle right?
The only problem is that I can only execute it once, because after it returns my numbers it causes a syntax error
EDIT: I've been playing around with it today and this is what I have come up with
[codebox]Lbl 1
?->A
If A=0
Then Goto 2 // The forumula doesn't handle 0 as an input
IfEnd
1->B
While (√((A/B)-Int (√A/B))!=0
Do
B+1->B
WhileEnd
√(A/B)->C // The basic function is now complete, the following is now to calculate how to display
Int (logB+1)->D // D=number of digits in B
Int (lobC+1)->E
22-(D+E+1)->F
22-(D+1)->G
22-D->H
Locate F,6,C
Locate G,6,"√"
Locate H,6,B
Goto 1
Lbl 2
Locate 21,6,0
Goto 1[/codebox]
What do I add to make the Exit key Exit the program and return to normal RUN mode?
Edited by Deathblake, 20 February 2009 - 06:24 AM.
#4
Posted 21 February 2009 - 04:15 PM
Hello,
Your method will work, although i don't know the answer to your programming question for this language. I don't use the built-in programming system at all.
What your method is doing is trying to divide out the non-square factors leaving the square factor remaining (if any). Consequently your value for B will range from 1 to A and will get quite slow if A is large.
As another approach, you could try to divide out the square factor. Here is the general idea:
if A has a square factor, it has a factor b <= sqrt(A).
loop b from 2 to sqrt(A)
if b^2 exactly divides A, then multiply b into the square factor (to return) and divide A by b^2 continue
otherwise increase b by 1 and continue.
Here's some LUA code that does what im talking about, maybe you can recode it for your casio.
[codebox]function surd(A)
sq = 1 -- will be the square factor on return
N = math.sqrt(A)
b = 2
while b <= N
do
b2 = b*b
q = math.floor(A/b2) -- INT of A/b^2
if A == q*b2 -- is it a factor?
then
-- yes, keep the square factor and reduce A
sq = sq * b;
A = q
else
-- otherwise move on to next b
b = b + 1
end
end
-- return two values, the square factor and reduced A
return sq, A
end
[/codebox]
Good Luck!
Your method will work, although i don't know the answer to your programming question for this language. I don't use the built-in programming system at all.
What your method is doing is trying to divide out the non-square factors leaving the square factor remaining (if any). Consequently your value for B will range from 1 to A and will get quite slow if A is large.
As another approach, you could try to divide out the square factor. Here is the general idea:
if A has a square factor, it has a factor b <= sqrt(A).
loop b from 2 to sqrt(A)
if b^2 exactly divides A, then multiply b into the square factor (to return) and divide A by b^2 continue
otherwise increase b by 1 and continue.
Here's some LUA code that does what im talking about, maybe you can recode it for your casio.
[codebox]function surd(A)
sq = 1 -- will be the square factor on return
N = math.sqrt(A)
b = 2
while b <= N
do
b2 = b*b
q = math.floor(A/b2) -- INT of A/b^2
if A == q*b2 -- is it a factor?
then
-- yes, keep the square factor and reduce A
sq = sq * b;
A = q
else
-- otherwise move on to next b
b = b + 1
end
end
-- return two values, the square factor and reduced A
return sq, A
end
[/codebox]
Good Luck!
#5
Posted 26 February 2009 - 09:22 AM
Thanks
While I don't get how your while loop works, I understand the basic idea behind it
However, to simplify fully, you need to make b an INT of Sqrt a, and decrease it each time
Here is my amended (and hopefully final) code:
[codebox]Lbl 1
?->A
If A=0
Then Goto 2 // The forumula doesn't handle 0 as an input
IfEnd
Int √A->B
While ((A/B^2 -Int A/B^2)!=0
Do
B-1->B
WhileEnd
A/B^2->C // The basic function is now complete, the following is now to calculate how to display
Int (logB+1)->D // D=number of digits in B
Int (lobC+1)->E
22-(D+E+1)->F
22-(E+1)->G
22-E->H
Locate F,6,B
Locate G,6,"√"
Locate H,6,C
Goto 1
Lbl 2
Locate 19,6,1
Locate 20,6,"√"
Locate 21,6,0
Goto 1[/codebox]
While I don't get how your while loop works, I understand the basic idea behind it
However, to simplify fully, you need to make b an INT of Sqrt a, and decrease it each time
Here is my amended (and hopefully final) code:
[codebox]Lbl 1
?->A
If A=0
Then Goto 2 // The forumula doesn't handle 0 as an input
IfEnd
Int √A->B
While ((A/B^2 -Int A/B^2)!=0
Do
B-1->B
WhileEnd
A/B^2->C // The basic function is now complete, the following is now to calculate how to display
Int (logB+1)->D // D=number of digits in B
Int (lobC+1)->E
22-(D+E+1)->F
22-(E+1)->G
22-E->H
Locate F,6,B
Locate G,6,"√"
Locate H,6,C
Goto 1
Lbl 2
Locate 19,6,1
Locate 20,6,"√"
Locate 21,6,0
Goto 1[/codebox]
#6
Posted 15 March 2009 - 08:09 PM
Lbl 1?->AIf A=0Then Goto 2 // The forumula doesn't handle 0 as an inputIfEndInt √A->BWhile ((A/B^2 -Int A/B^2)!=0DoB-1->BWhileEndA/B^2->C // The basic function is now complete, the following is now to calculate how to displayInt (logB+1)->D // D=number of digits in BInt (lobC+1)->E22-(D+E+1)->F22-(E+1)->G22-E->HLocate F,6,BLocate G,6,"√"Locate H,6,CGoto 1Lbl 2Locate 19,6,1Locate 20,6,"√"Locate 21,6,0Goto 1
Hi there, I tried your code above and it did not work flawlessly as expected. I have improved upon your program and came up with the following that is foolsproof. (NB. I have used different variables but this doesnt matter)
Lbl 11->A?->XRoot(X)->KFor 2->I To (Int K)If (X/I^2)=Int (X/I^2)ThenAxI->I(X/(I^2))->XIfEndNextInt (Log A+1)->DInt (Log X+1)->E22-(D+E+1)->F22-(E+1)->G22-E->HLocate F,6,ALocate G,6,"Root"Locate H,6,XGoto 1
You may have noticed that I use some of your code in the last few lines . Also 'Root' in my code simply means the Square root sign (I didnt know how to use it on the message)
If this code does not work for you or you have a question to ask me, then simply PM me or reply here.
Hope that this helps,
mintsmike
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users