Jump to content

Calculate slope of tangent on curve (Derivative)


Toady
 Share

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!

www.itoady.com

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...