Lost Password?


Go Back   CodeCall Programming Forum > Web Development Forum > PHP Forum

PHP Forum Use this forum to discuss all aspects of PHP Development. PHP is a server-side, cross-platform, HTML embedded scripting language that lets you create dynamic web pages.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-23-2006, 05:48 PM
DiscoBob DiscoBob is offline
Newbie
 
Join Date: Jul 2006
Posts: 12
Rep Power: 0
DiscoBob is on a distinguished road
Default Solving Variable Equations

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 09-24-2006, 02:22 AM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,433
Last Blog:
Google Web Toolkit
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-24-2006, 04:19 AM
TcM's Avatar   
TcM TcM is offline
Code Warrior
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 8,332
Rep Power: 68
TcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of light
Default

Umm sorry mate but if

2x=4
then x=2

huh?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-24-2006, 08:58 AM
Jimbo Jimbo is offline
Programmer
 
Join Date: Jul 2006
Posts: 121
Rep Power: 9
Jimbo is on a distinguished road
Default

Quote:
Originally Posted by Tcm9669 View Post
Umm sorry mate but if

2x=4
then x=2

huh?
Thats exactly what I was thinking?!!
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 09-25-2006, 08:21 PM
Lop's Avatar   
Lop Lop is offline
Speaks fluent binary
 
Join Date: May 2006
Posts: 1,149
Rep Power: 18
Lop will become famous soon enoughLop will become famous soon enough
Default

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.
__________________
Lop
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 09-26-2006, 02:19 AM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,433
Last Blog:
Google Web Toolkit
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default

Quote:
Originally Posted by Lop View Post
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.
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..

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

Last edited by John; 09-26-2006 at 02:27 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 09-26-2006, 12:31 PM
Jordan's Avatar   
Jordan Jordan is online now
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 9,232
Last Blog:
Ext JS or Ext GWT
Rep Power: 20
Jordan is just really niceJordan is just really niceJordan is just really niceJordan is just really nice
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default

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.
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog
The CodeCall Wiki is now fully integrated with vBulletin users! Check it out and add some new pages!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 09-26-2006, 02:35 PM
TcM's Avatar   
TcM TcM is offline
Code Warrior
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 8,332
Rep Power: 68
TcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of light
Default

Hmm its a little complicated!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 09-26-2006, 07:02 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,277
Last Blog:
wxWidgets is NOT code ...
Rep Power: 36
WingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to all
Default

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.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 09-28-2006, 11:54 PM
DiscoBob DiscoBob is offline
Newbie
 
Join Date: Jul 2006
Posts: 12
Rep Power: 0
DiscoBob is on a distinguished road
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using input to change a variable? Plutonic Java Help 3 07-17-2007 05:02 PM
symbolic equation solving? Witash General Programming 4 03-31-2007 06:24 PM
Java:Tutorial - The Variable John Java Tutorials 0 12-09-2006 10:59 AM
Variable Names Paradine PHP Forum 3 11-03-2006 12:29 PM
Variable to Debug Window Void C# Programming 3 07-04-2006 09:26 AM


All times are GMT -5. The time now is 04:57 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 98%

Ads