Upload
imani-goodman
View
41
Download
0
Embed Size (px)
DESCRIPTION
DERIVATIVES AND DIFFERENTIAL EQUATIONS. June 23,’99. i. +. v. -. WHAT IS A DERIVATIVE?. Derivative of f(x) at x=a is given by f’(a). y=f(x). f(a+h). f(a). a. a+h. SIGNIFICANCE OF DERIVATIVE. In the limit, derivative at x=a is equal to the slope m of the tangent line at a. - PowerPoint PPT Presentation
Citation preview
© 1999BG Mobasseri 1 5/30/99
DERIVATIVESANDDIFFERENTIAL EQUATIONS
June 23,’99
i
i =Cdvdt
v+
-
© 1999BG Mobasseri 2 5/30/99
WHAT IS A DERIVATIVE?
• Derivative of f(x) at x=a is given by f’(a)
a a+h
y=f(x)
f(a)
f(a+h)
′ f a( )=limh→0f a+h( )−f a( )
h
© 1999BG Mobasseri 3 5/30/99
SIGNIFICANCE OF DERIVATIVE
• In the limit, derivative at x=a is equal to the slope m of the tangent line at a.
a a+h
y=f(x)
f(a)
© 1999BG Mobasseri 4 5/30/99
APPLICATIONS OF DERIVATIVE
• The most widely used application of derivative is in finding the extremum (max or min) points of a function.
• If a function has a local extremum at a number c then either f’(c)=0 or f’(c) doesn’t exist
© 1999BG Mobasseri 5 5/30/99
CRITICAL NUMBERS
• A number c in the domain of a function f is a critical number of f if either f’(c)=0 or f’(c) does not exist
x=c
f’(c)=0
© 1999BG Mobasseri 6 5/30/99
DERIVATIVES IN MATLAB:diff
• MATLAB computes two differentials, dy and dx, using diff, to arrive at the derivative
• If x and y are input array of numbersdy=diff( y)dx=diff(x)
• Then, yprime=diff(y)./diff(x)
© 1999BG Mobasseri 7 5/30/99
How diff works
• Take the array y=[3 5 7 5 9];• diff(y) simply is the pairwise
differences, i.e. diff(y)=[5-3 7-5 5-7 9-5]
which is equal todiff(y)=[2 2 -2 4]
• Naturally, there is one fewer term in diff(y) than it is in y
© 1999BG Mobasseri 8 5/30/99
Using diff to find derivatives
• Let y=[10 25 30 50 10] for x=[1 2 3 4 5]
• Thendiff(y)=[15 5 20 -40]diff(x)=[1 1 1 1 1]• Dividing term-by-termyprime=[15 5 20 -40]
One fewer component
© 1999BG Mobasseri 9 5/30/99
WORKING WITH humps
• humps is a built-in MATLAB function, like peaks and is given by
y = 1(x−.3)2 +0.01[ ]
+ 1x−.9( )
2 +.04[ ]−6
© 1999BG Mobasseri 10 5/30/99
HOW IT LOOKS
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10
10
20
30
40
50
60
70
80
90
100
© 1999BG Mobasseri 11 5/30/99
Try it!:derivative of humps
• First, we must know how humps was created in order to know dx
x=0:0.01:1;%dx in this case is 0.01y=humps(x);• Now usedy=diff(y);dx=diff(x);
yprime=dy./dx;
© 1999BG Mobasseri 12 5/30/99
PLOT OF dy/dx
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10
20
40
60
80
100HUMPS
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1000
-500
0
500
1000FIRST DERIVATIVE OF HUMPS
Function peaks
Deriv. goes to 0
© 1999BG Mobasseri 13 5/30/99
Finding critical points:theory vs. application
• To find max. or min.we should look for instances where y’=0.
• This is where the difference between textbook methods and the real world shows up.
• To see for yourself look for instances where yprime=0.
© 1999BG Mobasseri 14 5/30/99
Where are the zeros?
• If you did the search right, you will realize that nowhere in yprime you can actually see a zero
• Since there are no points where y’ is exactly zero, we should look for points of transition from positive to negative, i.e. sign changes
+ +
© 1999BG Mobasseri 15 5/30/99
Zero crossing and sign transition
• In Matlab, all derivatives are discrete. Some are positive, some negative but no zeros
• Since derivative goes from + to -, we can infer that it went to zero somewhere in between
Zero crossing
© 1999BG Mobasseri 16 5/30/99
FINDING ZERO CROSSINGS
• There are two ways to find where a function crosses zero;
1. Numerical2. Algebraic(polynomial fitting)
© 1999BG Mobasseri 17 5/30/99
ZC USING ARRAY OPERATION
• To find where a sign transition takes place, multiply two consecutive numbers in the derivative array. If there is a sign change, the product is negative
[10 15 16 9 -4 -3 -4 -9]X X X X X X X
+ + + - + + -
Zero crossing
© 1999BG Mobasseri 18 5/30/99
MATLAB’s WAY
• Let x be an n element array[x1,x2,…,xn]. To generate the zero crossing array, do
y=x(1:n-1).*x(2:n)• Algebraically, this is what is
happeningy=[x1x2 x2x3 ,..., xn-1xn]
© 1999BG Mobasseri 19 5/30/99
Try it!
• Evaluate humps in the range x=0 to 1 in increments of 0.01
• This gives you a 1x101 array. Find yprime. This is now a 1x100 array
• Find where in this 101 positions sign changes occur
© 1999BG Mobasseri 20 5/30/99
LOCATING SIGN CHANGES
• Just look for instances of negative sign in the zero crossing array
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-800
-600
-400
-200
0
200
400
600
800
1st=0.292nd=0.633rd=0.88
© 1999BG Mobasseri 21 5/30/99
CLOSER LOOK
0.2 0.22 0.24 0.26 0.28 0.3 0.32 0.34 0.36 0.38 0.4-800
-600
-400
-200
0
200
400
600
800
Sign change
© 1999BG Mobasseri 22 5/30/99
SECOND ZC
0.55 0.6 0.65 0.7 0.75-50
-40
-30
-20
-10
0
10
20
30
40
50
© 1999BG Mobasseri 23 5/30/99
THIRD ZC
0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95-50
-40
-30
-20
-10
0
10
20
30
40
50
© 1999BG Mobasseri 24 5/30/99
Differential Equations
i
i =Cdvdt
v+
-
© 1999BG Mobasseri 25 5/30/99
Simplest Diff.Eq
• A first order differential equation is of the form
y ’=dy/dx=g(x,y)• We are looking for a function y
such that its derivative equals g(x,y)
© 1999BG Mobasseri 26 5/30/99
FEW EXAMPLES
• Find y that such thaty ’=3x2
y ‘=yy ‘=(2x)cos2y
• Answers:y=x3
y=exp(x)y=???
© 1999BG Mobasseri 27 5/30/99
SOLVING ODE’s USING MATLAB
• MATLAB solves ordinary DE in two ways: 1):numerical and 2):symbolic
• For numerical solution use[x,y]=ode23(‘function’,a,b,initial
)• See next slide for usage
© 1999BG Mobasseri 28 5/30/99
EXPLAINING ode23
• Here are the elements of [x,y]=ode23(‘function’,a,b,initial
) function - this is g(x,y) in y
’=g(x,y). Must be written as a separate MATLAB function
a - left point of the intervalb - right point of the intervalinitial - initial condition, i.e. y(a)
© 1999BG Mobasseri 29 5/30/99
USING ode23
• Let’s solve y ‘ =3x2
• First write a function as followsfunction yprime=anything(x,y)
yprime=3*x.^2;• Then call
[x,y]=ode23(‘anything’,2,4,0.5)• y is the solution. Plot x vs.y
© 1999BG Mobasseri 30 5/30/99
RC CIRCUIT
• Equation describing a source-free RC circuit is
dvc
dt+ 1
RCvc =0 RC vc
ic
© 1999BG Mobasseri 31 5/30/99
SOLVING FOR VOLTAGE
• The analytical solution is
• where Vo is the initial voltage across the capacitor
vc t( ) =Voe−t RC
© 1999BG Mobasseri 32 5/30/99
MATLAB’s WAY
• To use ode23, we need to cast the problem in the form of y ‘=g(x,y)
• Here, y is vc. . Therefore,
vc’=-(1/RC)vc
• With RC=10^-3, write a function likefunction vcprime=rc(t,vc)
vcprime=-(10^3)*vc
© 1999BG Mobasseri 33 5/30/99
SOLVING FOR vc
• Use ode23 as follows[t,vc]=ode23(’rc’,0,1,2)
© 1999BG Mobasseri 34 5/30/99
CIRCUIT WITH FORCED RESPONSE
• Take the following RL circuit(p.497)
Ldidt+Ri=Vmcosωt
L
Rvs=Vmcosωt~
i
© 1999BG Mobasseri 35 5/30/99
WHAT IS i ?
• From circuits analysis we know
i=VmZcosωt−β( )
whereZ= R2+ω2L2
β=tan−1ωLR
L
Rvs=Vmcosωt~
© 1999BG Mobasseri 36 5/30/99
SOME NUMBERS
• Let R=2 ohm, L=1 H and vs=10cos3t
• Here is what we haveZ=sqrt(9+4)=sqrt(13)Vm=10
β=56.3o
i = 1013
cos3t−56.3( )
© 1999BG Mobasseri 37 5/30/99
EXERCISE- VERIFY WITH MATLAB
• Use ode23 to solve for current. Match the two results, graphically, to see if the amplitude, phase and frequencies match the theoretical result