Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Algebra  (Read 9323 times)

0 Members and 1 Guest are viewing this topic.

Dilbert

    Topic Starter
  • Moderator


  • Egghead

  • Welcome to ComputerHope!
  • Thanked: 44
    Algebra
    « on: October 18, 2006, 04:25:12 PM »
    This isn't a homework assignment; rather, it's for helping with it.

    I want to write a C++ assignment that can do Algebra. Not very advanced algebra, not at first, but I'd like to write a program that can parse an equation, like "3X + 5 = 6" and give me the correct "X=0.33333..." However, I have no idea where to begin. Google hasn't turned up with anything useful. How should I start this task?

    BTW, I'm in Algebra II and writing a program that can do this simple Pre-Algebra stuff won't be of much help to me. So I can't use it to cheat or anything. :)
    "The geek shall inherit the Earth."

    Raptor

    • Guest
    Re: Algebra
    « Reply #1 on: October 18, 2006, 04:37:01 PM »
    I can send you an E-book on C++ if you don't know C.. Within a few chapters you can build that program.

    Unfortunately, my C++ is too rusty to be of use here.  :-[
    « Last Edit: October 18, 2006, 04:37:30 PM by Raptor »

    Dilbert

      Topic Starter
    • Moderator


    • Egghead

    • Welcome to ComputerHope!
    • Thanked: 44
      Re: Algebra
      « Reply #2 on: October 18, 2006, 04:38:44 PM »
      I would appreciate that. :) It does fit in an Email, right?
      « Last Edit: October 18, 2006, 04:43:21 PM by Timothy_Bennett »
      "The geek shall inherit the Earth."

      ghostdog74



        Specialist

        Thanked: 27
        Re: Algebra
        « Reply #3 on: October 18, 2006, 06:01:20 PM »
        If you don't mind other language like Python, modules have aalready been built for it. Just have to know how to use it.

        http://www.scipy.org/
        http://www.aims.ac.za/wiki/index.php/Python:scipy_module:linalg

        Neil



          Expert
        • Fear me Track. Noone can escape my wrath.
        • Thanked: 3
          Re: Algebra
          « Reply #4 on: October 19, 2006, 03:00:53 PM »
          I can help you. Do you want the full answer, or just hints to move you along? ;)

          Try researching itterative methods. I don't know how to spell it, which adds even greater challange ;D

          (Basically don't force a computer to solve a problem the same way a human does! :P)


          Smilie overload sorry..

          Dilbert

            Topic Starter
          • Moderator


          • Egghead

          • Welcome to ComputerHope!
          • Thanked: 44
            Re: Algebra
            « Reply #5 on: October 19, 2006, 07:19:18 PM »
            I could use a few hints, but I would prefer to do it myself. :)

            ghostdog74, I appreciate the help. However, the reason I'm doing this is so I can study/learn C++, so doing it in another language defeats the purpose. :)

            "Itterative"? You mean "iterative"? ;)
            "The geek shall inherit the Earth."

            Neil



              Expert
            • Fear me Track. Noone can escape my wrath.
            • Thanked: 3
              Re: Algebra
              « Reply #6 on: October 20, 2006, 08:19:09 AM »
              Humans solve problems using patterns blah blah. Computers are better suited to solving problems using itterative or something methods. There are dozens of methods available. At its simplist you try every value of x from minus infinity to positive infinity, until you find a value that "works" (makes both sides of the equation equal). Of course it's not possible to simply use "every" value.

              Instead you can try going through values of x from -9999 to 9999. It's up to you which degree of decimal point accuracy to use. Most equations you solve have fairly small values of x, but allow the option for th user to pick a range (or make your program automatically increase the range if no solutions found). Although this might seem to be the long way round, remember computers can calculate simple things like this VERY fast.

              You'll need to decide on a cut off point level of accuracy, for example within 6 decimal places. I've not attempted a program like this before (but I'll try one) so I'm not sure of the optimal values. Basically you will need to give your program the ability to decide if a value is close enough in terms of decimal points to be the correct answer, or if the range should be broadened. (If after the range has been increase and no better match has been found, then the initial value we weren't sure about will be assumed to be the answer).

              This might seem a rather sloppy method but should solve simple alegbraic equations satisfactorally, and suprisingly quickly. Consider these points:
              * Polynomials can have more than one solution.
              * By developing the logic of your program futher you can define a range better. Eg your program can do a few logical checks to determine whether x must be negative or positive, and thus half the number to be checked.
              * Use of pointers and references passed as function parameters, as opposed to global variables, can speed up the program.

              There are various other improvements you can make to this kind of program, but that should keep you busy ;)

              Alternatively you could try to create a program that emulates human thinking and attempts to solve the algebra symbolically. That is following a list of guidelines to move the terms around the equation. Even though it is the simplist to understand, it will be harder to program and I would attempt the above method first.

              Well good luck.

              Rob Pomeroy



                Prodigy

              • Systems Architect
              • Thanked: 124
                • Me
              • Experience: Expert
              • OS: Other
              Re: Algebra
              « Reply #7 on: October 21, 2006, 03:00:19 PM »
              Solve alegbra by brute force?  How would you detect an intractable problem?

              I would suggest breaking it down.  First start with X + 4 = 20; create an algorithm for solving the problem; then create pseudo code; then code.

              Next move onto something a little more adventurous, and then on.  You might like to read up on syntax parsers and computational grammars: this is definitely a programming discipline that would be easier with some good foundational understanding.
              « Last Edit: October 21, 2006, 03:01:12 PM by robpomeroy »
              Only able to visit the forums sporadically, sorry.

              Geek & Dummy - honest news, reviews and howtos

              Skreap

              • Guest
              Re: Algebra
              « Reply #8 on: October 23, 2006, 04:34:14 PM »
              Now, I'm pretty good at math, so forgive me if I'm downplaying the difficulty of your situation, but I think writting a program (no matter how simple) would take longer to do than if you just did the work by hand...

              So far, the most complex sample problem I've seen only had one variable, and it wasn't to a power.  Is that how all of these problems are going to be, or do they get more complicated?
              Like I said, I'm not trying to be mean or brag, but something like 3X+5=6 can be done in less than 5 seconds with a regular pocket calculator.  Getting the variable by itself requires the simple calculation of 6 minus 5.  With only 3X = 1 left, the problem should be a no-brainer.

              As long as the problems don't have X going to any powers, I think writting a program would be a waste of time.  And besides, I've been out of highschool for 5 years, and even then my cheapest-availalbe model TI-82 graphing calculator had a built in "function solver" where you could just enter in the equation as it written ("3X+5=6") and it would solve for X for you.


              If the problems your trying to solve DO get more complicated (4X² -¼X = ½X² + 15), I wouldn't mind helping you out if the books don't give you the answers you need.

              Dilbert

                Topic Starter
              • Moderator


              • Egghead

              • Welcome to ComputerHope!
              • Thanked: 44
                Re: Algebra
                « Reply #9 on: October 23, 2006, 06:29:57 PM »
                Like I said, it's not about the uses of this program, it's just for C++ practice. I don't pretend that I can get a computer to do this:

                Quote
                Find the maximum and minimum value possible when Objective Function is

                X = 2X + 3Y

                constrained by the following:

                X >= 0
                Y >= 0
                X + Y <= 9

                I'll get around to doing what Rob said, but not until I get a little more time. School projects just never end... I just got done with three and got slapped with another one.
                "The geek shall inherit the Earth."

                ghostdog74



                  Specialist

                  Thanked: 27
                  Re: Algebra
                  « Reply #10 on: October 23, 2006, 06:55:22 PM »
                  Another way to learn is to review/understand other people's code. From googling, there are packages in C++ that does algebra. you could download the source and see if you can learn the way they do it... :)

                  Neil



                    Expert
                  • Fear me Track. Noone can escape my wrath.
                  • Thanked: 3
                    Re: Algebra
                    « Reply #11 on: October 24, 2006, 12:25:05 PM »
                    That kind of problem can be easily solved by a computer using an iterative method. After you tried my suggestion I was going to provide you with information on more efficient and advanced techniques, but up to you.
                    « Last Edit: October 24, 2006, 12:26:08 PM by Neil »

                    aca20031

                    • Guest
                    Re: Algebra
                    « Reply #12 on: October 24, 2006, 06:19:00 PM »
                    I'd personally try it the 'human' way in computer form. First, strip all spaces (whitespace) from the string equation. Then, go through character by character and collct the basic arithmatic (plus, minus, multiply, divide) and work them out on both sides. Then, go through and split the equation at the equality mark into two seperate strings. Further, find your additions, and subtract them. Find your subtractions, add. Find your divisions, multiply, and your multiplications, divide. Once that's done, use intuitive methods (log numbers up to a character other than +-/* (the coeficient of the variable)) and divide.

                    In basic terms, strip white space then follow through with each character. Iterating through all possible solutions is a terrible way, because, as in his example, you would never get it (since the decimal is repeating the answer can never come out perfectly)

                    Neil



                      Expert
                    • Fear me Track. Noone can escape my wrath.
                    • Thanked: 3
                      Re: Algebra
                      « Reply #13 on: October 25, 2006, 06:55:49 AM »
                      The computer can never represent repeating decimals perfectly anyway.

                      Neil



                        Expert
                      • Fear me Track. Noone can escape my wrath.
                      • Thanked: 3
                        Re: Algebra
                        « Reply #14 on: October 25, 2006, 07:07:16 AM »
                        And besides, many expressions cannot be solved using normal algebraic methods anyway, only iterative methods ;)

                        Neil



                          Expert
                        • Fear me Track. Noone can escape my wrath.
                        • Thanked: 3
                          Re: Algebra
                          « Reply #15 on: October 25, 2006, 09:11:42 AM »
                          Dilbert, I made a C++ program to work out the answer for the question you posted in quotes. I assume you have to find the right X and Y values that make the "X" on the left hand side (that I assume is a different X, otherwise it makes little sense) a maximum or minimum value. The maximum value is 27 when Y = 9 and X = 0 and the minimum value is 0 when both equal zero. Although it's fairly easy to solve just by looking at it. Try posting a more difficult equation to solve, so I can prove once and for all that itteratertive something methods rule the world, MuWaHaHaHa

                          Dilbert

                            Topic Starter
                          • Moderator


                          • Egghead

                          • Welcome to ComputerHope!
                          • Thanked: 44
                            Re: Algebra
                            « Reply #16 on: October 28, 2006, 06:51:23 PM »
                            Very well, Neil. The following is the type of problem found a homework assignment that we covered a few days ago:

                            Solve the linear system by finding X, Y, and Z

                            x - 2y + 3z = 7
                            2x + y + z = 4
                            -3x + 2y - z = -10

                            Here's the page on how to solve it: http://tutorial.math.lamar.edu/AllBrowsers/1314/SystemsThreeVrble.asp
                            "The geek shall inherit the Earth."

                            Neil



                              Expert
                            • Fear me Track. Noone can escape my wrath.
                            • Thanked: 3
                              Re: Algebra
                              « Reply #17 on: October 28, 2006, 08:18:44 PM »
                              OK, but not now. It's 3AM ::)

                              Neil



                                Expert
                              • Fear me Track. Noone can escape my wrath.
                              • Thanked: 3
                                Re: Algebra
                                « Reply #18 on: November 08, 2006, 06:58:51 AM »
                                Don't worry I haven't forgotten... just lots of work...

                                unlovedwarrior



                                  Guru

                                • someday this name will be known
                                • Thanked: 13
                                  Re: Algebra
                                  « Reply #19 on: November 08, 2006, 09:44:08 AM »
                                  i just read this thread and ill work the problem out by hand and we can compare. plus i need to refresh my math

                                  steelegbr

                                  • Guest
                                  Re: Algebra
                                  « Reply #20 on: November 08, 2006, 12:58:24 PM »
                                  My results were:

                                  x = 9/4
                                  y = -5/4
                                  z = 3/4

                                  How come they look so simple yet give such silly answers!

                                  unlovedwarrior



                                    Guru

                                  • someday this name will be known
                                  • Thanked: 13
                                    Re: Algebra
                                    « Reply #21 on: November 08, 2006, 01:04:04 PM »
                                    did you graph it??

                                    steelegbr

                                    • Guest
                                    Re: Algebra
                                    « Reply #22 on: November 08, 2006, 01:18:02 PM »
                                    Quote
                                    did you graph it??

                                    No. The only 3D maths work I've done is vectors.

                                    It's supposed to be taken down from a 3x3 system to a 2x2 and then again down to a 1x1.

                                    If you do it properly, most of the time it will come out as fractions.

                                    There are also times when there is no solution (E.g. 2 of the 3 equations are the same).