Sub derivative() Dim firstx, h, df, f, x, fprime As Double Dim a, b As Double x = 1000 h = 1 / 45555555 firstx = x x = x + h df = -0.0002 * x * x * x + 0.0003 * (a + B)/> * x * x - 0.0006 * a * b * x + 10 x = firstx f = -0.0002 * x * x * x + 0.0003 * (a + B)/> * x * x - 0.0006 * a * b * x + 10 fprime = (df - f) / h MsgBox(fprime) End Sub
This is the code that I have. The function I am trying to get the derivative for is g(x) = -2x^3 + 3(a+b)x^2 -6abx + 10. In my program a and b will be given by the user and than the derivative will be computed. I am not quite sure if I have done this correctly.
Also, I would like the program to output the Maximum and Minimum of the function g(x) on the interval (0,1). I know I will need to use a function for each max and min.
The way I have done this is:
Function Min(x As Variant, y As Variant) As Variant If x > y Then Min = y Else Min = x End If End Function Function Max(x As Variant, y As Variant) As Variant If x < y Then Max = y Else Max = x End If End Function
where x and y are the critical points of g(x).
Have I done this correctly?
I am also a little stuck on how to combine these codes into one so that with the push of a button the derivative is done and a max and min produced.
Any suggestions on how to go about doing this?