diffequ_12

Upload: sameoldhat

Post on 04-Apr-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 diffequ_12

    1/5

    Problem Solving Skills in Physical Chemistry:Tutorial for using Mathcad for Solving Differential Equations.

    R. D. PoshustaDepartment of Chemistry

    Washington State University

    Pullman, WA 99164-4630

    [email protected]

    edited for Mathcad 12 by

    Theresa Julia Zielinski

    Monmouth University

    Department of Chemistry, Medical Technology, and Physics

    West Long Branch, NJ 07764

    [email protected]

    Copyright Ron D. Poshusta and Theresa Julia Zielinski, 2006. All rights reserved. You are

    welcome to use this document in your own classes but commercial use is not allowed without the

    permission of the author.

    You should drag and stretch/shrink mathcad windows

    to see this worksheet and help screens at the same

    time. First, make this mathcad window about half the

    width of your monitor display and position it on the

    left side of the screen.

    Part a. Mathcad has internal help files for many topics.

    Pull down the Help/Mathcad Help and choose Index

    .

    [Shrink the help window to half width and position it on

    the right.]

    Then, in the box, type differential equations and then

    click on display.

    A list of topics will be shown. Click on differential

    equations solvers and then on rkfixed etc.

    Click on the type of d.e. you need to solve for more

    instructions.

    For this exercise click on

    ordinary differential equations .

    These are the instructions to use the built-in function

    rkfixed for solving differential equations.

  • 7/30/2019 diffequ_12

    2/5

    PRINT the help sheet for O.D.E.. Keep this printout for

    easy reference. You may also want to print out the

    Quicksheets found on the page. The First-OrderSystem

    of ODEs quicksheet is especially applicable. It will give

    you an additional example for using the rkfixed function.

    The form for the rkfixed is

    rkfixed(init, x1, x2, npoints, D)

    Check the print copy to learn what each component of

    the function is.

    At this point you can restore the mathcad screen to full

    size. Click on the down-size button when you want to

    toggle back to half-screen size.

    Work the following exercises.

    (Part b) You are going to use the rkfixed function. Theway to use rkfixed for a n-th order ODE is to define nfunctions so that the single ODE is converted into asystem of n first-order differential equations.This may seem unnecessarily complicated but it reallymakes solution easier by the rkfixed method.

    For example, if the given ODE is second order:

    2x

    y x( )d

    d

    2

    f x( )

    x

    y x( )d

    d

    + g x( ) y x( )+ h x( ) 0=

    Two new functions are defined: y0(x) = y(x), and y1(x)=

    xy x( )

    d

    dand we can write a system of first order equations:

    xy0 x( )

    d

    dy1 x( )= , and

    xy1 x( )

    d

    dh x( ) g x( ) y0 x( ) f x( ) y1 x( )= .

    rkfixed works to find solutions for both functions y0 andy1 at the same time. For this, the two functions are placed

    in a two-rowed column: yy0

    y1

    = .

  • 7/30/2019 diffequ_12

    3/5

    The Runge-Kutta method achieves a numerical approximation foran ordinary differential equation.

    Part b. Follow the instructions for ODE in part a to solve the

    equation for y(t):

    y''10

    9 y

    2

    3y'=

    Recall the function we will use rkfixed(init, x1, x2, npoints, D)

    First specify init which is contains the initial value of y and theslope y'. Take y(0) = 1, and y'(0)=0. The RK method uses thevalues of

    y t( )

    y' t( )

    at successive values of x to compute y''(t) via the

    differential equation.

    Set the initial values for y and y' by defining

    y:1

    0

    You then have to define the D array, which contains y(t) and y'(t),in order to compute both the first and second derivative values asthe algorithm steps through a time interval in a finite number ofsteps:

    D(t,y):

    y1

    10

    9 y

    0

    2

    3y

    1

    Note well how the D array is formed.

    First it is important to recognize that there is some function y(x)that is a solution to the differential equation. However, this solutionmay not have an analytical form obtainable through integration.Thus we use the Runga-Kutta method to obtain a numericalsolution, one that can be plotted and viewed.

    To implement the Mathcad Rimga-Kutta algorithm, two new

    functions are defined: y0(x) = y(x), and y1(x)=x

    y0 x( )d

    dwhere the

    numerical component of the name on the left inidicates theposition in the D array.

    For this example the zero position in the D array is simply y(x)called y1 in the D array. The second position in the D array is the

    first derivative of y0(x) (that is the first derivative of y(x).

    Take the original differential equation and examine it.

  • 7/30/2019 diffequ_12

    4/5

    y''10

    9 y

    2

    3y'=

    On the right hand side replace y(x) by y0 and y' by y1(x). This putsthe differential equation into the correct format for the rkfixed

    algorithm. Place this new right hand side into the second positionin the D array.

    Finally specify other parameters to pass to the rkfixed function.Choose the number of integration steps (npoints), N, and theinitial and final values of t(x1 and x2). In our example let us use,

    N:1000 and t0:0, t1:12

    Finally, invoke the rkfixed function to find the solution:Z:rkfixed(y,t0,t1,N,D)

    Part d. The solution for part (c) is contained in the

    array Z.

    rkfixed returns a matrix in which the first column

    contains the list of points at which the solution is

    evaluated and the remaining columns contain the

    corresponding numerical values of the solution and

    the values of the first n-1 dervatives of the solution

    in increasing order.

    In our problem, Z is the column of all t-values in

    the range of integration, Z is the column of

    corresponding y-values, and Z contains the first

    derivatives. [To select column i, press Zi]

    Make a plot of y versus t from Z. To do this, you

    can first set t:Z, and y:Z. Then let i:0;N and

    plot yi versus xi. Add the first derivative curve to theplot and verify that when y(x) has a zero slope the

    y' curve shows that the slope is zero.

  • 7/30/2019 diffequ_12

    5/5

    Part e. Exercise: Here is a ODE that you can solveusing rkfixed. [You will encounter this differentialequation when you study the Schroedingerequation for the harmonic oscillator.]

    1

    2''

    1

    2x

    2 + = .

    Here is a function of x when x can vary from zeroto L. [Here L is the maximum length of oscillationand is rigorously infinite, but you may take it as 5.]Find and plot solutions, (x), when

    =1/2 and when

    =5/2.

    In both cases take y(0) = 1 and y'(0) = 0.

    Print your solution(s) and submit for grading if

    directed to do so by yur instructor.