View Full Version : Maximise function in PHP

09-21-2009, 06:48 PM

In my script i am trying to maximise a function, is it possible to do this with php? can you differentiate a function using php is what i am essentially asking?


09-21-2009, 06:59 PM

this maybe?

function Integer($integer) {
return $integer;

print Integer(5) - Integer(3);
//prints 2

09-21-2009, 08:21 PM
how would i use that?

09-21-2009, 09:12 PM
I think funnymoney has confused elementary subtraction with calculus.

Short answer: yes, you can do differentiation and loads more in PHP. There's not a built-in function, AFAIK. Here's a page that may help you get started building your own (http://www.phpmath.com/home?op=cat&cid=29).

09-21-2009, 09:29 PM
Thanks, i've worked it out thouigh, becuase it is just a quadratic i can just imput the a b and c values directly into a difernetiated version of the equation.

09-22-2009, 06:13 PM
ok so thought this was solved but just realised this solution won't work, as i am forming the equation from two simultaneous equations:

S, P, E, C and F are provided by the user hence i can use the following equation


I want to find the maximum value for M given all the variables in the equation above are given apart from x

this with those values should simplify to a quadratic which you could find a derivative for and optimize.

Does anyone know how to do this with php?

09-23-2009, 12:42 AM
i forgot how to handle those kind of math issues. was long time ago. i have a book near here i can look into, but i really don't want to remove the dust from the covering.

if you can remind me how to find maximum in a function. i remeber it had something to do with derivations... dunno how you call it. later i learned about integrals, also dunno how you say it right, but i'm pretty sure they were used to calculate surface under some curve or function something thingy... :rolleyes:

maybe you can even write it on paper and then post it here to "program" the function ;)