2 views

Uploaded by Rafflesia Khan

MatLab Lecture

- IIT-JEE Mathematics
- Maxima and Minima
- Final Overview
- Samuel Beckett - Dante... Bruno. Vico... Joyce
- Calculus Cheat Sheet All
- Maths Methods Calculus Notes
- 105628202-quant2
- Optimization of Maxima and Minima
- NUS - MA1505 (2012) - Chapter 2
- Sketching Graphs
- calculus cheat sheet all reduced 1
- Practice Exam IBEB NonCD Version 2014
- 16.Test3review and Solns (1)
- Generative Shape Design - Detailed Steps
- Note12_Optimization_and_Pracital_Optimization.pdf
- Functions of Several Variables
- Worked Solutions - Mathematics SL
- 02 01 Differential Calculus
- 6502 Multi 10
- XII-HSC Board Paper Maths Solutions

You are on page 1of 16

Differential Calculus

Derivative

The derivative of a function, F(x), is the instantaneous change of the function with respect to the

instantaneous change in the variable(s). Another way of saying this is that the derivative is the slope of a

tangent line to the curve defined by the function. Since the tangent line varies with the choice of variable,

the derivative is itself a function

The derivative is given several symbols, but the mathematical equation that defines it (the so-called limit

definition) is:

dF ( x) F ( x x) F ( x)

F ' ( x) Fx ( x) lim

dx x 0 x

We will not discuss limits too much, since they are never used to actually compute derivatives.

Just remember that the limit is the value that the function f(x) approaches or converges to when x gets

closer to some particular point, or infinity.

That means the function can have a limit even at points where it does not exist, or can have a completely

different value and limit.

However, for a continuous function, the limit equals the function value, i.e.

lim f ( x) f (a)

xa

The definition of the derivative by the limit in the above equation is also how it is actually done

numerically (on the computer), so keep it in mind.

1

Second derivative

The derivative of a function is itself a function. The derivative of this new function is the "second

derivative" of the initial function. The second derivative describes how the slopes of tangent lines change

as one moves from low x to high x from a given point.

d 2 F ( x)

lim

F ( x x) F ( x) F ( x) F ( x x)

dx 2 x 0 x 2

F ( x x) F ( x x) 2 F ( x)

lim

x 0 x 2

Again not this last equation for later numerical calculations of second derivatives.

The Differential of a Function

The derivative is the change in the function divided by the change in the variable. But, if we wanted to

know the amount by which the function changes as a result of changing the variable, we are asking about

the differential of the function, dF(x):

d F(x)

d F(x) = dx

dx

This seemingly simple idea implies that the derivative IS a fraction!!

Differentiation formulas

Derivatives of Sums: When two function are added, the derivative of the sum is equal to the sum

of the derivatives:

d F(x) + G(x) d F(x) d G(x)

= +

dx dx dx

Derivatives of Products: When two functions are multiplied, the differentiation is done in the

following way:

d F(x)•G(x) d F(x) d G(x)

= G(x) + F(x)

dx dx dx

This is usually called the product rule for differentiation.

The Quotient Rule: A special case of the product rule is when the one of the functions is divided by

the other, i.e. F(x)/G(x). To do this, we will write the quotient as:

F(x)

= F(x) [G(x)]–1

G(x)

This allows us to recognize that, indeed, this is a product. Therefore, the derivative is:

d F(x)• G(x) –1 d F(x) d G(x) –1

= G(x) –1 + F(x)

dx dx dx

What do we do about d[G(x)]–1/dx? This falls into the category of a function of a function. Therefore,

we can write:

d G(x) –1 d G(x) –1 d G(x) d G(x)

= = –1 G(x) –2

dx d G(x) dx dx

2

Thus, the derivative of the quotient is:

d F(x)• G(x) –1 d F(x) d G(x)

= G(x) –1 + F(x) –1 G(x) –2

dx dx dx

d F(x) d G(x) G(x) Fx (x) – F(x) Gx (x)

= G(x) –2 G(x) – F(x) =

dx dx G(x)2

The last expression is known as the "quotient rule", although it is nothing more than the product rule with

the chain rule.

Derivatives of simple functions: Every derivative can be solved using the limit definition, but

the process tends to be tedious. Several general results have been found that should be second nature.

Here is a list of functions whose derivatives should be known:

d (x p ) d (sin( x))

px p 1 for any p (integer or not) cos( x)

dx dx

d (e x ) d (cos( x))

ex sin( x)

dx dx

d (a x ) d (tan( x)) 1

a x ln(a )

dx dx cos 2 ( x)

d (ln( x)) 1 d (cot( x )) 1

2

dx x dx sin ( x )

d (log a ( x)) 1

dx x ln(a )

Chain Rule: Many functions are so-called "composite functions", meaning they are functions of

functions, which we can represent by G(F(x)). To take the derivative of G with respect to x requires us to

first differentiate G with respect to F, then differentiate F with respect to x. This is called the chain rule,

and it is written:

d G(F(x)) d G(F(x)) d F(x)

=

dx d F(x) dx

In practice, the function F(x) is usually set equal to another variable, say F(x) = y. This gives G(F(x)) =

G(y). This allows us to write the more common form of the chain rule:

d G(y) d G(y) d y

=

dx dy dx

3

Implicit Differentiation: Not all functions are written in terms of y = F(x). Some functions, for

example the function describing a circle, is a function of both x and y. It is possible to differentiate the

entire function with respect to x. In doing so, we will use the chain rule for the y = y(x) dependency, and

solve for the exact form of dy/dx.

d F(x,y) d f(x) d g(y) d y

F(x,y) = f(x) + g(y) = +

dx dx dy dx

= – /

dx dx dx dy

Example - The equation of a circle is x2 + y2 = r2, where r is a constant (the radius

of the circle). Taking the derivatives gives:

d (x2 ) d (y2 ) d (y2 ) d y d y d (r2 )

+ = 2x + = 2x + 2y =

dx dx dy dx dx dx

Since r is a constant, we can write it as r•x0, which when we take its derivative gives 0•r•x0–1 = 0. Thus,

we have:

dy dy dy

2x + 2y = 0 2y = –2x = – 2x = – x

y

dx dx dx 2y

In other words, it depends on both x and y. Of course we could try to determine the function y=y(x) and

differentiate it, but in most cases, this is much more complicated

Note 1: We can always find functions in terms of x and y and differentiate implicitly.

Note 2: We could have also differentiated with respect to y instead of x and arrive at dx/dy implicitly.

But, dx/dy = 1/[dy/dx], so the end result will have the same meaning.

Example Differentiating an inverse trigonometric function:

Functions like arcsin (sin–1) and arccos (cos–1) can be differentiated using the relationship

dy/dx = (dx/dy)–1. This example demonstrates this for y = arctan(x):

sin(y)

y = tan–1 (x) tan(y) = tan(tan–1 (x)) = x x = tan(y) =

cos(y)

sin(y) cos(y)[cos(y)] – sin(y)[–sin(y)] cos (y) + sin2(y)

2

dx = d = =

dy dy cos(y) cos2 (y) cos2 (y)

sin2 (y) dy

=1+ = 1 + tan2(y) = 1 + x2 = 1

cos2(y) dx 1 + x2

d ( f 1 ( x)) 1 1

dx f y df ( y ) dy

Example:

d arcsin( x) 1 1 1 1

dx d sin( y ) / dy cos( y ) 1 sin ( y )

2

1 x2

4

Extrema (maxima and minima) or functions

Since the derivative is the slope of a tangent line, the point when the derivative equals zero (i.e. F'(x) = 0)

has a tangent line that is horizontal. If the derivative at one of the points immediately to the side of the

horizontal is a positive, and at the other it is a negative, the horizontal corresponds to a "local extremum".

There are two possible extrema: maximum and minimum.

If the second derivative is negative, then the function at the extremum is at a MAXIMUM.

If the second derivative is zero, the point represents an INFLECTION POINT, i.e. between a max and a

min., where the function changes shape (from “convex” to “concave” or vice versa)

Example: Find r where the Morse potential function has a minimum.

Morse potential is given by

V ( r ) De 1 e r re 2

Here, De is the dissociation energy (which is always positive) and k / 2 De where k is harmonic

force constant (also positive).

d

dr

d

V (r ) De 1 e r re

dr

2

0

2 De 1 e r re e r re 0

2 Dee r re

1 e r re

0

e r re

1 e r re

0

5

r re

Because e is always greater than zero (remember the exponential functions - we talked about

them so much for a reason) the square bracket must be zero:

1 e r re 0

or e r re 1

( r re ) 0

Is it really a minimum? To confirm that, calculate the second derivative and show that it is positive at re:

d2

dr 2

V (r )

d

dr

2 De e r re 1 e r re

2 De e r re 1 e r re e r re e r re

r re

for r = re e e 0 1 so substituting simplifies things:

d2

2

V (r ) 2 De (1 1) 1 2 De 2 k

dr rr e

Taylor series expansion

Any function f(x) can be expanded into a polynomial series around some point x0 as:

df ( x) 1 d 2 f ( x) 1 d 3 f ( x) 1 d n f ( x)

f ( x) f ( x0 ) ( x x0 ) ( x x0 ) 2 ( x x0 ) 3 ... ( x x0 ) n ...

dx x x0 2 dx 2 x x0

6 dx 3 x x0

n! dx n x x0

1 d n f ( x)

n

( x x0 ) n

n 0 n! dx x x0

where x x0

means that the derivative is taken at x0. Note that the series is infinite. But for x close to x0 the

higher powers of (x x0) get smaller and smaller and the series typically converges very quickly. As a

result, to approximate the value of a function close to some point, the series can be truncated after the first

few terms without much loss in accuracy. Taylor expansion is therefore often used to approximate

complicated functions by a polynomial, commonly linear or quadratic function. But remember - it works

only for small (x x0) !

6

Some useful Taylor expansions:

1 2 1 3 1

ex 1 x x x ... x n ... ex 1 x

2 6 n!

1 3 1 5 1 7 sin( x) x

sin( x) x x x x ...

6 5! 7!

1 2 1 4 1 6

cos( x ) 1 x x x ... cos( x ) 1

1 2

x

2 4! 6! 2

1 2 1 3 1 4 ln(1 x) x

ln(1 x) x

x x x ...

2 3 4!

1 1 2 1 3 5 4

1 x 1 x x x x ... 1 x 1

1

x

2 8 16 128 2

1

x x 2 x 3 x 4 x 5 ... 1

1 x x

1 x

1

1 2 x 3 x 2 4 x 3 5 x 4 ... 1

1 2x

1 x 2

1 x 2

7

Numerical differentiation

As we have already discussed multiple times, but keep discussing, numerically a function is an array of

point for x with the corresponding array of points for y. That means that all the operations, including

derivatives, will be operations on arrays of points.

The points are spaced by finite steps and the derivative therefore must be approximated by finite

differences:

Over the whole interval, we can write the derivative as finite differences over all points. If

If our x is equally spaced, which is often the case (especially when we generate it in MATLAB using

a:b:c or linspace) all (xk+1 xk) will be the same, so we can call

dx = x(2)-x(1)

dy/dx

8

We know derivative is a function, precisely defined for each point x where it is calculated.

There is a slight problem when calculating finite differences: you need two points k and k+1 of the

function to get one point finite difference. Which x should it go with? k or k+1?

Rigorously, because we are doing finite differences, the derivative is an average over the interval

bounded by the two points. The natural place to put this would therefore be right in the middle between

the points k and k+1.

Also as you can see, from both the equations above and the figure, you will get one less point when you

calculate the derivative than the number of points you had in your original function. Therefore, to

represent the numerical derivative, we would have to “rescale” the original x-axis, in addition to

calculating all numerical differences.

In MATLAB, the numerical derivative (finite differences) can be written simply, taking advantage of all

the gymnastics possible with arrays:

x =

-5 -4 -3 -2 -1 0 1 2 3 4 5

>> y=x.^3;

y =

-125 -64 -27 -8 -1 0 1 8 27 64 125

>> dy=y(2:end)-y(1:end-1)

dy =

61 37 19 7 1 1 7 19 37 61

>> dx=x(2)-x(1)

dx =

1

>> dy_dx=dy/dx

dy_dx =

61 37 19 7 1 1 7 19 37 61

>> der_y=dy/dx

der_y =

61 37 19 7 1 1 7 19 37 61

Notice we have one less point in der_y than we had in y (or x).

>> length(y)

ans =

11

>> length(der_y)

ans =

10

9

Now we can plot the function, we have both x and y:

>> plot(x,y,'x-');

(plotted as connected blue crosses)

but to plot the derivative, we cannot use x and der_y, because they have difference numbers of points:

>> hold on

>> plot(x,der_y,'o-r');

??? Error using ==> plot

Vectors must be the same lengths.

We have to redefine x, but putting it the middle between the original points. That is done by “averaging”

each x point with the next: (x(1)+x(2))/2, (x(2)+x(3))/2, …

We can again write this very simply:

>> der_x=0.5*(x(1:end-1)+x(2:end))

der_x =

Columns 1 through 7

-4.5000e+000 -3.5000e+000 -2.5000e+000 -1.5000e+000 -5.0000e-001

5.0000e-001 1.5000e+000

Columns 8 through 10

2.5000e+000 3.5000e+000 4.5000e+000

>> plot(der_x,der_y,'o-r');

>> grid on

10

It turns out, however, that you do not have to do all this. The numerical derivative is already pre-

programmed in MATLAB for you and called diff(). The following commands would do exactly the

same as we did “by hand” above:

>> dy=diff(y)

dy =

61 37 19 7 1 1 7 19 37 61

In fact, diff will do any order of finite differencing: diff(y,n) will calculate nth order.

For example, if I wanted second derivative

>> d2y=diff(y,2)

d2y =

-24 -18 -12 -6 0 6 12 18 24

Note that we lost a point again so we would have to “rescale x” again and then again for each higher

derivative.

However, it turns out that you do not have to do even that. There is a function in MATLAB which will

calculate the numerical derivatives and keep the number of points the same. This function, which I

strongly recommend to use, is called gradient().

>> x=[-5 -4 -3 -2 -1 0 1 2 3 4 5]

x =

-5 -4 -3 -2 -1 0 1 2 3 4 5

>> y=x.^3

y =

-125 -64 -27 -8 -1 0 1 8 27 64 125

>> dy=gradient(y)

dy =

61 49 28 13 4 1 4 13 28 49 61

>> dx=x(2)-x(1)

dx =

1

>> dy_dx=dy/dx

dy_dx =

61 49 28 13 4 1 4 13 28 49 61

>> figure(1);clf reset

>> plot(x,y,'x-k')

>> hold on

>> plot(x,dy_dx,'o--r')

11

To calculate numerical derivatives, use gradient()function.

But remember to not forget to divide by x !!!!

You can put everything in one general command to calculate a numerical derivative:

>>dy_dx=gradient(y)/(x(2)-x(1));

>>d2y_dx2=gradient(gradient(y))/(x(2)-x(1))/(x(2)-x(1));

12

Maxima and minima

On paper, you look for extrema (maxima, minima) by calculating derivatives and setting them to zero.

On the computer, with a numerical representation of the function you do not have to do that. Since you

have an array (y) that represents your function, you can just look for the element of the array which has

the greatest value. The you find the corresponding element of the x array, which will tell you where the

maximum is.

Simple example:

x=[0 1 2 3 4 5 6 7 8 9 10]

y=[0 1 2 4 8 16 8 4 2 1 0]

The maximum is 16, it is the 6th element of the array 6 (its index is 6) and it corresponds to the 6th element

of x, which is 5. Therefore the function has a maximum at x =5 (and the maximum value is 16)

To find minima, there is a MATLAB function min().

They both works the same way, the difference is obvious: max find the greatest value, min the smallest.

Both max and min return the value (greatest, smallest) of the array, but can also return their indices. That

is how we can use them to find the positions of the maxima and minima:

13

[max, imax]=max(y)

Will give you the maximum value in the FIRST variable (max), and its index in the SECOND variable

(imax) in the square bracket.

(Note that it is always the FIRST and the SECOND what matters, not how you call them!)

>> [max,imax]=max(y)

max =

16

imax =

6

Now I can use imax (the index of the maximum element) to find its position on x.

>> x(imax)

ans =

5

>> y=[15 10 6 3 1 0 1 3 6 10 15];

>> plot(x,y,'-o')

>> plot(x,y,'-o')

>> [v,index]=min(y)

v =

0

index =

6

>> min_on_x=x(index)

min_on_x =

5

>>

This will work if you have one maximum (minimum) or searching for the global one. However,

remember that this is only an approximate extremum of your function. Always keep in mind that the

function is discretized, i.e. given by a finite number of points. You may not have a point exactly where

the true minimum/maximum is. That means to get the maximum/minimum accurately, you need

reasonably fine “grid” (point spacing).

There are more sophisticated tools to find maxima and minima, for example the MATLAB function

fminbnd().

14

Taylor expansions

From what we just learned we should be able to construct Taylor expansions of any function at any point

(except the end points) and of any order. Typically, we do Taylor expansions need the minima (or

maxima).

On of the most important Taylor expansions is the so-called HARMONIC APPROXIMATION, which

his nothing else but an expansion of a potential function near its minimum truncated after the quadratic

term. (The quadratic term is really the leading term at the minimum, because the linear term is always

zero why do you think that is?)

As an example, consider some arbitrary potential V, for which I have a function (named potential)

written somewhere:

>> x=0:250;

>> V=pontential(x);

>> plot(x,V);xlabel('x');ylabel('V');

>> [min,ind]=min(V)

min =

-2.3778e-002

ind =

117

Now I need to calculate the second derivative AT THE MINIMUM (remember I do not need the first

derivative, because at minimum it is zero). I do it by using the gradient() function twice and then

taking my second derivative at the point with the index ind that I just found to be the point where my

minimum is.

15

I also need to calculate x to get my derivative (never forget to divide by those when computing

derivatives)

>> dx=x(2)-x(1);

>>d2V=gradient(gradient(V))/dx/dx;

2

And now my Taylor expansion: f ( x) f ( x0 ) 1 d f ( x) ( x x0 ) 2

2 dx 2 x x

0

(remember, the x0 is now the minimum, and that is given by x(ind) where ind is the index of my

minimum);

>> Taylor=V(ind)+0.5*d2V(ind)*(x-x(ind)).^2;

And now I can plot it over my original function to see how well it approximates my potential V:

>>hold on;

plot(x,Taylor,’--r’);

You can see the quadratic function is a really good approximation close to the minimum, but get worse as

we get further away. That is why you will hear in your P-chem that harmonic approximation is good for

small displacements from equilibrium position (small amplitude vibrations).

16

- IIT-JEE MathematicsUploaded byAnonymous 8pCXXs
- Maxima and MinimaUploaded byTrisha Marieh
- Final OverviewUploaded byPatSramek
- Samuel Beckett - Dante... Bruno. Vico... JoyceUploaded byLore Buchner
- Calculus Cheat Sheet AllUploaded bykwame
- Maths Methods Calculus NotesUploaded byAnonymous na314kKjOA
- 105628202-quant2Uploaded bySwathi Narashima Rajan
- Optimization of Maxima and MinimaUploaded byarpit_srivastava706
- NUS - MA1505 (2012) - Chapter 2Uploaded byGilbert Sebastiano
- Sketching GraphsUploaded byAnonymous CKg2M9Sn
- calculus cheat sheet all reduced 1Uploaded byapi-319065418
- Practice Exam IBEB NonCD Version 2014Uploaded byYonYon
- 16.Test3review and Solns (1)Uploaded bymplukie
- Generative Shape Design - Detailed StepsUploaded byNoel Montoya
- Note12_Optimization_and_Pracital_Optimization.pdfUploaded by李华夏
- Functions of Several VariablesUploaded byVishnu Krishna Kumar
- Worked Solutions - Mathematics SLUploaded byPyjama Man
- 02 01 Differential CalculusUploaded byJohn Bofarull Guix
- 6502 Multi 10Uploaded byRoy Vesey
- XII-HSC Board Paper Maths SolutionsUploaded bySanskar Singh
- Mathematics CalculusUploaded byuditagarwal1997
- problemas de optimizaciónUploaded byAlexandra Díaz
- Limits MathsUploaded byPavan Boro
- College Algebra Graphs and Models 5th Edition Bittinger Test BankUploaded bya369417428
- Math ReviewUploaded bysupermario27
- Final1 ScanUploaded byMohammed Ibrahim
- MaximumUploaded byJL1206
- Exam 2Fall2012Uploaded byAli Hassan
- Math ThesisUploaded byMarie Walidji
- GraphRecLabSorts2007Uploaded byCarol H. APSI teacher

- Lecture Notes 2Uploaded byRafflesia Khan
- Asst3drfhg.psUploaded byRafflesia Khan
- NN SolutionsUploaded byಶ್ವೇತ ಸುರೇಶ್
- Weekly schedule templateUploaded byRafflesia Khan
- Ip in MatlabUploaded byRafflesia Khan
- Biodata Template 1 (1)Uploaded bymemalang
- Asst3 Solu.psUploaded byDuy Khánh Nguyễn
- asst4_solu.psUploaded byRafflesia Khan
- asst4_solu.psUploaded byRafflesia Khan
- Weekly Schedule Class 9 and 10Uploaded byRafflesia Khan
- Matlab FunctionUploaded byMoataz Dablo
- ch6_perceptron_mlp.pdfUploaded byKrishnan
- Lecture Notes 3Uploaded byRafflesia Khan
- Digital Image Processing Using Matlab (Gonzalez)Uploaded byAlex Țîmpău
- 0016 Microsoft Excel 2007 AdvancedUploaded byrohit raj
- j Intswing a4Uploaded byapi-26977199
- Graph Paper Template 06Uploaded byRomee Singh
- Swings PDFUploaded byneondust
- Image Processing Using MATLABUploaded byamadeus99
- Eclipse ProgrammingUploaded byAileen Chan
- Applet 1Uploaded byVaibhav Patil
- Engineering Graph PaperUploaded byJose Cesar G. Souza
- Welcome to the Computer Science and Engineering Discipline _ Khulna UniversityUploaded byRafflesia Khan
- grid-portrait-letter-6-index.pdfUploaded byRafflesia Khan
- TopologyUploaded byRafflesia Khan
- Laboratory Projects_DIP3EUploaded bycycliccrap
- Cryptography and Network Security Forouzan - CopyUploaded byRafflesia Khan
- Grid Portrait Letter 6 IndexUploaded byRafflesia Khan
- SwingUploaded byRafflesia Khan

- Limit Theorems.pptUploaded bysvillejohn05
- Limits.pdfUploaded byavijit_dasbihari1266
- Limits of Functions of Two VariablesUploaded byHugo Mayorga
- Continuous FunctionsUploaded byisraeljumbo
- A First Course in Complex AnalysisUploaded bysxydxt
- Reviewer - Differential CalculusUploaded byLorenz Ardiente
- Introduction to the Calculus of VariationsUploaded byNiflheim
- Calculus Cheat SheetUploaded bySrinivas Rao
- Epsilon DeltaUploaded bysprokonoinoi
- Foundations Of Economic AnalysisUploaded byVeeMeas
- mathematics.pdfUploaded byJohn Smith
- Chapter 1 SolutionsUploaded byToby Le
- Bernstein Calculus for MathematiciansUploaded bycamiloa91
- Differential and Int Clyde.Uploaded bysadna fernando
- pakram pakramUploaded byRugmini Vasudevan
- Rudin_4Uploaded byjubykins
- Worksheet LimitesUploaded byEduardo Nagel
- Calculus of Vector Valued FunctionsUploaded byDilo Tan
- CalcI Complete PracticeUploaded byJoy Edwards
- limit and continuity studentUploaded byHasnah Yahya
- 237 Course NotesUploaded byHarrison Gross
- Monotone Control SystemsUploaded byFabián Alberto Ortega Quintana
- calculus cheat sheet all reduced 1Uploaded byapi-319065418
- 1. Limit and Continuty (s)Uploaded byZuraini Arshad
- NCERT Continuity & DifferentiationUploaded bymastermohit1
- Bsc_mathsfirstyearUploaded byhaseeb3061
- Function and LimitUploaded byMahfuzh Zuhdi
- Limits of functions.pdfUploaded bygeniusamah
- finney ch 2Uploaded byapi-319065418
- Basic Calculus and ApplicationsUploaded bypriyadharshini869728