
-----------------------------------
Token
Tue Mar 08, 2005 1:30 pm

Quadratic Trinomials
-----------------------------------
Hey everyone, I just recently got fed up with the ammount of homework my math teacher has been giving my class, its not that its hard but that there is so much of it, she'd give us around 30 questions just solving quadratic trinomials (aÂ²+b+c) to do at home, on top of whatever other little tidbits she had taught us today, so0o i figured i'm not gonna do all that work and i  made a program to solve quadratic trinomials for you, it still might be a little buggy, if you find one pm me or post it here. Enjoy!

heres an question to try it out on XÂ²+2X-15


var digit1, digit2, counter, sum, prod, i, done, a, b, c, common1, common2 : int
var x : string

setscreen ("text:max;max")

loop


    put "Enter the value for.."
    put "\tA: " ..
    get a
    put "\tB: " ..
    get b
    put "\tC: " ..
    get c
    put "What letter would you like to use as a variable? " ..
    get x
    if a = 1 then
        put "\n\t", x, chr (178), "+", b, x, "+", c
    else
        put "\n\t", a, x, chr (178), "+", b, x, "+", c
    end if

    sum := b
    prod := a * c

    done := 0
    counter := -100
    loop
        i := -101
        loop

            i := i + 1


            if counter * i = prod and counter + i = sum then

                put "\nProd: ", prod, " = ", counter, " x ", i
                put "Sum: ", sum, " = ", counter, " + ", i
                done := 1
            end if


            exit when i = 100 or done = 1

        end loop
        exit when done = 1
        counter := counter + 1

    end loop
    if a = 1 then
        put "\n(", x, chr (178), "+", i, x, ") (", counter, x, "+", c, ")"
    else
        put "\n(", a, x, chr (178), "+", i, x, ") (", counter, x, "+", c, ")"
    end if

    put "What is common in the first part of the equation?(besides ", x, ")if nothing enter 1 " ..
    get common1
    put "The seccond? " ..
    get common2

    if a = 1 then
        put "\n", x, chr (178), "+", b, x, "+", c
    else
        put "\n", a, x, chr (178), "+", b, x, "+", c
    end if

    if a = 1 then
        put "(", x, chr (178), "+", i, x, ") (", counter, x, "+", c, ")"
    else
        put "(", a, x, chr (178), "+", i, x, ") (", counter, x, "+", c, ")"
    end if

    if common1 = 1 and a = 1 and counter / common2 = 1 then
        put x, "(", x, "+", i / common1, ")+", common2, "(", x, "+", c / common2, ")"
        put "(", x, "+", i / common1, ")(", x, "+", common2, ")"
    elsif common1 = a then
        put common1, x, "(", x, "+", i / common1, ")+", common2, "(", counter / common2, x, "+", c / common2, ")"
        put "(", common1, x, "+", i / common1, ")(", common1, x, "+", common2, ")"
    elsif common1 = 1 and a = 1 then
        put x, "(", x, "+", i / common1, ")+", common2, "(", counter / common2, x, "+", c / common2, ")"
        put "(", x, "+", i / common1, ")(", common1, x, "+", common2, ")"
    elsif common2 = 1 and a = 1 then
        put x, "(", x, "+", i / common1, ")+", common2, "(", counter / common2, x, "+", c / common2, ")"
        put "(", x, "+", i / common1, ")(", common1, x, "+", common2, ")"
    elsif common1 = 1 then
        put x, "(", a / common1, x, "+", i / common1, ")+", common2, "(", counter / common2, x, "+", c / common2, ")"
        put "(", a / common1, x, "+", i / common1, ")(", common1, x, "+", common2, ")"
    else
        put common1, x, "(", a / common1, x, "+", i / common1, ")+", common2, "(", counter / common2, x, "+", c / common2, ")"
        put "(", a / common1, x, "+", i / common1, ")(", common1, x, "+", common2, ")\n\n\n"
    end if
    delay (1000)
    loop
        exit when hasch
    end loop
end loop


Edit: I cleaned up the code a bit, changed the screen to text, and made the output more user friendly

-----------------------------------
jamonathin
Tue Mar 08, 2005 2:24 pm


-----------------------------------
pretty good! I juss think your next step is to figure it out using the quadratic formula, incase it doesn't work out perfectly, which shouldn't be too hard to do, other than that, gj.

-----------------------------------
Token
Tue Mar 08, 2005 2:38 pm


