Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com > PHP Algebra

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 01-02-2006, 06:58 AM PM User | #1 PureMisery New Coder   Join Date: Dec 2005 Posts: 27 Thanks: 0 Thanked 0 Times in 0 Posts Algebra Is there a way to get php to solve for a variable? Ex, 1.1x=110 output to screen would be what x is Last edited by PureMisery; 01-03-2006 at 03:05 PM..
 01-02-2006, 08:46 AM PM User | #2 ralph l mayo Regular Coder     Join Date: Nov 2005 Posts: 951 Thanks: 1 Thanked 31 Times in 29 Posts Brute force? I'm pretty sure that's how the fancy calculators do it. PHP Code: ```     function solveForX(\$equation, \$answer, \$min = null, \$max = null)    {        \$min = (\$min == null) ? -mt_getrandmax() : \$min;        \$max = (\$max == null) ? mt_getrandmax() : \$max;        \$last['guess'] = null;               while (true)        {            eval('\$attempt = ' . str_replace('x', (\$guess = mt_rand(\$min, \$max)), \$equation) . ';');            if (\$attempt == \$answer)            {                return(\$guess);            }            if (\$last['guess'] != null)            {                \$diff = abs(\$answer - \$attempt);                if (\$diff > \$last['diff'])                {                    if (\$guess > \$last['guess'])                    {                        \$max = \$guess - 1;                    }                    else                    {                        \$min = \$guess + 1;                    }                }            }            \$last['guess'] = \$guess;            \$last['diff'] = abs(\$answer - \$attempt);        }    }        echo solveForX('x+(x*.1)', 110);  ``` Note this is oversimplified and will fall into infinite loops on discontinuous functions and functions with noninteger answers. The latter problem is pretty easily resolvable, the former maybe not so much. Also, it'd probably be neater if it was refactored to use recursion, another exercise I'll leave to the reader.
 01-02-2006, 08:45 PM PM User | #3 Kurashu Regular Coder   Join Date: Aug 2004 Location: The US of A Posts: 767 Thanks: 1 Thanked 0 Times in 0 Posts There's some good classes that help handle this. http://www.phpclasses.org/browse/class/65.html Check there for some.
01-03-2006, 05:12 AM   PM User | #4
PureMisery
New Coder

Join Date: Dec 2005
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
 Originally Posted by Kurashu There's some good classes that help handle this. http://www.phpclasses.org/browse/class/65.html Check there for some.
Thanks, I'll go look around there now.

<---edit--->
I found one that I think will do what I need. But how do use the files?

Last edited by PureMisery; 01-03-2006 at 05:19 AM..

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 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 Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 02:45 PM.