This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's TI-BASIC subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. TI-Basic => TI-BASIC
Author Message
haun


Advanced Newbie


Joined: 14 Sep 2008
Posts: 54

Posted: 08 Sep 2009 05:20:44 pm    Post subject:

ok so i have a way to factor polynomials (AX²+BX+C) by calculator, but i am having problems doing this in code
normally what you do is multiply the first and last coefficients (A*C=Factors) and keep the middle one as the addition

For people in school this is know as the F 'n A method and it is quite useful.

In a calculator you multiply A and B then divide it by a list {1,2,3,4,5,6,7,8,9,10} and store it in a second list.
then you add list1 and list2 and store that too. then you look down list3 for b. when you find it, you take the number from list1's corresponding row.

i have all this down in basic. the only problem is the loop that looks for b in L1(x)+L2(X) (X is the row)


Code:
For(X,1,10,1)
If L5(X)+L6(X)=B
End


this is the loop i have, and it does not report the correct number

I have been using: 3X²-16X-12 and the 2 numbers i am looking for are 2 and -18, but it returns 1, -36. this means that the loop is only running once.

what seems to be wrong with this loop

thanks!
Back to top
calc84maniac


Elite


Joined: 22 Jan 2007
Posts: 770

Posted: 08 Sep 2009 05:40:18 pm    Post subject:

The End won't be run if the condition is false (which also causes a memory leak). Try this:

Code:
:1->X
:While X<=10 and B!=L5(X)+L6(X
:X+1->X
:End


Last edited by Guest on 05 Jul 2010 08:07:57 am; edited 1 time in total
Back to top
haun


Advanced Newbie


Joined: 14 Sep 2008
Posts: 54

Posted: 08 Sep 2009 05:44:30 pm    Post subject:

thank you good sir! I now have to spend less time doing pointless things in math
Back to top
DrDnar


Member


Joined: 28 Aug 2009
Posts: 116

Posted: 11 Sep 2009 05:54:27 am    Post subject:

I wrote a quadratic factorer a while ago. Guaranteed to find all possible fatorings of any quadratic that can be factored. Eventually. Ans must always be a number when you start the program.

Code:
::
:
:If Ans=1337.666
:Goto F1
:
:Disp "factor aX²+bX+c
:
:Input "a=",A
:Input "b=",B
:Input "c=",C
:
:Disp "factoring a..."
:A→S
:1337.666:prgmQFACTOR3
:∟TEMP→∟FA
:Disp "factoring c...
:C→S
:1337.666:prgmQFACTOR3
:∟TEMP→∟FC
:
:Disp "Finding all","possible answers","Smash ON to stop"
:
:Disp "form=","(hX+i)(kX+j)
:Disp "       {h,i,k,j}
:
:0→R
:For(F,1,4
:For(D,1,dim(∟FA
:For(E,1,dim(∟FC
:∟FA(D→H
:A/H→K
:∟FC(E→I
:C/I→J
:If F=2 or F=4
:‾I→I
:If F≥3
:‾J→J
:
:Output(1,1,{F,D,E
:If HK=A and HJ+IK=B and IJ=C
:Then
:Disp {H,I,K,J
:1→R
:End
:End
:End
:End
:
:If R=0
:Disp "Failed to factor"
:
:Disp "        ...done!
:DelVar ∟TEMP
:5
:Output(1,1,"
:Stop
:
:
:Lbl F1
:abs(S→S
:DelVar ∟TEMP
:{1,S→∟TEMP
:
:0→T
:0→U
:0→V
:0→W
:3→T
:2→U
:S→W
:
:While U≤S
:S/U→V
:If W=V
:Return
:Output(1,1,U
:
:If V=int(V
:Then
:V→∟TEMP(T
:S/V→∟TEMP(T+1
:T+2→T
:S/V→W
:Disp {V,S/V
:End
:U+1→U
:End

I actually have four versions of the program with minor differences. I no longer remember why, but this is the version I decided always to use.

So who knows a way to do this five times faster at one-tenth the size?
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 11 Sep 2009 08:39:53 am    Post subject:

Prompt A,B,C
C+B[font="times new roman"]i
-A→D
round(Ans/([font="times new roman"]i
+2C/(B+{1,‾1}√(B[font="verdana"]²+4AC[font="times new roman"]i[font="verdana"]²
Ans/gcd(abs(real(Ans)),abs(imag(Ans
augment({D/prod(Ans)},Anstanh(E9A

If I remember correctly, this doesn't capture all non-factorable polynomials, but it will factor any quadratic that is capable of being factored.

For example, -538965x[font="verdana"]² + 8902085x + 5934690 will return -5(-1081 + 63x)(1098 + 1711x) in about half a second.

Last edited by Guest on 05 Jul 2010 08:07:26 am; edited 1 time in total
Back to top
DrDnar


Member


Joined: 28 Aug 2009
Posts: 116

Posted: 11 Sep 2009 09:47:23 am    Post subject:

That's beautiful.

Using i for x is genius. By coincidence we just learned about hyperbolic tangent today in calculus. So what exactly is this doing?
Back to top
Roy192837


Newbie


Joined: 09 May 2009
Posts: 2

Posted: 12 Sep 2009 04:22:08 pm    Post subject:

[quote name='Dr. D'nar' post='136433' date='Sep 11 2009, 04:47 PM']That's beautiful.

Using i for x is genius. By coincidence we just learned about hyperbolic tangent today in calculus. So what exactly is this doing?[/quote]
Beautiful indeed, that 'tanh(E9A)' gives back the sign of A (A<0 gives -1; A>0 gives 1; A=0 gives 0).
Back to top
Mapar007


Advanced Member


Joined: 04 Oct 2008
Posts: 365

Posted: 13 Sep 2009 03:58:07 am    Post subject:

Use of rounding errors to your advantage... xD
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 13 Sep 2009 07:32:00 am    Post subject:

Mapar007 wrote:
Use of rounding errors to your advantage... xD
No, there are no rounding errors (or rather, abuse thereof): limx→∞ tanh(x) = 1 and limx→-∞ tanh(x) = -1.

If I really wanted to make a fuss, I'd've used tanh(17A) – it works the same (except it's slower).

Here is the gist of the program:

Take Ax[font="verdana"]²+Bx+C
, substitute [font="times new roman"]i for x, and then simplify. That's line two.

Everything in line three following [font="times new roman"]i+ is the quadratic formula. "x" is added to both of these terms to begin rebuilding the factors, e.g., ([font="times new roman"]i+r1)([font="times new roman"]i+r2). As this won't inherit the GCF of the originating coefficients, there may be fractional parts left over; dividing the D "polynomial" by this number resolves the issue by restoring the missing factor. The round( at the start takes care of that occasional stray E-14, as seen in 3x[font="verdana"]²+x-2.

There might be at this point something like (12+10[font="times new roman"]i)(-20+10[font="times new roman"]i). This becomes simplified in line four: taking the gcd( of the real parts and the imaginary parts separately (if you didn't know, these commands can operate on lists – check your manual!) and dividing them out will finalize the factors involving the roots. The fifth line prepends the GCF and reestablishes the sign that otherwise might not have made it past the gcd(.

I hope this disentangles my program slightly. Things like D/prod(Ans), for instance, are probably best understood if you understand enough for it to come naturally. Revealing the answer outright might instigate more harm than good, if you measure afterward what learning was missed on the way to knowing it! That's just my philosophy.

Last edited by Guest on 05 Jul 2010 08:28:06 am; edited 1 time in total
Back to top
Display posts from previous:   
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
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement