So I just discovered how to make Integration and Derivatives in roblox so i thought ill share it with yall, if anyone needs it
Derivative
- Create a function… of course
info
._.
function Derivative()
end
- Add a number and a function argument
info
f’(x)
here x
is our number argument and f
is the function arg.
you can name the arguments anything but you have to assign the names everywhere
function Derivative(x: number, f: ())
end
- Create a really small constant
info
The smaller the constant, the bigger the accuracy
function Derivative(x: number, f: ())
local C = 1e-10
end
- Calculate the slope of f from x to x+C
info
This is a bit confusing so please just CTRL+C, CTRL+V it if you dont understand
function Derivative(x: number, f: ())
local C = 1e-10
local slope = ( f(x+C) - f(x) )/C
end
- And lastly, return the slope
- Results:
function Derivative(x: number, f: ())
local C = 1e-10
local slope = ( f(x+C) - f(x) )/C
return slope
end
Integration
- Create a function with 2 number and 1 function argument.
info
;-;
function Integral(x: number, y: number, f: ())
end
- Create a small constant and a zero constant.
info ❗
If the constant is smaller than 1e-6
then it might blow up your pc crash your game.
function Integral(x: number, y: number, f: ())
local C = 1e-5
local a = 0
end
- Make a
for loop
starting at x, ending at y and grows by C
info
shortly, for i = x,y,C do
function Integral(x: number, y: number, f: ())
local C = 1e-5
local a = 0
for i = x,y,C do
end
end
- Insert
f(i)*C
into the loop (adding it toa
)
info
f(i)*C is a thin line under the curve. All of those make up the integral.
function Integral(x: number, y: number, f: ())
local C = 1e-5
local a = 0
for i = x,y,C do
a += f(i)*C
end
end
- And lastly, return
a
:)) - result:
function Integral(x: number, y: number, f: ())
local C = 1e-5
local a = 0
for i = x,y,C do
a += f(i)*C
end
return a
end
NOTE: i didn’t test this in every way i wanted to. It might have bugs or might not even work. I just learned Integration and Derivatives. Also… Integration is 5 decimals accurate