I can't think of how, and it's really annoying...
example: 2x=4
obviously x == 4
i can't think of exactly how to solve for x though....it's bugging me..i had an idea on it..but then forgot =x
p.s. no, this is not for math homework lol, i dont have math homework XD i'm just curious on how i would do it.
Solving Variable Equations
Started by
Guest_DiscoBob_*
, Sep 23 2006 01:48 PM
9 replies to this topic
#1
Guest_DiscoBob_*
Posted 23 September 2006 - 01:48 PM
Guest_DiscoBob_*
|
|
|
#2
Posted 23 September 2006 - 10:22 PM
hm... maybe store the equation as an array, use regular expressions to parse the degrees and coefficients, store each as a variable and use mathamatical operators to do the work
or if its a simple equation like that u could use a loop, but that wouldnt work that well with irrational equations or more complex ones
im interested in hearing some other ideas
or if its a simple equation like that u could use a loop, but that wouldnt work that well with irrational equations or more complex ones
im interested in hearing some other ideas
#3
Posted 24 September 2006 - 12:19 AM
Umm sorry mate but if
2x=4
then x=2
huh?
2x=4
then x=2
huh?
#4
Posted 24 September 2006 - 04:58 AM
Tcm9669 said:
Umm sorry mate but if
2x=4
then x=2
huh?
2x=4
then x=2
huh?
Thats exactly what I was thinking?!!
#5
Posted 25 September 2006 - 04:21 PM
hehe, that is what I was thinking.
So you have 2x=4 which means x=2? How do you have that in your code? Is it a string?
$variable = "2x=4"?
I do a substr on it, pull out the 2 and the 4 by getting the index of the X and the =. Once that is done, divide 4 variable by 2 variable.
So you have 2x=4 which means x=2? How do you have that in your code? Is it a string?
$variable = "2x=4"?
I do a substr on it, pull out the 2 and the 4 by getting the index of the X and the =. Once that is done, divide 4 variable by 2 variable.
#6
Posted 25 September 2006 - 10:19 PM
Lop said:
hehe, that is what I was thinking.
So you have 2x=4 which means x=2? How do you have that in your code? Is it a string?
$variable = "2x=4"?
I do a substr on it, pull out the 2 and the 4 by getting the index of the X and the =. Once that is done, divide 4 variable by 2 variable.
So you have 2x=4 which means x=2? How do you have that in your code? Is it a string?
$variable = "2x=4"?
I do a substr on it, pull out the 2 and the 4 by getting the index of the X and the =. Once that is done, divide 4 variable by 2 variable.
sort of what i was saying, but i was thinking suppose the equation is dynamic and dependent on what the user enters. he can enter any degree equation and any ammount of terms he wants.
i suppose you could explode it at the equals sign then subtract the right side of the equation from the right side of the equation and set the equation equal to zero. from there you could apply the intermediate value theorum and newtons method (farly basic calc theorums) and iterate it a hundred times or so, if the output appears chaotic there is no answer ie) X^2 = -4 has no answer and the iterations will appear chaotic... if the iterations appear as an integer or appear to approach a single value (rational or irreational) that value is the answer... fairly complex process and would also require taking the derivitive of the equation which would require a complex algorythm in itself... but i suppose this would be the "fool proof" way of going about it..:confused:
edit
hell on second thought X^2 = -4 does have an answer 2i^2 but that would require another step to the program, but its seems pretty straight forward other than a bunch of checks/validations and indepth calculations... and since im learning java in my computer science class i may try to program this in java for fun because im weird like that
#7
Guest_Jordan_*
Posted 26 September 2006 - 08:31 AM
Guest_Jordan_*
How would the user be inserting the code? A textbox?
Logic wise you could have 4 text boxes and one combo box. The first text box they would enter X (using your X^2 equation), combo box select ^ (or * or /), 3rd enter 2, fourth and equals enter -4. You could then take the opposite of the combo box selection and figure out the rest using the textbox variables.
Logic wise you could have 4 text boxes and one combo box. The first text box they would enter X (using your X^2 equation), combo box select ^ (or * or /), 3rd enter 2, fourth and equals enter -4. You could then take the opposite of the combo box selection and figure out the rest using the textbox variables.
#8
Posted 26 September 2006 - 10:35 AM
Hmm its a little complicated!!
#9
Posted 26 September 2006 - 03:02 PM
For exact solutions: you are going to be limited to 4th degree equations. 5th degree equations, in general, do not have a closed form solution, though they can be approximated using Newton's Method. You can find information about general solutions to cubic and quartic solutions here. Mind you, those solutions may be integers but look like messy complex numbers.
#10
Guest_DiscoBob_*
Posted 28 September 2006 - 07:54 PM
Guest_DiscoBob_*
lmao..i can't believe i messed up that first answer XD i must've been thinking i was typing the equation not the answer ::blushes::
all this seems interesting and i will still eventually work on it when im not so busy working on my forums...but thanks for all the info
and es..the user would just enter in an equation in a textbox
all this seems interesting and i will still eventually work on it when im not so busy working on my forums...but thanks for all the info
and es..the user would just enter in an equation in a textbox


Sign In
Create Account

Back to top










