calculus

32
Calculus S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan- Dearborn Math Review with Matlab: Differentiation

Upload: kendall

Post on 14-Feb-2016

23 views

Category:

Documents


0 download

DESCRIPTION

Math Review with Matlab:. Calculus. Differentiation. S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan-Dearborn. Differentiation. General Derivatives Diff Command Differentiation Example Product Rule Example Chain Rule Example Partial Differentiation - PowerPoint PPT Presentation

TRANSCRIPT

  • CalculusS. Awad, Ph.D.M. Corless, M.S.E.E.E.C.E. DepartmentUniversity of Michigan-DearbornMath Review with Matlab:Differentiation

    Calculus:Differentiation

    DifferentiationGeneral DerivativesDiff CommandDifferentiation ExampleProduct Rule ExampleChain Rule ExamplePartial DifferentiationPartial Derivative ExampleTotal Difference ApproximationSensitivity Analysis Example

    Calculus:Differentiation

    General DerivativesIn general, derivatives are used to determine how quickly or slowly a function varies with respect to a changing variableFor a two dimensional continuous curve, the derivative can be thought of as representing the instantaneous slope of the curve with respect to the changing variableThe derivative operation is a limiting process defined as:

    Calculus:Differentiation

    Differential PairsA few common differential pairs are shown belowNote that a is a constant

    Calculus:Differentiation

    Higher Order DerivativesHigher order derivatives can also be definedThe second derivative of a function f(x) is defined as:The nth derivative of a function f(x) is defined as:

    Calculus:Differentiation

    Diff CommandThe diff command can be used to differentiate symbolic variablesdiff(s) differentiates s with respect to the Matlab default free variablediff(s,v) differentiates s with respect to the free variable vdiff(s,v,n) differentiates s n times with respect to the free variable v (n must be positive)

    Calculus:Differentiation

    Differentiation ExampleGiven the sinusoidal function f(x):1)Use Matlab to determine the first derivative of f(x)3)Use Matlab to determine the second, third, and fourth derivatives of f(x)2)Plot f(x) and its first derivative to verify that the first derivative of f(x) corresponds to the scaled instantaneous slope of f(x)

    Calculus:Differentiation

    First DerivativeUse the diff command to determine the first derivative thus verifying the differential pair: syms x f=sin(2*x);

    dfdx=diff(f) dfdx = 2*cos(2*x)

    Calculus:Differentiation

    Slope AnalogyPlot f(x)=sin(2x) and its df/dx=2cos(2x) subplot(2,1,1) ezplot(f) subplot(2,1,1) ezplot(f,0,pi) grid on subplot(2,1,2) ezplot(dfdx,0,pi) grid onShow relationship between slope of f(x) and the derivative

    Calculus:Differentiation

    Second DerivativeCalculate second derivative from the first derivative d2fdx2=diff(dfdx)d2fdx2 =-4*sin(2*x)

    Calculate second derivative f(x) by passing 2 as the number of times to differentiate Both methods give the same result! d2fdx2=diff(f,2)d2fdx2 =-4*sin(2*x)

    Calculus:Differentiation

    Higher Order DifferentiationCalculate the third and fourth derivatives

    d3fdx3=diff(f,3)d3fdx3 =-8*cos(2*x)

    d4fdx4=diff(f,4)d4fdx4 =16*sin(2*x)

    Calculus:Differentiation

    Product RuleThe Product Rule is used to differentiate products of functions of the same variable and is defined as:The Product Rule can be expressed in shorthand notation as:

    Calculus:Differentiation

    Product Rule ExampleUse Matlab to verify the Product Rule1)Create two arbitrary functions u(x) and v(x) both dependent on x2)Let f(x)=u(x)v(x)3)Use Matlab to differentiate f(x) and verify that:

    Calculus:Differentiation

    Product Rule VerificationDefine u and v as functions of x syms x u=sym('u(x)'); v=sym('v(x)');

    Create f as the product of u and v Differentiate f and verify the Product Rule f=u*vf =u(x)*v(x) dfdx=diff(f,x); pretty(dfdx) /d \ /d \ |-- u(x)| v(x) + u(x) |-- v(x)| \dx / \dx /

    Calculus:Differentiation

    Chain Rule Example2)Differentiate f(x) with respect to xThe Chain Rule is used to differentiate a function of a function and is defined as:3)Use Matlab to verify the result1)Given f(x) where a and b are constants:

    Calculus:Differentiation

    Perform Chain RuleBreak into sections and differentiateUse the chain rule to differentiate f(x)

    Calculus:Differentiation

    Verify Chain Rule ResultThe result is easily verified in Matlab syms a b x f=(a+b*x^3)^2; dfdx=diff(f) dfdx = 6*(a+b*x^3)*b*x^2

    Calculus:Differentiation

    Partial DifferentiationUsed to determine the rate of changes for functions of multiple changing variablesTo signify that a derivative is with respect to one variable that another variable exists use the notations:First Partial Derivative of f(x,y) with respect to x:(y held constant)First Partial Derivative of f(x,y) with respect to y:(x held constant)Consider a function f(x,y) which is dependent on two variables x and y

    Calculus:Differentiation

    Second Partial DerivativesSecond partial derivatives of f(x,y) can be defined as:Provided that the second partial derivatives are continuous at the point of question, the following relationship holds true:

    Calculus:Differentiation

    Partial Derivative ExampleGiven the function:Use Matlab to determine:1) The first partial derivatives:2) The second partial derivatives:3) Verify the relationship:

    Calculus:Differentiation

    First DerivativesThe standard diff command is used to determine the first partial derivatives in Matlab syms x y; f=2*x^3*y^2 + y^3;

    dfdy = diff(f,'y') dfdy =4*x^3*y+3*y^2 dfdx = diff(f) dfdx =6*x^2*y^2

    Calculus:Differentiation

    Second DerivativesThe second derivatives with respect to the same variable can be found by instructing setting the n parameter to 2 d2fdx2 = diff(f,2)d2fdx2 =12*x*y^2

    d2fdx2 = diff(f,'y',2)d2fdx2 =4*x^3+6*y

    Calculus:Differentiation

    Second DerivativesThe second derivatives with respect to different variables must be calculated from the first derivatives d2fdxy = diff( dfdy, 'x')

    d2fdxy =12*x^2*y d2fdyx = diff( dfdx, 'y')

    d2fdyx =12*x^2*y

    Verified!

    Calculus:Differentiation

    Total Difference ApproximationGiven a function f(x,y) dependent upon the two variables x and ySuppose that small changes Dx in x and Dy in y occur simultaneouslyAs a result, f changes to f + Df which can be approximated as:

    Calculus:Differentiation

    Sensitivity AnalysisThe total difference approximation can be extended to a function of N variables where:A common application of sensitivity analysis is to examine the change in a digital filters frequency response and stability due to coefficient quantizationThe total difference approximation can be used to perform sensitivity analysis of analog and digital systems

    Calculus:Differentiation

    Sensitivity Analysis ExampleGiven a circuit with a resistance R=1kW and initial current I=100mA flowing through it:1)Approximate the total change in power if :Current may increase by 2%Resistance may increase by 5%2)Calculate the approximate new power and actual new power when both I and R change by the above percentsThe power, P, in Watts, absorbed by the resistor can be calculated using the equation:

    Calculus:Differentiation

    Sensitivity EquationsCreate symbolic expressions to determine the approximate change in power given known changes in resistance, R, and current, I. syms I R Idelta Rdelta P=I^2*R;

    dPdI=diff(P,'I')dPdI =2*I*R dPdR=diff(P,'R')dPdR =I^2 Pdelta = Rdelta*dPdR + Idelta*dPdIPdelta =Rdelta*I^2+2*Idelta*I*R

    Calculus:Differentiation

    Determine Initial PowerCreate symbolic variables to represent the desired conditions to analyzeDescribe DR and DI in terms of percent changes I1 = sym(0.1);% I=100mA R1 = sym(1000);% R=1k Ohms Idelta1 = sym(0.02*I1);% I changes 2% Rdelta1 = sym(0.05*R1);% R changes 5%

    P1_sym = subs(P,{'R','I'},{'R1','I1'})P1_sym =I1^2*R1 P1initial= double(eval(P1_sym))P1initial =10

    Calculus:Differentiation

    Sensitivity ApproximationSubstitute the desired parameters into the general symbolic expressions to determine approximate DP P1delta_sym = subs(Pdelta,... {'R','I','Rdelta','Idelta'},... {'R1','I1','Rdelta1','Idelta1'}) P1delta_sym =Rdelta1*I1^2+2*Idelta1*I1*R1 P1delta_approx = double(eval(P1delta_sym))P1delta_approx = 0.9

    Calculus:Differentiation

    New Power CalculationsEvaluate approximated new total powerCalculate the actual new power P1final_approx = double(eval(P1_sym+P1delta_sym))P1final_approx = 10.9000 P1final_sym = subs(P,{'R','I'},...{'(R1+Rdelta1)','(I1+Idelta1)'})P1final_sym =(I1+Idelta1)^2*(R1+Rdelta1) P1final_act = double(eval(P1final_sym))P1final_act = 10.9242

    Calculus:Differentiation

    Compare ResultsNotice that the approximated power and actual new power are very closeAlthough this is a simplistic example, it demonstrates how the total difference approximation can be used to predict the response of more complicated systems without performing complex simulationsThe smaller the values of DR and DI are, the more accurate that DP will be

    Calculus:Differentiation

    SummaryDifferentiation is used to determine the rate at which a function changes with respect to a changing variableThe symbolic diff command can be used to differentiate functions. The user can specify the variable to differentiate with respect to and the number of times to differentiate Partial differentiation is used to determine the rate of changes for functions of multiple changing variablesTotal difference approximation and sensitivity analysis are used to approximate changes in a function based partial derivatives and on fixed changes in variables