When I was in high school, I figured out how to program my TI-84 Plus calculator to do quadratic equations for me. Like the goody-two-shoes I was, I deleted the program before the final exam. I am trying to recreate the program now, but it's not working well. Here's my code:
:Prompt A, B, C
:(-B+√(B²-4AC))/2A→Y
:(-B-√(B²-4AC))/2A→Z
:Disp Y
:Disp Z
(→
corresponds to the STO> (store) button on the calculator, which allows a user to set a value for a given letter variable.)
As far as I can tell, this should work. The math and the parentheses seem to be in order, the Prompt
function works (after the program finishes, asking the calculator to print A, B, and C match the values stored from the last time the program was run).
When I ask it to calculate quadratic equations that I already know the answers to, it gives me funny numbers. Entering A=1
, B=-3
, C=2
, which should return x-intercept values of 1 and 2, returns 2 and 0 instead. The x-intercepts of 0=3x²-10x+7 are 1 and 7/3, but the calculator returns 21 and 0. I can't reproduce it right now, but the this program has also returned some imaginary numbers where there shouldn't have been.
What's wrong with this code? The math works (inputting the second and third lines of code into the calculator to calculate, as opposed to lines of code in a program, after storing values in the variables does return the correct value), the Prompt
and Disp
functions work; what's wrong here?
Order of operations strikes again. The expression
(-B+√(B²-4AC))/2A
is being parsed as
((-B+√(B²-4AC))/2)*A
Add parentheses to /(2A)
to fix this.