Results 1 to 11 of 11

Thread: Quadratic Equation Solver

  1. #1
    Join Date
    Mar 2008
    Location
    New Jersey
    Posts
    1,673
    Mentioned
    1 Post(s)
    Quoted
    9 Post(s)

    Default Quadratic Equation Solver

    Made this because I got easily side-tracked while doing homework, and I could use it to make sure I'm doing my homework right. I guess you guys can use it to check/do your homework also whatever you decide. The first pop-up box it just to make sure you understand how a quadratic equation should be set-up, just hit enter. Then you imput a, b, and c and the script does the rest.

    By the way, I'm in pre-calc, this stuff is just review.

    EDIT: Oh forgot to mention, there is no setup you need to do before running the script, just run it then like I said above, you imput a, b, and c. (ax^2 + bx + c = 0)

    If you use this a simple thank you would be appreciated

    Features:

    -Quadratic Formula
    -imaginary numbers
    -Cubic Formula
    -Pop-up box to declare which formula to use, and to imput the base numbers of the equation
    -Leaves numbers that aren't perfect squares in the radical, so you don't get a big decimal answer


    Future:

    -Shorten coding
    -Add Quartic formula
    -Maybe make the output look better
    -Maybe add custom form


    Changelog:

    Version 1.0: Initial release
    Version 1.1: Added support for imaginary numbers
    Version 1.2: Added the cubic equation solver, fixed some bugs (dealing with imaginary numbers) (V1.2 is ComplexEquationSolver.Scar)
    Last edited by Sir R. M8gic1an; 11-14-2009 at 03:28 PM.

  2. #2
    Join Date
    Mar 2008
    Location
    New Jersey
    Posts
    1,673
    Mentioned
    1 Post(s)
    Quoted
    9 Post(s)

    Default

    bump, I don't know if anyone will start caring, but if you had a negative number inside the radical it couldn't solve it since you can't do the square root of a negative number. It now supports square roots of negative numbers using i (imaginy number), I figured I'd add this in since I have problems dealing with i in my homework. Someone should use this , I see I got 4 views, I don't think any were from me, maybe one, just to make sure it looked right when opened. Uploading new version now.

  3. #3
    Join Date
    Sep 2007
    Location
    British Columbia, Canada
    Posts
    4,047
    Mentioned
    1 Post(s)
    Quoted
    2 Post(s)

    Default

    Can you make a solver for cubic, quartic, and quintic
    Oh Hai Dar

  4. #4
    Join Date
    Mar 2008
    Location
    New Jersey
    Posts
    1,673
    Mentioned
    1 Post(s)
    Quoted
    9 Post(s)

    Default

    I believe I learned cubic, I will have to jog my memory, but I never heard of quartic or quintic, but I will try to learn the formula and apply it, so I'll give it a shot.

    Not really important, but I actually did hear of quartic yesterday, I forgot how to factor by grouping and I asked a smart kid that's in my principles of comp science class (I have to take it since it's a pre-requisite for AP computer science, and I'm as Sr. so I take both at once) and I forgot it was called grouping, but showed him the part I remembered, and after a minute he realized what I was trying to do, and he said ohh grouping, that's for quartic, I was like WTF? Quartic? lol, but yea, pointless story, just mentioning the one time I heard of it. Well I'll refresh my memory on cubic, and then see if I can learn quartic an quintic real fast, or at least there formulas.

    You better love me for giving up time to do this

    EDIT: Quartic formula: http://www.1728.com/quartic2.htm

    Looks like I can do it, but it looks a little long, and it's midnight, I'll do it tomorrow

    still gotta look up cubic and quintic.

    EDIT2: cool I love f'ing with urls, I changed quartic to cubic, and what do you know, they have as much creativity as a 13 y/o web designer would, they have the same url for cubic formulas, only with cubic where quartic was

    cubic: http://www.1728.com/cubic2.htm

    quintic is probably the same too, if they have it, I'll check


    EDIT3:
    either they don't have quintic or the url wasn't what I expected I'll google it.


    EDIT4:
    wikipedia doesn't make quintic look too fun, I'll see tomorrow if I can find a better website that makes it look more promising. So far I think I should have cubic and quartic solved, but not so sure bout the quintic.

    Time for bed now though, in 14 hours I'll be getting home from school and I'll solve the first two then look up quintic again (14 hours, because not everyone is on the same time, should be bout 14 hours from my last edit time, 12:10 for USA east coast, I think that's -5GMT)
    Last edited by Baked0420; 09-24-2009 at 12:04 PM.

  5. #5
    Join Date
    Jul 2009
    Posts
    421
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I'll use for mine
    Quote Originally Posted by Cstrike View Post
    Why do I even try these things? I just shit my pants over this god damn tutorial. Fuck, that's uncleanable. I can't even wash that out because there's so much of my shit it will just stain everything else. If I put it in the washing machine, I'm sure to stain the sides.

  6. #6
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    There's no solving formula for 5th degree functions...
    Here's your next challenge: Find imaginary roots too
    x^2 = -1

    EDIT: Wow, it does already? o_O Nice work dude
    Last edited by marpis; 09-25-2009 at 01:47 AM.

  7. #7
    Join Date
    Mar 2008
    Location
    New Jersey
    Posts
    1,673
    Mentioned
    1 Post(s)
    Quoted
    9 Post(s)

    Default

    yep, that was my latest version

    my last two problems I tested my script with said it was having a problem, I instantly knew it had to be a problem with imaginary numbers so I added it and it works now, and that's what about the quintic function from wikipedia, which is why I said I'm not so sure bout a solver for that one .

    Well I gotta go to the eye doctor today for a follow-up on getting contacts a week ago, then I'll put in the cubic and quartic functions and make a spot to choose which solver to use.

    And thank you very much for telling me nice work

  8. #8
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Mine:

    SCAR Code:
    Var A, B, C : Extended;
        Ans : Array [0..1] Of Extended;
        Astr, Bstr, Cstr : String;

    begin
      Astr := ReadLn('What is the value of A in an integer form');
      Bstr := ReadLn('What is the value of B in an integer form');
      Cstr := ReadLn('What is the value of C in an integer form');
        A := StrToFloatDef(Astr, 0);
        B := StrToFloatDef(Bstr, 0);
        C := StrToFloatDef(Cstr, 0);
      wait(8);
        Ans[0] := (-B + Sqrt(Sqr(B)  - (4* A * C))) div (2 * A);
        Ans[1] := (-B - Sqrt(Sqr(B)  - (4* A * C))) div (2 * A);
      WriteLn('The answer is X = '+FloatToStr(Ans[1])+', Or X = '+FloatToStr(Ans[0]));
    end.

    E: Lol, it's pretty basic compared to yours

  9. #9
    Join Date
    Apr 2007
    Posts
    3,152
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    actually give the roots as roots with the +- fractions instead of the usually useless decimals. That would make me happier =)
    SCAR Tutorials: The Form Tutorial | Types, Arrays, and Classes
    Programming Projects: NotePad | Tetris | Chess


  10. #10
    Join Date
    Mar 2008
    Location
    New Jersey
    Posts
    1,673
    Mentioned
    1 Post(s)
    Quoted
    9 Post(s)

    Default

    c'mon, always gotta steal my glory

    pretty nice, very short and looks efficient, I could shorten mine a lot, but I posted mine right after testing, so I never bothered to turn things into one line like you.

    But mine still has one thing on yours, imaginary numbers, so even though mines a bit longer when it could easily be shortened, mine still has an edge on your's because I don't think your's can handle imaginaries.


    And I am about half way done with the cubic (switched quartic to cubic in this first edit, realized I said the wrong one ) equation, but I'm leaving now to go to the eye doctor, I couldn't resist starting though


    EDIT: Dan cardin, I was thinking bout that today in school, how when it's not a perfect square in the radical, we usually leave it as -b plus/minus the square root of the discriminant over 2a. Sorry for writing it out like that, I started to write it without words but it didn't look good, by the way, for anyone who doesn't know (since I didn't till two days ago in pre-calc), the discriminant is b^2-4ac, the part in the radical.

    I will probably add that in the next version, or the version after the cubic and quartic formulas.


    EDIT:

    Status update: Still working on the cubic function, so far I got it done for all the roots being equal, now I just need to make it solve all roots being real and for only one real root. I thought I'd get this done today, but I took a break for a while in the middle, so I only finished 1 outta 3 pieces, I should have the cubic function done by tomorrow now, and hopefully have it added into the quadratic formula script with an option for which formula to use.

    Then I need to add the quartic formula. Then I will work on what me and dan cardin said if I'm still into this project and if I feel it's worth it, getting replies/views/thank yous or people just in general using it.
    Last edited by Baked0420; 09-26-2009 at 02:22 AM.

  11. #11
    Join Date
    Mar 2008
    Location
    New Jersey
    Posts
    1,673
    Mentioned
    1 Post(s)
    Quoted
    9 Post(s)

    Default

    New post for a new update, I now have the cubic equation solved, and there is an option to choose which solver. Also, there is a bugfix, when you got an answer with i, say 12+5i over 6, it would say 17i over 6. I now have it fixed for when it uses i's (quadratic formula). The quadratic formula now also shouldn't give you decimals, if the discriminant isn't a perfect square, it'll leave it alone and write it out how me and dan cardin said. Uhm, I don't know what else, I guess if you use this and see that an answer is wrong, post the equation and I'll work on fixing it.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •