Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Quadratic Trinomials
Index -> Programming, Turing -> Turing Submissions
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Token




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
jamonathin




PostPosted: Tue Mar 08, 2005 2:24 pm   Post subject: (No 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.
Token




PostPosted: Tue Mar 08, 2005 2:38 pm   Post subject: (No 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!
jamonathin




PostPosted: Tue Mar 08, 2005 2:50 pm   Post subject: (No subject)

here i juss show you the formula

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




PostPosted: Tue Mar 08, 2005 3:28 pm   Post subject: (No 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
person




PostPosted: Tue Mar 08, 2005 3:39 pm   Post subject: (No subject)

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

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




PostPosted: Tue Mar 08, 2005 3:47 pm   Post subject: (No 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
person




PostPosted: Tue Mar 08, 2005 3:52 pm   Post subject: (No 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)
Sponsor
Sponsor
Sponsor
sponsor
Token




PostPosted: Tue Mar 08, 2005 3:59 pm   Post subject: (No 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
[Gandalf]




PostPosted: Tue Mar 08, 2005 4:55 pm   Post subject: (No 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.
Token




PostPosted: Tue Mar 08, 2005 5:15 pm   Post subject: (No 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
Token




PostPosted: Tue Mar 08, 2005 5:56 pm   Post subject: (No 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
person




PostPosted: Tue Mar 08, 2005 5:57 pm   Post subject: (No 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
cool dude




PostPosted: Tue Mar 08, 2005 7:18 pm   Post subject: (No 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.
endusto




PostPosted: Wed Mar 09, 2005 6:03 pm   Post subject: (No subject)

if there are no real roots you get an error.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 25 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: