Click here to Skip to main content
15,743,179 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
i have being wondering how to solve simultaneous equation in javascript using only one input field, to set the equation like this 2x + 3y + 8 = 0 and solve it without using three input field,but i can,t still figure it out i need help,i don't really know if this question is accepted here but i need an answer please

What I have tried:

i have google it out but no solution yet
Updated 6-Feb-21 20:43pm
[no name] 3-Apr-17 13:17pm    
You are looking for an expression parser.
ZurdoDev 3-Apr-17 13:58pm    
You'll have to break out the pieces. Not an easy thing to do.
alertfrancis 3-Apr-17 15:51pm    
please can you tell me how to break it out in pieces or refer me to a site were i can read about it,i don't care how hard it is i am willing to learn.

1 solution

First restrict yourself to solving something like:
(user input) Ax + By = C (use only 'x' and 'y' for variables to solve)
Remove all spaces so that you get:
Ax+By=C (this makes parsing easier since any MINUS in (Ax - By = C) becomes part of the coefficient)
Use the equivalent of (C function) strchr() to search for 'x' then 'y' and then '=' to get the values of A, B & C respectively (of course you will have to convert the ascii values of digits to plain numeric - your own atoi() or atof()).

You can then use determinants to solve. The following is just one link that provides step by step details - search google determinant equation 2X2:
"Determinants and Cramer's Rule for 2x2 Systems 1 |[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900