Sei sulla pagina 1di 3

MathCAD Differential Equation Examples

The first example is directly from the MathCAD Quicksheet:

Solving a First-Order ODE Initial Value Problem

To find this quicksheet, go to MathCAD Help; on the Index tab, type in Differential Equations;
from the list of Topics that come up, select Differential Equation Solvers; in the explanation that
comes us, select the topic Odesolve(x,b,step). The quicksheet link is at the bottom of the page.

The first example is explained in some detail on that Quicksheet. I typed it in here to see if I
could duplicate the example.

1
f( t , y ) := sin( t) +
y

t0 := 0 y0 := 1 t1 := 8 ⋅ π N := 1000

Given
y'( t) = f( t , y ( t) ) y ( t0) = y0

y := Odesolve( t , t1)

10

6
y( t)

0
0 5 10 15 20 25
t
The second example solves two differential equations. We use some of the defined quantities
defined in the first example. I will define them again, so this example stands on its own.

First, we define the initial and final time and the number of time steps.

t0 := 0 t1 := 8 ⋅ π N := 1000

Second, we define the equations. I have selected the well-known differential equation method of
obtaining a sine and cosine wave. y0 is the sine and y1 is the cosine. Here, the differential
equations are

d d
y =y y = −y
dt 0 1 dt 1 0

These must be formatted as follows: (An explanation appears in the rkfixed(y,x1,x2,npts,D) link from
the same help explanation: go to that link and then click on the link explaining the D under
Arguments.)

⎛ y1 ⎞
f( t , y ) := ⎜ ⎟
⎜ −y 0 ⎟
⎝ ⎠

Declare this function to be the set of differential equations that we want to solve.

D( t , Y) := f( t , Y)

Third, enter the initial conditions in sequence...y0, y1.... The value of sine at t=0 is 0 and the value
of cosine at t=0 is 1.

⎛0⎞
ic := ⎜ ⎟
⎝1⎠

Fourth, command MathCAD to solve the differential equations.

S := rkfixed ( ic , t0 , t1 , N , D)
The result comes back as a matrix with the time values in the 0 column, the first variable in the
second column, etc.

0 1 2
880 22.117 -0.125 -0.992
881 22.142 -0.15 -0.989
882 22.167 -0.175 -0.985
883 22.192 -0.2 -0.98
884 22.217 -0.224 -0.975
885 22.242 -0.249 -0.969
886 22.268 -0.273 -0.962
S = 887 22.293 -0.297 -0.955
888 22.318 -0.321 -0.947
889 22.343 -0.345 -0.939
890 22.368 -0.368 -0.93
891 22.393 -0.391 -0.92
892 22.418 -0.414 -0.91
893 22.444 -0.437 -0.899
894 22.469 -0.46 -0.888
895 22.494 -0.482 -0.876

Extract what is to be plotted or used:

〈0〉
t := S

〈1〉
a := S
〈2〉
b := S

0.5

a
0
b

0.5

1
0 5 10 15 20 25
t

Potrebbero piacerti anche