-----------------------------------
thanks man, yah i would but thats the only way she has showed us how to do it, she said she was gonna show us the other way when we get back from the march break, but my school is desemestered and we run on a day 1 day 2 schedual so we learn things over a more spread out period of time, thats why she hasnt showed us yet

thanks for the feedback!

-----------------------------------
jamonathin
Tue Mar 08, 2005 2:50 pm


-----------------------------------
here i juss show you the formula

x = -b +- sqrt[b**2 - 4(a)(c)] all divided by 2(a)

-----------------------------------
Token
Tue Mar 08, 2005 3:28 pm


-----------------------------------
okay so let me try one to se if i get it

x = -b +- sqrt[b**2 - 4(a)(c)] all divided by 2(a)

i'll use the example i gave above... XÂ²+2X-15 
a=  1
b=  2
c= (-15)

= -2+ - sqrt (2Â² x 2- 4 (1)(-15) )     /2
= -2+ - sqrt (8-(-60))     /2
= -2+ - sqrt (68 )     /2
= -2+ (-8.25)     /2
= -10.25     /2
= -5.125

some how i dont think that turned out right... lmao... help

okay the questions i have are
- by **2  do you mean Â² ? because what i did was squared it and then multiplied it by 2... maybe thats my problem, if not let me know, thanks
and if i'm starting to bug one of the mods just let us know and we can do this through pm

-----------------------------------
person
Tue Mar 08, 2005 3:39 pm


-----------------------------------
-b (+ or -) squaroot (b^2 - 4ac) all div 2a should work

ur not getting it (theres sometimes 2 solutions??)

-----------------------------------
Token
Tue Mar 08, 2005 3:47 pm


-----------------------------------
= -2+ - sqrt (2Â² x 2- 4 (1)(-15) ) /2 
= -2+ - sqrt (8-(-60)) /2 
= -2+ - sqrt (68 ) /2 
= -2+ 8.25 /2         or      = -2 -8.25 /2
=  6.25 / 2                      = -10.25 /2 
= 3.15                            = -5.125 


i think i get it now, but i think i got the wrong answer... somehow lol but yes i realise now that +- meant  +/- because a parabola has to roots, or x-intercepts, but i think i screwed up my answer somewehere here '(2Â² x 2' umm do u see my problem? thanks

-----------------------------------
person
Tue Mar 08, 2005 3:52 pm


-----------------------------------
y do u have 2^2 * 2?? its supposed to be 2^2 not 2^3

im so happy i can help someone whos probably in a higher grade than me  :D  (gr9)

-----------------------------------
Token
Tue Mar 08, 2005 3:59 pm


