2 equations 2 unknown Calculator

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pepsy11
    New Member
    • Sep 2009
    • 5

    2 equations 2 unknown Calculator

    I am trying to make a windows app where i can write to equations, in 2 textboxes, with 2 unknown, x and y, and then press a button and get the x and y written in a label or something.
    I have tried to make it myself and i have used about 10 hours the last 2 days so now i have to just ask for help.

    The app hould calculate x and y by this formel(on danish it is called "determinan t-metoden" and i would translate it to be "determinan t-method", but i haven't found anything about how to say it on englsih):

    D= a1*b2-a2*b1 (if D == 0 then it should not continue with the following because then there is no answer or there is infinite anwsers)

    Dx = c1*b2-c2*b1
    Dy = a1*c2-a2*c1

    x = Dx/D
    y = Dy/D

    Just ask if you have any questions. =)
  • cloud255
    Recognized Expert Contributor
    • Jun 2008
    • 427

    #2
    So what problem are you experiencing exactly?

    Comment

    • pepsy11
      New Member
      • Sep 2009
      • 5

      #3
      I don't know how i can define a, b and c in a user written text.. I tried to use Split but then the equation have to be written in a certain way each time and i can't use that to anythins.. =s
      But i know that "a" have to be the number before "x", and "b" have to be the number before "y" and "c" is the number before or after "=".

      Comment

      • cloud255
        Recognized Expert Contributor
        • Jun 2008
        • 427

        #4
        You need to create user inputs like text boxes or numeric up down controls, you then save this value to a variable and perform the equation using that variable:

        Code:
        int a = (int) Textbox1.Text;
        int b = (int) txtMyBValue.Text;
        //etc
        
        if(D == 0)
           return;
        
        int Dx = c1*b2-c2*b1;
        //etc
        
        float x = Dx/D;

        Or have I misunderstood the problem you are facing?

        Comment

        • pepsy11
          New Member
          • Sep 2009
          • 5

          #5
          I think you have misunderstood.
          I need a textbox to each variable the way you do it(if i understood it right) and that is possible cause i have made one of them but isn't it possible to make something like this with only two textbox?

          Comment

          • GaryTexmo
            Recognized Expert Top Contributor
            • Jul 2009
            • 1501

            #6
            Are you basically looking to create an equation solver that will take any two arbitrary equations and solve them?

            Comment

            • pepsy11
              New Member
              • Sep 2009
              • 5

              #7
              Yeah any 2 equations with 2 unkown

              Comment

              • GaryTexmo
                Recognized Expert Top Contributor
                • Jul 2009
                • 1501

                #8
                That's definitely not going to be an easy task for you.

                I'd start by building an equation parser/solver with numbers, not variables. I made one once, about 3 years ago but it was in a programming language called Haskell and I can't remember many details anyway. Basically, you'll want to break things up into a set of operations based on what you parse out. Don't forget to do bracket matching either!

                Anyway, once you have a solver working with numbers, you can start implementing variables to get your equations in. At that point you'll need to need to start thinking about how to solve any given set of equations based what you have. So like, eliminating common variables between the equations, getting common denominators, etc...

                As I said, not an easy task by any stretch! If I can find the code for my Haskell numeric equation solver, I'll post it later. I don't think it was very long, but that's the beauty of a functional programming language. Hopefully it gives you something to go on.

                I might as well mention that if you do a bit of googling, you might find something someone else has already written, so that might give you a bit of a leg up on the task.

                Good luck!

                Comment

                • GaryTexmo
                  Recognized Expert Top Contributor
                  • Jul 2009
                  • 1501

                  #9
                  Here, this should help...

                  Comment

                  • pepsy11
                    New Member
                    • Sep 2009
                    • 5

                    #10
                    Okay.. I have looked at it but its too complicated for me now, i just thought there was a more simple way to do it. But thank you very much for your help and time. I will still fight to get it done but i am quite sure it will be hard. =)

                    Comment

                    • cloud255
                      Recognized Expert Contributor
                      • Jun 2008
                      • 427

                      #11
                      What you want to build is fairly complex and bordering on a functional programming language... You need to consider things like trigonometry, abstract math rules vs standard algebra, etc. this is really a huge area of study. I find it rather interesting (although the math is often above me).

                      A far smarter man than I has come up with a language which might interest you: Jos's new functional language

                      Comment

                      Working...