Finding Derivatives
In this example, we demonstrate the use of derivatives in Python. Suppose we have a mass m dragged along the ground by a rope attached to a pulley. Suppose also that, as shown in the figure, x is the horizontal distance from the mass to the pulley, h is the height of the pulley, and F is the force applied to the rope. Finally, let g be the gravity acceleration and mu be the friction coefficient of the box along the ground. It can be shown that F = (mu)mg*sqrt(x^2+h^2) / (x + mu*h). We want to know how fast the force is changing with respect to the distance x, both in general and at the following values: m=18 kg, h = 10m, mu = 0.55, g = 9.8, and (two problems): x = 10 m and x = 40 m. For the general expression, we have several symbolic variables, which can be defined one at a time or all at once using the symbols command. Notice the variables are comma separated on the left, but not in the names on the right. After defining our expression F, we use the diff command to differentiate (since “how fast the force is changing” implies we want the derivative of F with respect to x). Either notation: COMMAND(VARIABLE) or VARIABLE.COMMAND works here, with the option being which variable we are differentiating with respect to. All other letters are treated as constants. For the specific values, we will substitute all the values using the subs command; this requires a Python type called a dictionary. Notice the curly braces and the colon notation to specify the value of each variable. Finally, we can get the decimal approximation by using the evalf command.