Using Mathcad To Solve Systems of Differential Equations PDF
Using Mathcad To Solve Systems of Differential Equations PDF
Charles Nippert
Getting Started
Consider the system of differential equations and initial value conditions shown below
y' '1 = y1 − 3y 2
y 2 = y1 '+ y' 2
y1 (0) = 2
y'1 (0 ) = 1
y 2 (0 ) = 3
To generate a solution, define a new variable y3 = y1’ and rearrange to obtain the
following system.’
y'1 = y 3
y' 2 = y 2 − y 3
y' 3 = y 1 − 3y 2
y1 (0) = 2
y 2 (0 ) = 3
y 3 (0) = 1
In the sample on these notes you will obtain a numerical solution for the following
system of differential equations. You will the use the solution to make both a
conventional parametric plot and a plot of the phase plane.
y'1 = y 2
y' 2 = y1
y1 (0) = 1
y 2 (0) = 2
1. Open Mathcad in the usual fashion and move the cursor about 1 inch below the
menu slightly to the right. If the matrix toolbar is not visible open it by choosing
"View/Toolbars/Matrix". The initial values are entered as a vector. You can give
the vector any name you wish. In this example enter the name space "y0". Press
the ":" key to generate the arithmetic assignment symbol ":=". Use the mouse
cursor to press the matrix logo on the matrix toolbar, . On my toolbar it is the
first button on the first row. The "Insert Matrix" dialog box immediately appears.
The initial conditions are entered as a vector with one column and two rows.
When you are finished the dialog box should look like figure 1.
Figure 1
Insert Matrix Dialog Box
2. Press the "OK" button. The dialog box should immediately close and a column
vector with two elements should immediately appear. The blue inverted L. cursor
should be on the upper black rectangle or placeholder in the matrix. Type "1" to
enter the first boundary condition. You can use the arrow keys on the keyboard to
move between the elements on a matrix. Press the down arrow key to move to the
next element and enter its value, "2". The finished vector should look like figure
2.
Figure 2
Initial Condition Vector
6. You can see the numerical results of the integration by displaying the contents of
the matrix "yn". Press enter and move the red cross cursor far down and to the
right of the rest of your equation. Next, type "yn=". A table showing a portion of
the results will appear. Clicking on any portion of the table will cause that portion
to be highlighted and will cause a scrollbar to appear to the right of the table. Use
this scrollbar to make the rest of the table visible. This table is shown in figure 6.
Figure 6
Table Showing Partial Results Of Numerical Integration
8. Create two more arrays, y1 and y2 that contain the values from the first and
second columns of the yn matrix. This portion of your worksheet should now
look like figure eight.
Figure 8
Defining the Vectors From the yn Matrix
t := yn<0>
y1 := yn<1>
y2 := yn<2>
9. You will now make a plot of y0 and y1 versus the independent variable, t. Move
the red cross cursor to a vacant area of your worksheet. You can create a x-y plot
in any of the following ways:
1. Press the "@"
2. Select "Insert/Graph/X-Y Plot" from the menu.
This plot will be y1 and y2 versus t. Enter "t" as the name of the variable on the
horizontal axis. Keep pressing the left arrow key until the blue inverted L. cursor
surrounds the leftmost solid black rectangle that is the placeholder for the vertical
axis. When plotting more than one line on a X-Y axis, you enter the names of the
arrays separated by a coma. Type the characters "y1,y2" and press "Enter". The
graph should immediately appear. Double-click on the graph to call up the
formatting dialog box. Your worksheet should now resemble figure 9.
Figure 9
The Solution To This System of Differential Equations
10. You can now format this graph. First, check the "Grade to Lines" box for both
the x-axis and y-axis. The analytical solution of these differential equations
includes exponential terms check the "Log Scale" option for the y-axis. Press
"OK". The dialog box should immediately close and the graph will show grid
lines and the y-axis will become a logarithmic axis. Use the mouse to grab the
solid black rectangular "handle" in the lower right corner and enlarge and the
graph. Now your figure should resemble figure 10.
Figure 10
Finished Plots of y1 & y2 versus t
11. A phase plot is a plot of the dependent variables plotted against each other. The
independent variable is not shown. You will not make a phase plot for this
system. Click on a portion of the worksheet that is below your solution but still
empty and create a new graph. This time label the horizontal axis "y1" and label
the vertical axis "y2". Double-click on the graph to open the format dialog box
and check "Grid Lines" for both axes. Press the "OK" button and then enlarge the
graph. Your face plot should resemble figure 11.
Figure 11
Finished Phase Plot