Calculus Review Slope Slope riserun DyDx y 2

  • Slides: 35
Download presentation
Calculus Review

Calculus Review

Slope • Slope = rise/run • = Dy/Dx • = (y 2 – y

Slope • Slope = rise/run • = Dy/Dx • = (y 2 – y 1)/(x 2 – x 1) • Order of points 1 and 2 not critical, but keeping them together is • Points may lie in any quadrant: slope will work out • Leibniz notation for derivative based on Dy/Dx; the derivative is written dy/dx

Exponents • x 0 = 1

Exponents • x 0 = 1

Derivative of a line • • • y = mx + b slope m

Derivative of a line • • • y = mx + b slope m and y axis intercept b derivative of y = axn + b with respect to x: dy/dx = a n x(n-1) Because b is a constant -- think of it as bx 0 -- its derivative is 0 bx-1 = 0 • For a straight line, a = m and n = 1 so • dy/dx = m 1 x(0), or because x 0 = 1, • dy/dx = m

Derivative of a polynomial • In differential Calculus, we consider the slopes of curves

Derivative of a polynomial • In differential Calculus, we consider the slopes of curves rather than straight lines • For polynomial y = axn + bxp + cxq + … • derivative with respect to x is • dy/dx = a n x(n-1) + b p x(p-1) + c q x(q-1) + …

Example y = axn + bxp + cxq + … dy/dx = a n

Example y = axn + bxp + cxq + … dy/dx = a n x(n-1) + b p x(p-1) + c q x(q-1) + …

Numerical Derivatives • slope between points

Numerical Derivatives • slope between points

Derivative of Sine and Cosine • • sin(0) = 0 period of both sine

Derivative of Sine and Cosine • • sin(0) = 0 period of both sine and cosine is 2 p d(sin(x))/dx = cos(x) d(cos(x))/dx = -sin(x)

Partial Derivatives • Functions of more than one variable • Example: C(x, y) =

Partial Derivatives • Functions of more than one variable • Example: C(x, y) = x 4 + y 3 + xy

Partial Derivatives • Partial derivative of h with respect to x at a y

Partial Derivatives • Partial derivative of h with respect to x at a y location y 0 • Notation h/ x|y=y 0 • Treat ys as constants • If these constants stand alone, they drop out of the result • If they are in multiplicative terms involving x, they are retained as constants

Partial Derivatives • Example: • C(x, y) = x 4 + y 3 +

Partial Derivatives • Example: • C(x, y) = x 4 + y 3 + xy • C/ x|y=y 0 = 4 x 3 + y 0

WHY?

WHY?

Gradients • del h (or grad h) • Flow (Darcy’s Law):

Gradients • del h (or grad h) • Flow (Darcy’s Law):

Gradients • del C (or grad C) • Diffusion (Fick’s 1 st Law):

Gradients • del C (or grad C) • Diffusion (Fick’s 1 st Law):

Basic MATLAB/Python

Basic MATLAB/Python

Matlab/Python • • Programming environment Post-processer Graphics Analytical solution comparisons • Use File/Preferences/Font to

Matlab/Python • • Programming environment Post-processer Graphics Analytical solution comparisons • Use File/Preferences/Font to adjust interface font size

Vectors/Lists and tuples >> a=[1 2 3 4] a= 1 >> a' ans =

Vectors/Lists and tuples >> a=[1 2 3 4] a= 1 >> a' ans = 1 2 3 4

Autofilling and addressing Vectors > a=[1: 0. 2: 3]' a= 1. 0000 1. 2000

Autofilling and addressing Vectors > a=[1: 0. 2: 3]' a= 1. 0000 1. 2000 1. 4000 1. 6000 1. 8000 2. 0000 2. 2000 2. 4000 2. 6000 2. 8000 3. 0000 >> a(2: 3) ans = 1. 2000 1. 4000

xy Plots >> x=[1 3 6 8 10]; >> y=[0 2 1 3 1];

xy Plots >> x=[1 3 6 8 10]; >> y=[0 2 1 3 1]; >> plot(x, y)

Matrices >> b=[1 2 3 4; 5 6 7 8] b= 1 5 2

Matrices >> b=[1 2 3 4; 5 6 7 8] b= 1 5 2 6 >> b' ans = 1 2 3 4 5 6 7 8 3 7 4 8

Matrices >> b=2. 2*ones(4, 4) b= 2. 2000 2. 2000

Matrices >> b=2. 2*ones(4, 4) b= 2. 2000 2. 2000

Reshape >> a=[1: 9] a= 1 2 3 4 5 6 >> bsquare=reshape(a, 3,

Reshape >> a=[1: 9] a= 1 2 3 4 5 6 >> bsquare=reshape(a, 3, 3) bsquare = 1 2 3 >> 4 5 6 7 8 9

Load • a = load(‘filename’); (semicolon suppresses echo) a=np. loadtxt('book 3. csv', delimiter=', ')

Load • a = load(‘filename’); (semicolon suppresses echo) a=np. loadtxt('book 3. csv', delimiter=', ')

If • if(1) … else … end

If • if(1) … else … end

For • for i = 1: 10 • … • end

For • for i = 1: 10 • … • end

BMP Output bsq=rand(100, 100); %bmp 1 output e(: , 1)=1 -bsq; %r e(: ,

BMP Output bsq=rand(100, 100); %bmp 1 output e(: , 1)=1 -bsq; %r e(: , 2)=1 -bsq; %g e(: , 3)=ones(100, 100); %b imwrite(e, 'junk. bmp', 'bmp'); image(imread('junk. bmp')) axis('equal')

Quiver (vector plots) >> scale=10; >> d=rand(100, 4); >> quiver(d(: , 1), d(: ,

Quiver (vector plots) >> scale=10; >> d=rand(100, 4); >> quiver(d(: , 1), d(: , 2), d(: , 3), d(: , 4), scale)

Contours • h=[…]; • Contour(h) • Or Contour(x, y, h)

Contours • h=[…]; • Contour(h) • Or Contour(x, y, h)

Contours w/labels • C=[…]; • [c, d]=contour(C); • clabel(c, d), colorbar

Contours w/labels • C=[…]; • [c, d]=contour(C); • clabel(c, d), colorbar

Numerical Partial Derivatives • slope between points • MATLAB – h=[]; (order assumed to

Numerical Partial Derivatives • slope between points • MATLAB – h=[]; (order assumed to be low y on top to high y on bottom!) – [dhdx, dhdy]=gradient(h, spacing) – contour(x, y, h) – hold – quiver(x, y, -dhdx, -dhdy)

Gradient Function and Streamlines • [dhdx, dhdy]=gradient(h); • [Stream]= stream 2(X, Y, U, V,

Gradient Function and Streamlines • [dhdx, dhdy]=gradient(h); • [Stream]= stream 2(X, Y, U, V, STARTX, STARTY); • [Stream]= stream 2(-dhdx, dhdy, [51: 100], 50*ones(50, 1)); • streamline(Stream) • (This is for streamlines starting at y = 50 from x = 51 to 100 along the x axis. Different geometries will require different starting points. )

Stagnation Points

Stagnation Points

Integral Calculus

Integral Calculus

Integral Calculus: Special Case

Integral Calculus: Special Case

Integral Calculus: Special Case

Integral Calculus: Special Case