View Full Version : Maximise function in PHP

ojsimon

09-21-2009, 05:48 PM

Hi

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?

Thanks

funnymoney

09-21-2009, 05:59 PM

umm..

this maybe?

function Integer($integer) {

return $integer;

}

print Integer(5) - Integer(3);

//prints 2

ojsimon

09-21-2009, 07:21 PM

how would i use that?

tomws

09-21-2009, 08: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).

ojsimon

09-21-2009, 08: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.

ojsimon

09-22-2009, 05: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:

u=S*(1+((x/P)-1)*-E)

m=(u*(x-C))-F

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

m=S*(1+((x/P)-1)*-E)(x-C)-F

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?

funnymoney

09-22-2009, 11:42 PM

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 ;)

Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.