Você está na página 1de 5

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

R. D. Poshusta Department of Chemistry Washington State University Pullman, WA 99164-4630 poshustr@mail.wsu.edu edited for Mathcad 12 by Theresa Julia Zielinski Monmouth University Department of Chemistry, Medical Technology, and Physics West Long Branch, NJ 07764 tzielins@monmouth.edu

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.

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. The way to use rkfixed for a n-th order ODE is to define n functions so that the single ODE is converted into a system of n first-order differential equations. This may seem unnecessarily complicated but it really makes solution easier by the rkfixed method. For example, if the given ODE is second order: d
2 2

y ( x ) + f( x )

dx

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

Two new functions are defined: y0(x) = y(x), and y1(x)= d y ( x ) and we can write a system of first order equations: dx d y0( x ) = y1( x ), and dx d y1( x ) = h ( x ) g ( x ) y0( x ) f( x ) y1( x ). dx rkfixed works to find solutions for both functions y0 and y1 at the same time. For this, the two functions are placed y0 . in a two-rowed column: y = y1

The Runge-Kutta method achieves a numerical approximation for an ordinary differential equation. Part b. Follow the instructions for ODE in part a to solve the equation for y(t): y' 9 3 Recall the function we will use rkfixed(init, x1, x2, npoints, D) First specify init which is contains the initial value of y and the slope y'. Take y(0) = 1, and y'(0)=0. The RK method uses the values of y'' = 10 y 2

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


differential equation. Set the initial values for y and y' by defining 1 y: 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 as the algorithm steps through a time interval in a finite number of steps: y 1 D(t,y): 10 2 9 y0 3 y1 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 solution may not have an analytical form obtainable through integration. Thus we use the Runga-Kutta method to obtain a numerical solution, one that can be plotted and viewed. To implement the Mathcad Rimga-Kutta algorithm, t wo new d functions are defined: y0(x) = y(x), and y1(x)= y0( x ) where the dx numerical component of the name on the left inidicates the position 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.

y'' =

10 9

2 3

y'

On the right hand side replace y(x) by y0 and y' by y1(x). This puts the differential equation into the correct format for the rkfixed algorithm. Place this new right hand side into the second position in the D array. Finally specify other parameters to pass to the rkfixed function. Choose the number of integration steps (npoints), N, and the initial 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<0> is the column of all t-values in the range of integration, Z<1> is the column of corresponding y-values, and Z <2> contains the first derivatives. [To select column i, press Z<ctrl-^>i] Make a plot of y versus t from Z. To do this, you can first set t:Z <0>, and y:Z <1>. Then let i:0;N and plot yi versus xi. Add the first derivative curve to the plot and verify that when y(x) has a zero slope the y' curve shows that the slope is zero.

Part e. Exercise: Here is a ODE that you can solve using rkfixed. [You will encounter this differential equation when you study the Schroedinger equation for the harmonic oscillator.] 1 2 '' + 1 2 x = .
2

Here is a function of x when x can vary from zero to L. [Here L is the maximum length of oscillation and 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.

Você também pode gostar