Yo, guys, I got a question, is there any way to improve this or maybe better way to calculate it? Because the only way to calculate derivative very accurate I can think of is this.. lol, its just logic like d/dx of x^n = nx^(n-1) so I thought of that and tried it out, tho doesnt work with functions like e^x so I need help with make a very accurate derivative calculation
function derivative(Function, x)
local dxlog = math.log(Function(x), x)
return dxlog * x^(dxlog - 1)
end
print(derivative(function(x) return x^3 end, 10))
and its so bad it cant even calculate y^x with respect to x..
tried everything I can think of, too dumb to fix this
btw this is the old way I did this:
function derivative(Function, x)
local d = (Function(x + 6.7219579999763e-006) - Function((x - 6.7219579999763e-006))) / 1.3443915999953e-005
if math.abs(math.round(d) - d) < 4.1212121212e-6 then
return math.round(d)
end
return d
end
I presume, you want to get numerical derivative, not symbolic. Then why not use the most straightforward approach?
or simplified: