generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Simplistic derivation.

Previous Thread :: Next Thread 
Absurdism is not online. Absurdism
Joined: 18 Jul 2013
Total Posts: 2568
06 Jan 2014 08:16 PM
Happy birthday.

local derivative = function(y)
return (function(x, dx)
dx = dx or 0.1e-5
return (f(x + dx) - f(x))/dx
end)
end

local tangentLine = function(y, x0)
return (function(x)
local dy = derivative(y)
return dy(x) * x + y(x) - dy(x0) * x0 + y(x0)
end)
end

f = function(x) return x^2 end
g = function(x) return math.cos(x) end

print(derivative(function(x) return math.exp(x) end)(0))
print(derivative(f)(2))
print(derivative(g)(math.pi)) -- quite the fault.
print(tangentLine(f, 2)(2))
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
06 Jan 2014 08:17 PM
I get this feeling that I've lost all value as an SH'er as everyone with a problem is more knowledgeable in the field of Lua than I am.
Report Abuse
Absurdism is not online. Absurdism
Joined: 18 Jul 2013
Total Posts: 2568
06 Jan 2014 08:19 PM
'Tis not a problem. I am sharing my knowledge. It's a pretty efficient and accurate derivative calculator.
Report Abuse
StBashkir is not online. StBashkir
Joined: 29 Aug 2008
Total Posts: 26171
06 Jan 2014 08:39 PM
"I get this feeling that I've lost all value as an SH'er as everyone with a problem is more knowledgeable in the field of Lua than I am."

Mmmm... don't confuse knowing Lua with knowing a bit of math.
Report Abuse
Absurdism is not online. Absurdism
Joined: 18 Jul 2013
Total Posts: 2568
06 Jan 2014 08:40 PM
A slight variation is using:

local derivative = function(y)
return (function(x, dx)
dx = dx or 0.1e-5
return (f(x + dx/2) - f(x - dx/2))/dx
end)
end

Which may provide more accurate results depending on the context.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image