Using Process to solve equations of the form ax+b=c

edited February 2015 in How To...

Hi everyone I need to solve the following using programming and I a novice here. ax+b=c I know this much mathematically Here are some examples of those types of equations: 1. 2x + (-8) = 12 2. (1/2)x + 7 = -9 3. x + 11 = 2 a, b, and c can be any numbers whatsoever, and there will be one guaranteed solution for x (the one exception is that a cannot be equal to 0) A computer (or a person) can solve any equation in the form ax + b = c by reversing the two operations done to x. Here is how I would solve example 1. above: 2x +(-8) = 12 + 8 +8 (add 8 to both sides) 2x = 20 /2 /2 (divide both sides by 2) x = 10 (solution) I need code that can solve that same equation simply by performing operations: x = (12 – (-8)) / 2 = 10 to solve any equation written as ax + b = c, all the computer has has to do is: x = (c – b) / a As long as "a" does not equal 0, this will return a solution. Can anyone please help?

Tagged:

Comments

  • You already provided the method that a program could use: x = (c - b) / a

    Maybe the problem is how the equation input is represented? If got to a point where you had the three variables, a, b, and c, then you could do this:

    float x = (c - b) / a;

    Assuming you are using floats, when a is zero then you will get Infinity

  • x is 0. Iam trying to solve for x.

  • I got this far (plugging in values for a,b,c). But keep getting an error

    float x=0; float c=12; float b=8; float a=16;

    void setup(){ x=(c-b)/a; println("x=" c - (-b) )/a; }

  • Your print statement is wrong, and could be simpler!

    println( "x = " + x );
    
  • Thank you TfGuy44!! you are an awesome person.

Sign In or Register to comment.