Jump to content
Sign in to follow this  

Calculate slope of tangent on curve (Derivative)

Recommended Posts


; Function: _SlopeOfTangent
; Author: Toady
; Action: Calculates the slope of of a tangent to a curve
;         Same as calculating the derivative in calculus
; $expr: String - Mathmatical expression
; $var: String - Independent variable
; $at_point: Number - x coordinate to evaluate slope
; $places: Integer - Places to round result (default = 4)
; Ex) y = x^2
;     dy/dx = 2x
;     dy/dx(2) = 4
; MsgBox(0,"Slope",_SlopeOfTangent("x^2","x",2))
Func _SlopeOfTangent($expr,$var,$at_point,$places=4)
    Local $dx = 0.00000001
    Local $x = $at_point
    Local $y = $x + $dx
    Local $slope = Execute(StringReplace($expr,$var,"$y")) - Execute(StringReplace($expr,$var,"$x"))
    Return Round($slope/$dx,$places)
EndFunc ;_SlopeOfTangent()==>

Here is a script I had to write for one of my courses in school. It is the same as calculating the derivative

of a function to determine the slope of a tangent point. Very simple!


A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.