Computer Science Canada

Quadratic Trinomials

Author:  Token [ Tue Mar 08, 2005 1:30 pm ]
Post subject:  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

code:

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

Author:  jamonathin [ Tue Mar 08, 2005 2:24 pm ]
Post subject: 

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.

Author:  Token [ Tue Mar 08, 2005 2:38 pm ]
Post subject: 

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!

Author:  jamonathin [ Tue Mar 08, 2005 2:50 pm ]
Post subject: 

here i juss show you the formula

x = -b +- sqrt[b**2 - 4(a)(c)] all divided by 2(a)

Author:  Token [ Tue Mar 08, 2005 3:28 pm ]
Post subject: 

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

Author:  person [ Tue Mar 08, 2005 3:39 pm ]
Post subject: 

-b (+ or -) squaroot (b^2 - 4ac) all div 2a should work

ur not getting it (theres sometimes 2 solutions??)

Author:  Token [ Tue Mar 08, 2005 3:47 pm ]
Post subject: 

= -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

Author:  person [ Tue Mar 08, 2005 3:52 pm ]
Post subject: 

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 Very Happy (gr9)

Author:  Token [ Tue Mar 08, 2005 3:59 pm ]
Post subject: 

= -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

Author:  [Gandalf] [ Tue Mar 08, 2005 4:55 pm ]
Post subject: 

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:
Posted Image, might have been reduced in size. Click Image to view fullscreen.

Author:  Token [ Tue Mar 08, 2005 5:15 pm ]
Post subject: 

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 Very Happy
btw my error b4 was i pulled a brain fart on the sqrt of 64

Author:  Token [ Tue Mar 08, 2005 5:56 pm ]
Post subject: 

So this would be the code to figure it out through the equation
Posted Image, might have been reduced in size. Click Image to view fullscreen.


code:

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

Author:  person [ Tue Mar 08, 2005 5:57 pm ]
Post subject: 

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

Author:  cool dude [ Tue Mar 08, 2005 7:18 pm ]
Post subject: 

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.

Author:  endusto [ Wed Mar 09, 2005 6:03 pm ]
Post subject: 

if there are no real roots you get an error.

Author:  Token [ Wed Mar 09, 2005 6:18 pm ]
Post subject: 

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 Smile

Author:  person [ Wed Mar 09, 2005 6:21 pm ]
Post subject: 

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)

Author:  Token [ Wed Mar 09, 2005 6:30 pm ]
Post subject: 

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

Author:  apomb [ Fri Mar 11, 2005 3:40 pm ]
Post subject: 

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

Author:  w00t [ Mon Mar 28, 2005 9:12 pm ]
Post subject: 

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

Author:  jamonathin [ Tue Mar 29, 2005 7:53 am ]
Post subject: 

I am not worthy then you're a math guru w00t Razz

Author:  Mr. T [ Fri May 06, 2005 1:00 am ]
Post subject: 

Token wrote:
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 Smile

*cough* Just because the answer will give you imaginary numbers doesnt mean its irrelevant Wink

Author:  Token [ Fri May 06, 2005 6:06 am ]
Post subject: 

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

Author:  dann_west [ Fri May 06, 2005 2:22 pm ]
Post subject:  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 Evil Twisted Evil Twisted Evil Twisted Evil Twisted Evil Twisted Evil Twisted Evil

Author:  Token [ Fri May 06, 2005 2:36 pm ]
Post subject: 

actually i'm workin on a really good helecopter game... i'll post it once i finnish the highscore part


: