# Calculate slope of tangent on curve (Derivative)

## Recommended Posts

```;=======================================================
; Function: _SlopeOfTangent
;
; 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 on other sites

That is just too simple...

##### Share on other sites

That is just too simple...

would you have prefered it to be over 100 lines, or a full blown #include?

Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...