In TI-83/84 BASIC, how can I factor trinomials by inputting the raw ax^2+bx+c?
If my question is unclear there is a great explainaion of what I'm attempting to do here under the section, "Method 2: The British Method": http://www.gradeamathhelp.com/how-to-factor-polynomials.html
My current program simply inputted all 3 A,B, and C variables and then assigned A*C to D
I then took the negative value of the absolute value of D and assigned it to X and Y
I then simply did if/then statements to test if X+Y=B and X*Y=D and if not, to add .5 to X until it was equal to or greater than D at which point I put X back to it's orignial value and added .5 to Y. This resulted in a memory error.
Disregarding the awful, AWFUL habit I made of using if/then statements, does anyone have a better idea of how I can solve this? (And cut me some slack, I only dabb开发者_Python百科le around in java and python and sometimes TIBasic, and I'm only a sophomore in highschool!)
Note: This code won't run because I'm recreating it, it's not the actual code, just a recreation. Syntax is all bugged up. (IE: -> is an arrow, not a negative equal sign)
I just wrote this so i might have forgotten something.
:Prompt A
:Prompt B
:Prompt C
:A*C→D
:-abs(D)→X
:-abs(D)→Y
:Lbl A
:If X+Y=B and X*Y=D
:Then
:Disp X,Y
:Pause
:Else
:X+.5→X
:Goto B
:Lbl B
:If X>D
:-abs(D)→X
:Y+.5→Y
:Goto A
Your code isn't working because you need "END" commands every time you use a "THEN" command. END is also used to close off "REPEAT", "FOR", and "WHILE" loops. Why does it need "END" for an "IF,THEN" type command? Because "IF,THEN" equates to:
If X+Y=B and X*Y=D (
In typical scripting
The "END" is like an end parentheses, and is needed because the "THEN" is like an open parentheses.
If you only have one command needing executed, do something like
If X+Y=B and X*Y=D
do this
Which is like
If X+Y=B and X*Y=D do this
I'm not sure on this because I'm not sure exactly what you want to do, but I think the code is:
:Prompt A
:Prompt B
:Prompt C
:A*C -> D
:-abs(D) -> X
:-abs(D) -> Y
:lbl A
:if X+Y=B and X*Y=D
:then
:disp X,Y
:pause
:else
:X+.5 -> X
:goto B
:end
:lbl B
:if X>D
:-abs(D) -> X
:Y+.5->Y
:goto A
Where if X+Y=B and X*Y=D, it will display the correct answer, but if not it will add 0.5 to X, and proceed to lbl B.Within lbl B, it will check to check if X>D; if X is greater than D then the negative absolute value of D will be stored as X, Y will be increased by 0.5, and it will recheck the values again in lbl A.
Also, a note on lbl B:
:if X>D
:-abs(D) -> X
:Y+.5->Y
:goto A
Will make store the negative absolute value of D as X only if X>D. Y will be increased by 0.5 whether or not X is greater than or less than D. Not sure if that's what you intended, but just in case I figured I'd bring it to your attention.
There's an easier way to do this. Setting a+bi
makes sure that the program displays imaginary numbers as well instead of giving errors. "
denotes comments. Finally, adding the last line gets rid of the "Done" message.
: "Clear and request input
: ClrHome
: a+bi
: Disp "ax^2+bx+c=0"
: Input "a. ",A
: Input "b. ",B
: Input "c. ",C
: "Doing the maths
: Disp (-B+√(B^2-4AC))/(2A)
: Disp (-B-√(B^2-4AC))/(2A)
: "
The code itself is pretty self explanatory, it asks for the variables a
, b
, and c
, when it then substitutes into the quadratic formula and prints.
Download available at: http://www.ticalc.org/pub/83/basic/math/algebra/
精彩评论