-----------------------------------
= -2 +/- sqrt (2Â² - 4 (1)(-15) ) /2 
= -2 +/- sqrt (4 - (-60) 
= -2 +/- sqrt (64)
= -2 + 6           or     = -2 - 6
= 4                  or     = -8


... okay but what are 4 and -8? the roots? if they are then i did some calculations wrong because when i solved this with    x=aÂ²+b+c i got the roots to be -5 and 3

and yes you are helping somone older than you  :wink:

-----------------------------------
[Gandalf]
Tue Mar 08, 2005 4:55 pm


-----------------------------------
WTF? You're doing this in grade 9?

All I did in grade 9 is a**2 + b + c using decomposition, and then special cases and stuff like that.

If you still don't understand the symbols or what to do:
http://www.sosmath.com/algebra/quadraticeq/quadraformula/img9.gif

-----------------------------------
Token
Tue Mar 08, 2005 5:15 pm


-----------------------------------
AHH Gandalf you did it lol i get it now, so it would go like this

X= (-b +/- sqrt (bÂ² - 4ac) ) /2a
X= (-2 +/- sqrt (2Â² - 4(1)(-15) ) ) /2
X= (-2 +/- sqrt (4 - 4(-15) ) ) /2
X= (-2 +/- sqrt (4 - 4(-15) ) ) /2
X= (-2 +/- sqrt (4 + 60 ) ) /2
X= (-2 +/- sqrt (64) ) /2
X= (-2 +/- 8 ) /2

X= (-2 + 8 ) /2
X= 6/2
X= 3

X= -10 /2
X= -5

YAY! I GOT IT!! lol i'm gonna suprise the hell out of my math teacher tommorow! thanks guys  :D
btw my error b4 was i pulled a brain fart on the sqrt of 64

-----------------------------------
Token
Tue Mar 08, 2005 5:56 pm


-----------------------------------
So this would be the code to figure it out through the equation 
http://www.sosmath.com/algebra/quadraticeq/quadraformula/img9.gif



var a, b, c : int


loop
put "Enter the value for.."
put "\tA: " ..
get a
put "\tB: " ..
get b
put "\tC: " ..
get c


put "= (-b +/- sqrt ((b) - 4 * a * c)) / 2 * a"
put "= (-", b, "+/- sqrt ((", b, chr (178), " ) - 4 * ", a, "*", c, ")) / 2 *", a
put "= (", -b, "+/- sqrt ((", b * b, " ) - ", 4 * a * c, ")) / ", 2 * a
put "= (", -b, " +/- ", sqrt ((b * b) - 4 * a * c), ") / ", 2 * a

put "\n= (", -b, " +", sqrt ((b * b) - 4 * a * c), ") / ", 2 * a
put "= (", -b + sqrt ((b * b) - 4 * a * c), ") / ", 2 * a
put "= ", (-b + sqrt ((b * b) - 4 * a * c)) / 2 * a

put "\nor"

put "\n= (", -b, " -", sqrt ((b * b) - 4 * a * c), ") / ", 2 * a
put "= (", -b - sqrt ((b * b) - 4 * a * c), ") / ", 2 * a
put "= ", (-b - sqrt ((b * b) - 4 * a * c)) / 2 * a

put "\n\nPress any key to do another"

loop
exit when hasch
end loop

end loop


-----------------------------------
person
Tue Mar 08, 2005 5:57 pm


-----------------------------------
i never said i was learnig this in grade 9...frankly my class hasnt even touched anything to the power of 2 wich is sad becasue im in a program that is supposed to be for ppl who r good at Math, Computers, and Science

-----------------------------------
cool dude
Tue Mar 08, 2005 7:18 pm


-----------------------------------
nice prog but it's useless to me for now. we didn't learn this stuff in math yet, but i know we will be learning this in this semester because we r doing similar stuff right now.

school programs r really bad, they should be teaching this stuff in earlier grades instead of teaching us +-x/ for several years.

-----------------------------------
endusto
Wed Mar 09, 2005 6:03 pm


-----------------------------------
if there are no real roots you get an error.

-----------------------------------
Token
Wed Mar 09, 2005 6:18 pm


-----------------------------------
Well if there are no real roots then it cant be solved, then you wouldent want to solve it, because you wouldent get an answer, therefore if there were no real roots then you wouldent ened the program to begin with  :)

-----------------------------------
person
Wed Mar 09, 2005 6:21 pm


-----------------------------------
of course u would want to solve a problem without real roots...i mean how would u know if it had real roots or not (besides using the method wich im too lazy to type)

-----------------------------------
Token
Wed Mar 09, 2005 6:30 pm


-----------------------------------
well heres the thing, i should just put a line that says if the program crashes there are no real roots lol that solves that problem

-----------------------------------
apomb
Fri Mar 11, 2005 3:40 pm


-----------------------------------
or you could state that the roots are imaginary and figure out that  the

sqrt (-1) = i

so sqrt (-4) = 2i

therefore if a negative number, change to positive and add "i" beside it

-----------------------------------
w00t
Mon Mar 28, 2005 9:12 pm


-----------------------------------
man, i even touched on Quadratic Equations in Gr.8 < only becuase i chose too, and my teacher didn't mind helping me> and in grade 10 we started wtih Loci and Conics

-----------------------------------
jamonathin
Tue Mar 29, 2005 7:53 am


-----------------------------------
:notworthy:  then you're a math guru w00t  :P

-----------------------------------
Mr. T
Fri May 06, 2005 1:00 am


-----------------------------------
Well if there are no real roots then it cant be solved, then you wouldent want to solve it, because you wouldent get an answer, therefore if there were no real roots then you wouldent ened the program to begin with  :)
*cough* Just because the answer will give you imaginary numbers doesnt mean its irrelevant  :wink:

-----------------------------------
Token
Fri May 06, 2005 6:06 am


-----------------------------------
this was made like 2 months ago, do u just go around the forum looking for new people to try and show up or somthin because thats about the third time u've done it to my old posts

-----------------------------------
dann_west
Fri May 06, 2005 2:22 pm

Re: Quadratic Trinomials
-----------------------------------
interesting?... I guess it could be useful. If your that good with the code show me a good game.
I never get enough of them!!!!
 :twisted:  :twisted:  :twisted:  :twisted:  :twisted:  :twisted:  :twisted:

-----------------------------------
Token
Fri May 06, 2005 2:36 pm


-----------------------------------
actually i'm workin on a really good helecopter game... i'll post it once i finnish the highscore part
