Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: Munchor on October 31, 2010, 04:16:08 pm

Title: Quadratic Formula
Post by: Munchor on October 31, 2010, 04:16:08 pm
Ok, I was programming a few little things in BASIC to learn I got this problem:

Code: [Select]
:ClrHome
:Prompt A,B,C
:(BB-(4AC))->X
:If X<0
:Then
:Disp "NO REAL ANSWER"
:Else
:(-B+sqrt(X))/(2A)->Y
:(-B-sqrt(X))/(2A)->X
:Output(6,2,"RESULTS:
:Output(7,2,X
:Output(8,2,Y

It gives me error in:

Code: [Select]
(BB-(4AC))->X
It's probably a stupid and easy mistake.

Any help?

Thanks :)
Title: Re: Quadratic Formula
Post by: jnesselr on October 31, 2010, 04:17:53 pm
BB?  Try B^2.  Also, what error? syntax? what does it highlight on the goto?
Title: Re: Quadratic Formula
Post by: Munchor on October 31, 2010, 04:20:59 pm
Tried B^2 and BB, none works.

Syntax Error, it highlights in B, of B^2-(4AC)->X.
Title: Re: Quadratic Formula
Post by: SirCmpwn on October 31, 2010, 04:21:51 pm
Lowercase B will not work, although I doubt you are doing that.  Try 2.
Title: Re: Quadratic Formula
Post by: nemo on October 31, 2010, 04:21:52 pm
B2 should fix the problem... also, this could be optimized into Ti Basic Dev's quadratic formula. or if you like your way:

Code: [Select]
ClrHome
Prompt A,B,C
B^2-4AC->X
If Ans<0:Then
Disp "NO REAL ANSWER
Else
Output(6,2,"RESULTS:
Output(7,2,-B+sqrt(X)/(2A)
Output(8,2,-B-sqrt(X)/(2A)
End
Title: Re: Quadratic Formula
Post by: Munchor on October 31, 2010, 04:23:30 pm
I tried that, B2 (two as an exponent)...
Title: Re: Quadratic Formula
Post by: nemo on October 31, 2010, 04:24:03 pm
are you typing "->" or are you using the [STO] key in the lower lefthand corner?
Title: Re: Quadratic Formula
Post by: thepenguin77 on October 31, 2010, 04:24:10 pm
Ok, sorry if this isn't the problem, but we can't over look this.

You are using the STO button to get the arrow right? Not minus greater than.

Edit:
   Ninja'd
Title: Re: Quadratic Formula
Post by: jnesselr on October 31, 2010, 04:25:05 pm
Please post the program.
Title: Re: Quadratic Formula
Post by: Munchor on October 31, 2010, 04:26:27 pm
Ok, sorry if this isn't the problem, but we can't over look this.

You are using the STO button to get the arrow right? Not minus greater than.

Edit:
   Ninja'd

OF COURSE NOT...
Title: Re: Quadratic Formula
Post by: nemo on October 31, 2010, 04:29:44 pm
so... any other ideas?
Title: Re: Quadratic Formula
Post by: Munchor on October 31, 2010, 04:31:50 pm
so... any other ideas?

Made it working:

Code: [Select]
:ClrHome
:Prompt A,B,C
:B^2-4AC→X
:If Ans<0:Then
:Disp "NO REAL ANSWER
:Else
:Output(6,2,"RESULTS:
:Output(7,2,-B+sqrt(X)/(2A)
:Output(8,2,{-}B-sqrt(X)/(2A)
:End

Thanks
Title: Re: Quadratic Formula
Post by: Michael_Lee on October 31, 2010, 06:09:53 pm
Or better yet...

Code: [Select]
:ClrHome
:a+bi                             (Found in the [MODE] menu, allows imaginary numbers)
:2->dim(L₁
:Disp "AX²+BX+C=0
:Prompt A,B,C
:(-B+√(B²-4AC))/(2A->L₁(1
:(-B-√(B²-4AC))/(2A->L₁(2
:Pause L₁

Allows imaginary numbers!  (Scroll for answer, don't keep anything important in L1)

Edited:  Thanks, Qwerty.55
Title: Re: Quadratic Formula
Post by: AngelFish on October 31, 2010, 06:29:35 pm
The Superscript and subscript tags don't work in a code block. Try alt codes:

Code: [Select]
:ClrHome
:a+bi                             (Found in the [MODE] menu, allows imaginary numbers)
:2->dim(L₁
:Disp "AX²+BX+C=0
:Prompt A,B,C
:(-B+√(B²-4AC))/(2A->L₁(1
:(-B-√(B²-4AC))/(2A->L₁(2
:Pause L₁

EDIT: Sorry if this shows up a few hours late. I think I'm using the bandwidth for the whole building right now.
Title: Re: Quadratic Formula
Post by: Deep Toaster on October 31, 2010, 06:38:53 pm
So what was the error?
Title: Re: Quadratic Formula
Post by: Munchor on October 31, 2010, 06:40:24 pm
Yeah, I knew that it allowed imaginary numbers, but I haven't learn them at school yet =P
Title: Re: Quadratic Formula
Post by: Michael_Lee on October 31, 2010, 06:42:57 pm
Oh.  If this isn't too intrusive, may I ask what math level you're currently taking?
Title: Re: Quadratic Formula
Post by: Munchor on October 31, 2010, 06:45:16 pm
Oh.  If this isn't too intrusive, may I ask what math level you're currently taking?

10th grade in portugal
Title: Re: Quadratic Formula
Post by: meishe91 on October 31, 2010, 08:12:01 pm
Out of how many grades? I don't know the Portugal schooling system.

Also, could you post the original program you had instead of nemo's one that fixed the issue. I think we're all still curious about what was originally going on with the error and that would help figure it out.
Title: Re: Quadratic Formula
Post by: Xeda112358 on November 01, 2010, 01:07:38 am
(sorry, but I had to optimize a little  ;D)

Code: [Select]
:ClrHome
:a+bi                             (Found in the [MODE] menu, allows imaginary numbers)
:Disp "AX²+BX+C=0
:Prompt A,B,C
:√(B²/4-AC
:Pause -B/(2A)+{Ans,-Ans

This won't use L₁, either. If you do want to store it to L₁, then just do Ans→L₁ after running the program because Ans will contain the results.
Title: Re: Quadratic Formula
Post by: calcdude84se on November 01, 2010, 08:30:09 pm
(sorry, but I had to optimize a little  ;D)
And I has to optimize it more. :P Also, your code doesn't work; it would have to be √(B²/4-AC)/A :(
Code: [Select]
:ClrHome
:Disp "AX²+BX+C=0
:Prompt A,B,C
:Pause -(B+{1,-1}√(B²+4i²AC))/(2A
Doesn't even change the mode settings ;D
Title: Re: Quadratic Formula
Post by: Michael_Lee on November 01, 2010, 09:00:47 pm
Code: [Select]
:ClrHome
:Disp "AX²+BX+C=0
:Prompt A,B,C
:Pause -(B+{1,-1}√(B²+4i²AC))/(2A
Doesn't even change the mode settings ;D

O.o
That's hyper-optimized!  If you remove the ClrHome and the Disp, you can get it to be under 50 bytes!
Does using i allow for an imaginary output even if you don't mess with the mode settings?
Title: Re: Quadratic Formula
Post by: calcdude84se on November 01, 2010, 09:05:01 pm
Indeed :) A number that's already "imaginary" (even if that imaginary part is 0) will not give an error when you try to take its square root.
Title: Re: Quadratic Formula
Post by: Runer112 on November 01, 2010, 09:05:06 pm
(sorry, but I had to optimize a little  ;D)
And I has to optimize it more. :P Also, your code doesn't work; it would have to be √(B²/4-AC)/A :(
Code: [Select]
:ClrHome
:Disp "AX²+BX+C=0
:Prompt A,B,C
:Pause -(B+{1,-1}√(B²+4i²AC))/(2A
Doesn't even change the mode settings ;D

Two can play the optimization game. :P

Code: [Select]
:ClrHome
:Disp "AX²+BX+C=0
:Prompt A,B,C
:-B+{1,-1}√(B²+4i²AC
:Pause Ans/(2A
Title: Re: Quadratic Formula
Post by: calcdude84se on November 01, 2010, 09:07:59 pm
Congratulations, you win. :D
* calcdude, admitting defeat, bows to Runer in acknowledgement of his victory.
Title: Re: Quadratic Formula
Post by: nemo on November 01, 2010, 09:24:56 pm
(sorry, but I had to optimize a little  ;D)
And I has to optimize it more. :P Also, your code doesn't work; it would have to be √(B²/4-AC)/A :(
Code: [Select]
:ClrHome
:Disp "AX²+BX+C=0
:Prompt A,B,C
:Pause -(B+{1,-1}√(B²+4i²AC))/(2A
Doesn't even change the mode settings ;D

Two can play the optimization game. :P

But only one may win...

Code: [Select]
:ClrHome
:Disp "AX²+BX+C=0
:Prompt A,B,C
:B+{1,-1}√(B²+4i²AC
:Pause -2C/Ans
Title: Re: Quadratic Formula
Post by: Runer112 on November 01, 2010, 09:30:33 pm
(sorry, but I had to optimize a little  ;D)
And I has to optimize it more. :P Also, your code doesn't work; it would have to be √(B²/4-AC)/A :(
Code: [Select]
:ClrHome
:Disp "AX²+BX+C=0
:Prompt A,B,C
:Pause -(B+{1,-1}√(B²+4i²AC))/(2A
Doesn't even change the mode settings ;D

Two can play the optimization game. :P

But only one may win...

Code: [Select]
:ClrHome
:Disp "AX²+BX+C=0
:Prompt A,B,C
:B+{1,-1}√(B²+4i²AC
:Pause -2C/Ans

:o that works? In which case...

Code: [Select]
:ClrHome
:Disp "AX²+BX+C=0
:Prompt A,B,C
:Pause -2C/(B+{1,-1}√(B²+4i²AC
Title: Re: Quadratic Formula
Post by: nemo on November 01, 2010, 09:32:00 pm
oops. how'd i miss that.

but yeah, alternate form of the quadratic formula.
Title: Re: Quadratic Formula
Post by: AngelFish on November 01, 2010, 09:38:56 pm
But only one may win...
Quote
Code: [Select]
:ClrHome
:Disp "AX²+BX+C=0
:Prompt A,B,C
:B+{1,-1}√(B²+4i²AC
:Pause -2C/Ans

:o that works? In which case...

Code: [Select]
:ClrHome
:Disp "AX²+BX+C=0
:Prompt A,B,C
:Pause -2C/(B+{1,-1}√(B²+4i²AC

And the winner is...

Code: [Select]
:ClrHome
:Pause "GOOGLE IT

 ;)

Only 11 bytes!
Title: Re: Quadratic Formula
Post by: Runer112 on November 01, 2010, 09:42:07 pm
But only one may win...
Quote
Code: [Select]
:ClrHome
:Disp "AX²+BX+C=0
:Prompt A,B,C
:B+{1,-1}√(B²+4i²AC
:Pause -2C/Ans

:o that works? In which case...

Code: [Select]
:ClrHome
:Disp "AX²+BX+C=0
:Prompt A,B,C
:Pause -2C/(B+{1,-1}√(B²+4i²AC

And the winner is...

Code: [Select]
:ClrHome
:Pause "GOOGLE IT

 ;)

Only 11 bytes!


Oh really?

Code: [Select]
:ClrHome
:Pause "JFGI"
Title: Re: Quadratic Formula
Post by: AngelFish on November 01, 2010, 09:46:57 pm
You left an extra parenthesis  :P

Code: [Select]
:ClrHome
:Pause "JFGI

Meh, let the user clear the screen:

Code: [Select]
:Pause "JFGI
Title: Re: Quadratic Formula
Post by: nemo on November 01, 2010, 09:50:04 pm
why pause it anyway?
Code: [Select]
"JFGI
Title: Re: Quadratic Formula
Post by: meishe91 on November 01, 2010, 10:10:41 pm
And the official winner is...Runer112 with 54 bytes :P

Xeda had the first hyper optimization and then calcdude84se optimized it again. Runer112 then did an optimization that, in turn, actually wasn't since they resulted in the exact same size (since the new line accounts for the taking off two parentheses). Nemo then optimized it again and then Runer112 optimized again by taking out that last line.

If you want a winner the the latest one I would go with me with:

Code: [Select]
"GI
Who really needs the "Just F******" part? ;)
Title: Re: Quadratic Formula
Post by: Builderboy on November 02, 2010, 01:21:23 am
Taken from Cemetech:

Code: [Select]
:Prompt A,B,C
:(-B+sqrt(B^2-4AC))/(2A
:Disp Ans, -B/A-Ans
Title: Re: Quadratic Formula
Post by: Xeda112358 on November 02, 2010, 01:42:26 am
As long as we are keeping the list output (as a pause) and the
Code: [Select]
:ClrHome
:Disp "AX²+BX+C=0

Then here is a smaller version (by 1 byte):

:ClrHome
:Disp "AX²+BX+C=0
:Prompt A,B,C
:√(B²+4i²AC
:Pause .5A-1(-B+{Ans,-Ans


(The code box didn't allow the -1)
Title: Re: Quadratic Formula
Post by: meishe91 on November 02, 2010, 03:46:20 am
As long as we are keeping the list output (as a pause) and the
Code: [Select]
:ClrHome
:Disp "AX²+BX+C=0

Then here is a smaller version (by 1 byte):

:ClrHome
:Disp "AX²+BX+C=0
:Prompt A,B,C
:√(B²+4i²AC
:Pause .5A-1(-B+{Ans,-Ans


(The code box didn't allow the -1)

It's smaller than who's by one byte?
Title: Re: Quadratic Formula
Post by: yunhua98 on November 03, 2010, 06:19:59 pm
couldn't you use -4AC instead of i^2?  or am i missing something?
Title: Re: Quadratic Formula
Post by: Runer112 on November 03, 2010, 06:22:29 pm
Having i2 forces the calculator to evaluate the expression as complex numbers, so the square root function won't throw an error and you can find imaginary roots.
Title: Re: Quadratic Formula
Post by: yunhua98 on November 03, 2010, 06:23:33 pm
couln't you set the mode to a+bi at the beginning?
Title: Re: Quadratic Formula
Post by: meishe91 on November 03, 2010, 06:25:21 pm
Having i2 forces the calculator to evaluate the expression as complex numbers, so the square root function won't throw an error and you can find imaginary roots.

Plus it's two bytes smaller :P
Title: Re: Quadratic Formula
Post by: nemo on November 03, 2010, 06:25:24 pm
couln't you set the mode to a+bi at the beginning?

this changes the mode setting, and adds just as many bytes as i2 anyway.
Title: Re: Quadratic Formula
Post by: yunhua98 on November 03, 2010, 06:31:11 pm
kk, cool, you learn something new everyday.  ;)
Title: Re: Quadratic Formula
Post by: Xeda112358 on November 04, 2010, 03:00:08 am
Sorry, in my program above, on my calculator I forgot the :ClrHome part. hehe...