You are on page 1of 19

Differentiation

with Python Programming


Module 3- Part 2
CS 132 - Mathematics for Computer Science

1
Objectives

1. Solve problems that need the application of the concept of


the derivative.

2. Introduce Differentiation using the Python programming


language.
General Points

I. DERIVATIVE AS A RATE OF CHANGE


The first derivative of a function is a rate of change.

II. DERIVATIVE AS THE SLOPE OF A TANGENT LINE


Given y=f(x), dy/dx represents the slope of a line that is tangent to the curve y=f(x) at a
certain point.

III. MAXIMA AND MINIMA


The/A point in a curve where the tangent line has a slope that is equal to zero is a MINIMUM
point or a MAXIMUM point.
General Points
MAXIMA and MINIMA.
The/A point in a curve where the tangent line has a slope that is equal to zero is a MINIMUM point or
a MAXIMUM point.
• In some applications, the function dealt with is corresponding to a curve showing
measurements of errors (i.e. error function ).
• The error is a function of some variables.
• i.e. y = f(x) where y represents error as a function of the value of x

• The interest is usually the point corresponding to a minimum error, that is, a minimum point
in the curve.

• A minimum point is a point where the slope of the tangent line is zero(horizontal line).
Hence, a minimum point corresponds to "when the first derivative is equal to 0".

• Look at dy/dx=0
General Points
MAXIMA and MINIMA.
The/A point in a curve where the tangent line has a slope that is equal to zero is a MINIMUM point or
a MAXIMUM point.

 Profit, or something of the same nature, may be represented by a function (i.e. profit
function).

 Profit is a function of some variables.


 i.e. y=f(x) where y represents profit which depends on x

 With the profit function, the interest is the point corresponding to a maximum value, that is,
a maximum point in the curve. Like the minimum point, the tangent line to a curve at the
maximum point is 0 (horizontal line).

 Look at dy/dx=0
Problem:
Find the rate at which the reciprocal of a number changes as the number increases.

• Create the equation that shows the reciprocal as a function of


the number.

Let R be the reciprocal and n be the number.

R = 1/n

• The rate at which the reciprocal of a number changes as the


number increases is the derivative of R with respect to n, dR/dn

dR/dn = d/dn (1/n) = d/dn (n-1) <— Apply the formula d/dn(u ) = nu
n n-1(du/dn)

dR/dn = (-1)n-1-1(dn/dn) = (-1)n-2(1)= -n-2 = -1/n2. <— ANSWER


Find how fast the body diagonal of a cube increases as the length of the
edge increases. See figure.

Let
D = length body diagonal
E = length of an edge edge
F = length of face diagonal

Find a way to express the length of the body


diagonal as a function of the length of an edge
Find how fast the body diagonal of a cube increases as the length of the
edge increases. See figure.

D
E

Let D = length body diagonal, E = length of an edge, F = length of face diagonal

Find a way to express the length of the body


diagonal as a function of the length of an edge
Find how fast the body diagonal of a cube increases as the length of the
edge increases. See figure.

D
E

F
Let D = length body diagonal, E = length of an edge, F = length of face diagonal

Find a way to express the length of the body diagonal as


a function of the length of an edge
Since, the figure is a right triangle, the
Pythagorean theorem applies.
D2=F2+E2.
Find how fast the body diagonal of a cube increases as the length of the
edge increases. See figure.

D
E
F
Let D = length body diagonal, E = length of an edge, F = length of face diagonal

Find a way to express the length of the body diagonal as a function of


the length of an edge
Since, the figure is a right triangle, the Pythagorean theorem applies.
D2=F2+E2.

The Face diagonal F can be expressed in terms of E.


Find how fast the body diagonal of a cube increases as the length of the
edge increases. See figure.
From one face

F
E
E

The Face diagonal F can be expressed in terms of E. (Look at one face of the
cube)

Pythagorean theorem applies because a right triangle is formed.


F2 = E2 + E2.
F2 = 2E2.
F = Square root of 2E2
Since square root of E 2 is E; F = E2
Find how fast the body diagonal of a cube increases as the length of the
edge increases. See figure.
D F =E2
E
F

Let D = length body diagonal, E = length of an edge, F = length of face diagonal

Go back to the inner triangle involving the body diagonal

D2=F2+E2.
D2=(E√2)2+E2.
D2=2E2+E2.
D2=3E2.
D = Square Root of 3E2.
D = (3)E
Find how fast the body diagonal of a cube increases as the length of the
edge increases. See figure.

Let D = length body diagonal, E = length of an edge edge, F = length of face diagonal

The rate at which the body diagonal (how fast!)


increases as the length of the edge increases is
dD/dE.
Since, D = (3)E.
dD/dE = d/dE((3)E) = 3(dE/dE)
= 3(1) =3 ANSWER
Exercises

• Please find separate file showing more examples of


application problems and solutions. Review the examples.

• Some problems included in the Problem Set for the


midterms should be solved by applying the concept of
derivatives.
Differentiation Using Python Programming

• Some derivatives may be determined by using Python


programming. Unfortunately, getting the derivatives of
complex expressions using Python programming may be
more challenging than getting the derivative
analytically(manually).

• For our introductory course, we have the following


example on differentiation using Python programming.
Differentiation Using Python Programming

• The Sympy module of the Python Programming


language may be used to determine the
derivative of f(x)
Differentiation Using Python Programming

Code in Python
# derivative of f(x) = x^3 - 2x
# In Python, the operator ** is for exponentiation

import sympy as sp
def f(x):
return x**3 - 2*x
x=sp.Symbol('x')
print("Derivative of f(x) = ", sp.diff(f(x)))
Differentiation Using Python Programming

Code in Python

# derivative of f(x) = x^3 - 2x


# In Python, the operator ** is for exponentiation

import sympy as sp
def f(x):
return x**3 - 2*x
x=sp.Symbol('x')
print("Derivative of f(x) = ", sp.diff(f(x)))
Output:
Derivative of f(x) = 3*x**2 - 2
Be reminded.
Authentic learning of
Mathematics and
Programming happens
through doing exercises.
Reading is not enough!
- More Power.

You might also like