Anda di halaman 1dari 190

ByrgeBirkeland

Calculusand
Algebrawith
Mathcad2000
Studentlitteratur
MathcadisaregistreredtrademarkofMathSoftInc.
InSwedenMathcadisdistributedbyRavenholmComputingAB
Email:info@ravenholm.se
Copyingprohibited
Allrightsreserved.Nopartofthispublicationmaybereproducedortransmitted
inanyformorbyanymeans,electronicormechanical,includingphotocopying,
recording,oranyinformationstorageandretrievalsystem,withoutpermissionin
writingfromthepublisher.
Art.No.7193
ISBN91-44-01356-6
eISBN91-44-03290-0
ByrgeBirkelandandStudentlitteratur2000
PrintedinSweden
Studentlitteratur,Lund
Webaddress:www.studentlitteratur.se
Printing/year 1 2 3 4 5 6 7 8 9 10 04 03 02 01 2000
Tableofcontents
Preface9
1 Fundamentals11
1.1 Elementaryoperations11
1.2 Handlingfiles15
1.2.1 Savingyourwork15
1.2.2 Startinganewfile15
1.2.3 Openinganexistingfile16
1.2.4 Closingafile16
1.2.5 Printingafile16
1.3 Symbolicversusnumericalcalculations17
1.3.1 NumericalandsymbolicMathcad17
1.3.2 Forcingsymboliccalculations17
1.4 Mathcad'sbuilt-infunctions19
1.5 Variables20
1.5.1 Definingavariable20
1.5.2 Variablenames21
1.5.3 Rangevariables22
1.5.4 Usingdimensions23
1.6 Arrays25
1.6.1 Defininganarraywith[Ctrl]M25
1.6.2 Accessingtheelementsofanarray26
1.6.3 Thenthcolumnvectorofamatrix26
1.6.4 Defininganarraybymeansofaformula27
1.6.5 Thefirstindexofanarray28
1.6.6 Thenumberofrowsandcolumns28
1.6.7 Arrayoperations28
1.6.8 Nestedarrays30
1.6.9 Definingbiggerarrays30
1.7 Functions32
1.7.1 Definingyourownfunctions32
1.7.2 Drawingthegraphofafunction33
3
1.7.3 Drawingaparametercurve36
1.7.4 Drawingapolarcurve36
1.7.5 Functionsasargumentstoanewfunction38
1.8 UsingMathcad'sprogramminglanguage40
1.8.1 Anexample:Thetrapezoidalrule40
1.8.2 UsingMathcad'sprogramminglanguage40
1.9 Numbers46
1.9.1 Functionsfornumbertheoryandcombinatorics46
1.9.2 Functionsforroundingandtruncations46
1.9.3 Primenumbers47
1.9.4 Numbersinvariousbases49
1.10 Sumsandproducts50
1.10.1 Thesummationsymbol50
1.10.2 Theproductsymbol51
1.11 Threedimensionalplots52
1.11.1 Thegraphofafunctionoftwovariables52
1.11.2 Contourplotsand3Dbarcharts53
1.11.3 Parametersurfaces54
1.11.4 Spacecurves57
1.11.5 Drawingseveralthreedimensionalobjects58
1.12 Text60
1.12.1 Textblocks60
1.12.2 Textvariables62
1.12.3 Textontwodimensionalgraphs63
1.13 Animation65
2 Algebra67
2.1 Toolsforsymbolicalgebra67
2.2 Algebraicexpressions68
2.2.1 Evaluatinganexpression68
2.2.2 Simplifyinganexpression69
2.2.3 Expandinganexpression70
2.2.4 Factoringanexpression71
2.2.5 Collectingonasubexpression72
2.2.6 Partialfractions73
4
2.2.7 Substitutinganexpressioninanotherexpression74
2.2.8 Gettingafloatingpointvalue76
2.2.9 Polynomialcoefficients76
2.3 Equations77
2.3.1 Solvinganequationwithoneunknownnumerically77
2.3.2 Solvinganequationwithoneunknownsymbolically78
2.3.3 Polynomialequationssolvednumerically79
2.3.4 Severalequationswithseveralunknownsolved
numerically79
2.3.5 Linearequations80
2.3.6 Severalsimultaneousequationssolvedsymbolically81
3 Calculus84
3.1 Limits83
3.2 Differentiation83
3.2.1 Thederivativeasalimit83
3.2.2 Mathcad'sbuilt-indifferentiationoperator84
3.2.3 Higherorderderivatives85
3.2.4 Differentialformulae85
3.2.5 Differentiationofimplicitfunctions86
3.2.6 Tangentandnormal87
3.2.7 Curvatureandevolute89
3.2.8 Envelopeofafamilyofcurves93
3.2.9 Extremaoffunctions94
3.2.10 Partialderivatives96
3.2.11 Series96
3.2.12 Extremaoffunctionsoftwovariables97
3.2.13 Extremaoffunctionswiththreeormorevariables99
3.2.14 Extremawithsideconditions101
3.2.15 Linearoptimization103
3.3 Integration104
3.3.1 Indefiniteintegrals104
3.3.2 Definiteintegrals106
3.3.3 Improperintegrals108
3.3.4 Planeareas109
3.3.5 Curvelength112
3.3.6 Centroidsandmomentsofinertia114
3.3.7 Thevolumeofasurfaceofrevolution116
5
3.3.8 Surfaceareaofasurfaceofrevolution119
3.3.9 Doubleintegrals121
3.4 Vectorcalculus122
3.4.1 VectorsinRn122
3.4.2 Vectorvaluedfunctions123
3.4.3 Differentialgeometryofspacecurves125
3.4.4 Vectorfieldsandscalarfields127
3.4.5 Lineintegrals128
3.4.6 Surfaceintegrals130
3.4.7 Surfaceareas132
3.4.8 Tripleintegrals132
4 Differentialequations135
4.1 Differentialequationsoforderone135
4.1.1 Indefiniteintegralsy'=f(x)135
4.1.2 Separableequationsf(y)dy=g(x)dx135
4.1.3 Linearequationsy'+f(x)y=g(x)136
4.1.4 Linearequationsy'-ay=g(x),whereaisaconstant136
4.1.5 Bernoulli'sequation137
4.1.6 Totaldifferentials137
4.2 Differentialequationsorordertwoorhigher138
4.2.1 Homogeneousequationswithconstantcoefficients138
4.2.2 Inhomogeneousequationswithconstantcoefficients139
4.2.3 Solutionbypowerseriesexpansion142
4.3 Laplacetransforms144
4.3.1 Thebuilt-inLaplacetransform144
4.3.2 Applicationtoinitialvalueproblems144
4.4 Differenceequations146
4.4.1 Themethodofundeterminedcoefficients146
4.4.2 Theztransform147
4.5 Fourierseries149
4.5.1 FouriercoefficientsandFourierseries149
4.5.2 Stepfunctions150
4.5.3 Fouriertransforms151
4.5.4 Fouriertransformsandtheheatequation152
4.5.5 DiscreteFouriertransforms153
6
4.6 Numericalsolutionofdifferentialequations155
4.6.1 Drawingatwodimensionalvectorfield155
4.6.2 Drawingafamilyofintegralcurves158
4.6.3 Runge-Kutta'sfourthordermethodrkfixed 159
4.6.4 Drawingafamilyofnumericallycomputedintegralcurves
161
4.6.5 ODEsofordertwoorhigher163
4.6.6 Phasediagramforadampedpendulum165
4.6.7 Otherdifferentialequationsolvers165
4.6.8 Aboundaryvalueproble:Ballistics169
5 LinearAlgebra173
5.1 ElementaryrowoperationsandGausselimination173
5.1.1 Elementaryrowoperations173
5.1.2 NaivGausselimination175
5.1.3 Gausseliminationwithpivoting175
5.2 Rankandsubspaces177
5.2.1 Therankofamatrix177
5.2.2 Thespacespannedbythecolumn/rowvectorsofamatrix
178
5.2.3 Basisforthenullspaceofamatrix178
5.2.4 Gram-Schmidt'sorthonormalizationprocess181
5.2.5 Completiontoafullbase182
5.3 Eigenvaluesandquadraticforms182
Index187
7
Preface
This book is intended to help students and teachers who want to use Mathcad
as their computer tool in mathematics courses at first year college level. It
contains the standard topics usually included: Calculus, vector calculus,
differential equations and linear algebra, and in addition chapters on the
fundamentals of Mathcad and elementary algebra.
I have used Mathcad Professional version 2000.
I have made no attempt to include the mathematical theory in the book. I
presume that the theory is known from some standard textbook, and my
emphasis has been to show how the various topics can be implemented with
Mathcad. I have included a few exercises after most of the sections, but you
may as well take your mathematics textbook and do the exercises you find
there with the methods I describe in the book. For many topics, I have written
my own functions that you may want to apply. You can find them on the WEB
at the address www.studentlitteratur.se/7193. At this address, you can also
find suggestions for solutions to some of the exercises. The definitions are in
files with names of the form Dx_y.mcd for section x.y, and they are placed in
a collapsed area. The suggested solution for exercise u in subsection x.y.z is in
the file Xx_y_z_u.mcd. To use the definitions you can either use Insert -
Reference and refer to the relevant file, or you can open the definition file and
copy the definitions into your file.
I would be interested to receive suggestions and remarks from the readers. My
address is:
Byrge Birkeland
Agder College,
Department of Mathematics and Sciences
Serviceboks 422
N-4604 KRISTIANSAND
NORWAY
Telephone: +47 38 14 15 08
e-mail: Byrge.Birkeland@hia.no
9
1 Fundamentals
1.1 Elementary operations
You start Mathcad by double clicking on the Mathcad icon
Mathcad is primarily a mathematics program that can be used to do
calculations and draw diagrams. You can also use Mathcad as a calculator in a
natural way. If you want to calculate say 2+3, you just put the cursor where
you want the calculation to take place, type 2+3 and press =. Then what you
see, is:
2 + 3 = 5
So the program has computed the value of 2+3 and inserted the result after the
equality sign. Also, the program has inserted some white spaces to make the
formula look better. Now, press [Enter] to move the cursor a suitable number
of rows downwards, and write 2*3=. You see the following:
2 3 = 6
So, Mathcad shows the multiplication sign * as the usual dot . This is a
general principle of Mathcad: The formula you type, will look the way you are
used to in mathematics rather than the way you type them. Try 2-2/3=. This
will look like this:
2
2 = 1.333
3
Mathcad performs the arithmetical operations in the same order as you are
used to in mathematics:
1 + 23 = 7 (1 + 2)3 = 9
Multiplication takes priority before addition, so if you want the addition to be
performed before multiplication, you have to insert parentheses to change the
default order in which the operations take place.
Of course, Mathcad contains all the standard elementary operations, and they
are performed in the order you are used to in mathematics. If you use the same
operator twice or two operators of the same priority after one another, then the
leftmost operator will be used first.
11
In Mathcad, most operations can be done in several ways. You can use the
keyboard or a menu for many operations. You will probably find it best to use
the keyboard rather than the mouse, especially for operations that are used
often.
To get access to the elementary arithmetic operations, look at the Math
Toolbar:
This may have a different format on your
screen. If you don't see it at all, you need to
choose View - Toolbars - Math from the menu.
Click on the first button -the one with the
calculator - to get the calculator menu:
The symbols on the toolbar are more or less
self explanatory. However, there are alternative
keystrokes for many of the operators on the
toolbar, and you may want to use them instead
of the palette.
Instead of Use keystroke: Instead of Use keystroke
! '
1i x^2
; \
[ /
| *
e^x +
x^-1 :
.
^
-
[Ctrl] |
=
[Ctrl] p
To make the keystroke [Ctrl]p work, you need to turn off Standard Windows
Shortcut keys: Use View - Preferences - General. If you haven't doen so, the
shortcut key combination is [Ctrl] [Shift] p.
12
All the functions ln, log etc. can be typed from the keyboard instead of using
the palette. Also, if you need to write a sum over two lines, use the keystroke
[Ctrl][Enter]
The space bar plays an important role when writing and editing formulas.
When you write a mathematical expression, you see a vertical and a horizontal
editing line. The vertical line indicates where the next character is going to be
placed, while the horizontal line indicates what part of the expression that is
going to be an operand for the next operator you type. Pressing the space bar
will extend this subexpression. For instance, say you want to compute
1 + 2
5
Then you either use parentheses (1+2)/5, or you can use the space bar 1+2_/5
(where the underscore _ denotes the space bar).
Example 1
Type: To get: Type:
(3*10^5)/7

(
3 10
5
)
2^3^2=
7
3*10^5_ 7
3
10
5
2^3_^2=
7
2+3^3=
3 10
5
2+3_^3=
3*10^5_ _ 7
7
\3_+\5=
3 + 5 = 3.968
1/1/3+1/5=
\3+\5=
3 + 5 = 2.288
5 6 + 6 8
5*6+6*8_ _ _/15*4+12*3=
To get:
2
3
2
= 512
2
3
( )
2
= 64
2 + 3
3
= 29
(2 + 3)
3
= 125
1
= 3.2
1
1
3+
5
= 0.813
154 + 123
1
1/1/3_+1/5=
= 1.875
1 1
+
3 5
2+3_*2[Ctrl]/[Enter]3+4_*5=
(2 + 3)2 ... = 45
+ (3 + 4)5
2 [Ctrl]/ 3 or 2 [Ctrl] * 3 =
2 3 = 0.667
Let us look at an important detail. Mathcad, by default gives the result of a
calculation as a decimal fraction:
13
Type 2/3_ - 1/4= to get:
After the result 0.417 you see a filled rectangle. This is Mathcad's notation for
a placeholder - a place where an input is expected. In this case the input is
optional, and if you choose to give any input here (click on the placeholder),
the effect is that the result is given as the product of this input and another
factor. In the case above, you could choose 1/12, since 12 is the common
denominator and get:
2

1
5
1
=
3 4 12
This trick can be used in several connections. Say you have a numerical result,
but have a suspicion that it can be expressed as a multiple of some known
symbolic constant. Then you just use this symbolic constant as a factor in the
way described above. Here are some examples:
atan 1 ( ) = 1

8 = 2 2 sin


= 0.5
4

4

2
Alternatively, you can use symbolic evaluation, as described in section 1.3:
atan 1 ( )
1
8 2 2 sin



1

4

4

2
2
Another application is using dimensions, which we shall discuss briefly in
section 1.5.4.
Exercises. Make Mathcad do the following computations:
1.210
19
2.510
20

3
= 4.5 10
18
2 + 5 = 3.65
100
100

1

1 +

= 2.705 2
2
+ 3
2
+ 4
2
+ 5
2
= 54

100

1 1 1 1 12 + 13.50 10 + 1
+ + + = 0.464 = 1.833
2
2
3
2
4
2
5
2
2(3 + 1.5)
1 1 1 1 8
+ + + = 0.717 15 = 14.923
2! 3! 4! 5! 104.5
2
6
= 0.707

1 +
4.5


= 1.302
2

100

1 1 1 1 1 1
1 + + + + + + = 127
1
2 4 8 16 32 64 64
14
1.2 Handling files
1.2.1 Saving your work
At this point you may want to save your work. The mechanism for saving your
file is the same as for most windows programs. In fact there are several
alternative ways to do it:
Choose File from the menu. You get a pull-down menu where the first
options are the following:
Choose Save to save your work. If you save for the first time, you'll be asked
for a file name. Otherwise, the present version of your file will replace
whatever version you had before. If you want to keep both versions, you have
to choose Save As instead. Then you'll be asked for a new file name for the
new version of your file.
Alternatively, you can save your file by clicking the icon
You can also press [Ctrl] S or [F6].
1.2.2 Starting a new file
To open a new file, you also have four possibilities:.
Choose New from the File menu
Click on the icon
Press [Ctrl] N
Press [F7]
15
1.2.3 Opening an existing file
Similarly, to open an existing file, you have the following four options:
Choose Open from the File menu
Click on the icon
Press [F5]
Press [Ctrl] O
You'll be asked for a file name, which you can either type or pick from a list of
files in the current directory.
1.2.4 Closing a file
To close a file means to save it to disk and then remove it from the machine's
internal memory. You can do this by either
choosing Close from the File menu or
pressing [Ctrl][F4]
1.2.5 Printing a file
For printing the active file, you have two possibilities:
Choose Print from the File menu.
Click on the icon:
In either case you get a dialogue box where there is a number of choices you
can make. Most of the options are self explanatory, and I won't go into further
details. Refer to Mathcad's documentation or use the Help function if you need
any help.
One thing, though: If you need to produce a Postscript file (or any other print
file) that a publisher can use to produce a book (like this one) without having
to open Mathcad, check the Print to File box. Then a file with Postscript code
will be produced instead of a printout.
16
1.3 Symbolic versus numerical
calculations
1.3.1 Numerical and symbolic Mathcad
Mathcad in its present form is really a combination of several programs. The
first versions of Mathcad could only do numerical calculations. Symbolic
manipulation of expressions was impossible. From version 3.0 on, however,
Mathcad has included a symbolic part as well. The technology comes partly
from the mathematics program Maple. Mathcad calls this part of the program
"The Symbolic Processor" - the name could perhaps have been chosen better,
since most people think of hardware when they see the word processor.
The Symbolic Processor was a very useful addition to Mathcad. However, we
shall see that the two parts of the program - the numerical and the symbolic
part - are not one hundred percent integrated. The are some subtle, but
important syntactic differences between the two parts, which you have to take
careful notice of. For instance, numerical Mathcad can take a function as an
argument to another function, whereas the Symbolic Processor can also handle
an expression instead of a function as an argument to a new function. This is
in agreement with programs like Maple, Derive and Mathematica. Also,
Mathcad's programming language, which was a very valuable addition in
version 6.0, works somewhat differently for functions that you are going to use
numerically and symbolically.
1.3.2 Forcing symbolic calculation
Anyway, Mathcad can do many calculations both numerically and
symbolically. You just have to signal to the program which one of the two
possibilities you want to use.
For elementary operations the only thing you need to do to make a result come
out symbolically instead of numerically, is to replace the ordinary equal
symbol = by a right arrow symbol:
2 3 2 3 17
+ = 1.417
is replaced by
+
3 4 3 4 12
To get the symbolic calculation symbol you can do one of two things:
17
Either you click on the icon to get the menu:
Then click on the icon
Or - more easily - you press [Ctrl][Period]
Examples
3 10
5
= 4.286 10
4
3 10
5
300000

7 7 7
3 + 5
1
10
1
= 2.288 3 + 5 +
2 2
2
3 2 + 2 = 2.414 3 2 + 2 2 + 1
Notice that you can follow a symbolic calculation with a numerical calculation:
5 6 + 6 8 5 6 + 6 8 13
= 0.813 = 0.813
154 + 123 154 + 123 16
sin



1
2 = 0.707

4

2
You can get as many digits in the approximation as you want by using the
button or pressing [Ctrl] [Shift] [Period] and then writing float,40 in the
placeholder:
2asin 1 ( ) float , 40 3.141592653589793238462643383279502884197
You can also use the menu choice Symbolic - Evaluate - Floating Point and
write the number of decimals into the dialogue box:
( )
floating point evaluation yields
3.1415926535897932385 2asin 1
Notice that numerical evaluation will give you at most 15 significant digits.
The number of significant digits shown in numerical results is determined by
choosing Format - Result - Number Format from the menu.Then set the
number of decimal places you want after Number of decimal places. If you
want to change the displayed format for just one result, double click on it to
get the same dialogue box. The change will now concern just the one result.
Exercises. Repeat (some of) the exercises after section 1.1, but with symbolic
calculation.
18
Dirac
1.4 Mathcad's built-in functions
Mathcad's built-in functions in general have the syntax you know from
mathematics. So you can just type the function's name from the keyboard.
Alternatively, you can choose from a list of functions: Choose Insert -
Function from the menu. Alternatively, press the button
on the standard toolbar. You get the following dialogue box:
In the left half of the window, you scroll down to the category of functions that
you need. Then, in the right window you'll see a list of Mathcad's built-in
functions of that category. Click on the one you want you want. You'll see an
explanation of the function in the area below the lists. Press the button Insert to
insert the function into your worksheet. Most of the functions are understood
both numerically and symbolically, but there are some exceptions, e.g.
(1 0) = 0 (1 0) (1 0)
Kronecker's delta function
, , ,
1 ( ) 0
Dirac's delta function
Dirac( ) = Dirac 1
I shall not make any attempt to list Mathcad's built-in functions. The best way
to learn about them is to go through the dialogue box above, or to consult
Mathcad's documentation "Reference manual".
19
a
1.5 Variables
1.5.1 Defining a variable
Defining variables is a fundamental operation in any programming language,
and so it is in Mathcad. Say you want to assign the value 2 to a variable named
x and the value 3 to the value y. Then type x:2 and y:3. The colon will appear
as :=
x := 2 y := 3
After having defined x and y you can use them in calculations:
x = 2 y = 3 x + y = 5 x + y
2
= 11 sin(xy) = 0.279
x 2 y 3 x + y 5 x + y
2
11 sin(xy) sin 6 ( )
If you try to use a variable before it has been defined, Mathcad shows the
variable in a different color and shows the error message "This variable or
function is not defined above".
a = a := 34 a = 34
However you can choose to let Mathcad behave differently at this point.
Choose View - Preferences from the menu. Choose the General tab, and
check Use context sensitive equal sign. Now, when you try to use the = sign
on an undefined variable, Mathcad will find that this variable is not defined,
and will assume that your intention is to define the new variable instead of
trying to evaluate an already defined variable.
There is one more operation for assigning a value to a variable, which
Mathcad denotes global assignment. Instead of the colon, you use the tilde ~,
which is shown as
X 5 Y 7 X + Y = 12 X
Y
= 7.813 10
4
However, a global assignment works a little different than a local assignment
with :=. Global assignments are calculated before the local assignments, so
they appear as working "both ways". So you get the following:
A = 6 A 6 A = 6 A := 3 A = 3
You see that even if you get an error message the first time you try to evaluate
an undefined variable, the error message will disappear as soon as you define
the variable by means of a global assignment, even if this definition comes
after the evaluation. The last two blocks above show that a global definition is
overridden by a local definition.
You cannot use a variable that has been defined as local when you define a
global variable, but you can use a global variable when you define a local
variable:
20
3A
a B 2a
(a is shown as an undefined variable) but:
D 3 B 2D D = 3 E := 2D E = 6
1.5.2 Variable names
Mathcad has a set of rules concerning variable names, which you can find in
Mathcad's documentation. Here are a few things to notice:
A variable name can consist of letters, digits, the underscore, the prime ,
the percent %, and the infinity symbol , which you can get by typing
[Ctrl] Z. The prime will combine with some vowels like in ,,. To get a
prime alone, write, say, t and delete the t.
A variable name has to start with or a letter, which can be uppercase or
lowercase. The symbol can only be used as the first letter of a variable
name (which you will probably never do). If you violate this rule you'll
get the error message that states that the expression cannot be defined.:
B := 4
is all right but
3A := 3
gives an error message.
You can use Greek letters in variable names. Type the Roman equivalent
(a list of these can be found in Mathcad's documentation), and press
[Ctrl]G. Roman and Greek letters can be mixed:
g := 3 g = 3
You can make part of a name a subscript by pressing period (.). This is
just a typographic effect, and has nothing to do with a vector index, which
you get by pressing the left square bracket [, as you'll see later.

F
:= 5
F
= 5
16
:= 13
16
= 13
You can let the type style be part of a variable name in the following way.
Choose Format - Equation from the menu to get the following dialogue
box.
21
a
Click on the down arrow to the right of the upper input field, and scroll down
to the name MyType (or User 2 ...). Then press the button Modify. You get a
dialogue box where you can choose the type style. Say you choose Italic type.
Then press OK to get out of the dialogue box. Now, to define a new variable
with the name A in italic type style, type A and click the down arrow button
on the formatting toolbar:
Click on MyType. Then continue with the variable definition:
A := 67
Notice that:
A = 3 A = 67
This means that the style is part of a variable's name. Two variables with their
names spelled identically are different if their styles are different.
1.5.3 Range variables
Often you need a sequence of numbers that increase or decrease by a constant
amount. For this Mathcad has the concept range variable. It has the syntax
First value, Second value; Last value or First value; Last value.
With the second syntax, it is assumed that Second Value = First Value + 1:
The semicolon ; will be shown as two periods [..]. For example, if you want to
assign the numbers 0,0.5,1..2 to a variable with the name a, you type a:0,0.5;2:
a := 0 , 0.5.. 1.5
Notice that it is a common mistake to use two periods .. instead of semicolon.
Mathcad will mark that as an error (Can't understand this number)
Then you can use the variable a in computations. The results will be given in
output tables. As you see, the operation is performed for all the values in the
range variable a. However, if you try to define a new variable by means of a
range variable, you get an error message "Illegal context":
( ) = 2 a = a = a
2
= sin a
0
0.5
1
1.5
0
0.25
1
2.25
0
0.479
0.841
0.997
0
1
2
3
b := 2a
(Illegal context)
22
The main applications for range variables are as array indices and as variables
that runs through a function's interval of definition e.g. when you draw the
graph. Range variables cannot be used in symbolic calculations.
1.5.4 Using dimensions
Mathcad has several unit systems built-in: SI, MKS, CGS and US. You can
choose which one you want to use by choosing Math - Options from the
menu, and then clicking the Unit System tag. Let's say we use the SI system.
You can define variables that involve units or dimensions. This is very useful
in physics. Here is a (physically trivial) example:
Say you want to find the force that is necessary to give a mass of 1 kg an
acceleration of 2 m/s
2
.
First you define a variable for the mass. Write
m := 1
(Use MyType format)
With the cursor on the placeholder after the multiplication dot, choose Insert
- Unit from the menu. Alternatively, press [Ctrl] U. You get the following
dialogue box:
Mathcad has a set of units for most of the physical quantities you can think of.
To access the units of mass you scroll down the list to the left till you come to
Mass. The two lists now look like this:
Click on Kilograms [kg] and then on the Insert button (or double click on
Kilograms). The result is:
m := 1 kg
Now, define a variable a for the acceleration. Using the same procedure as for
the mass, you get:
m
a := 2
To compute the force, you define by Newton's second law:
2
s
23
F := ma
Writing F = you get:
F = 2 N
So, Mathcad applies any definition of derived units that it finds. You can also
use your own version of the unit abbreviations if they are different from
Mathcad's. Try to write an N in the placeholder after the result above, and you
get: F = 2 N
You can also choose to format the resulting unit differently. Instead of
F = 2 kg m s
-2
you may want to have F = 2
kg m
2
s
In that case you do check Format Units instead of Simplify units when
possible in the dialogue box mentioned above
Exercises.
1. Use Mathcad to compute x+y when
a. x=2 and y=3 b. x=3.14 and y=1.24
2. Use Mathcad to compute the value of x/y when
a. x=3.14 and y=3.4 b. x=4.5 and y=1.26
3. Define
x := 2
and
y := 3
and calculate the value of the following
expressions. Use numerical and symbolic evaluation.
x + y (x + y)
10
x y
2
y! x
y
x y x y
x y
ln(x y) x y atan2(x , y) atan


x
2
+ y
2

x

,
2 3
( )
for x = 1,2,...,10 4. Use a range variable to find the values of
x x , x , sin x
5. Use Mathcad to find the resistance of the following electric circuit:
(This figure has been
drawn entirely by means
of Mathcad, using some
functions that I have
developed somewhere
else, and which are
beyond the scope of this
book. Then it has been
copied to this file.)
24
1.6 Arrays
1.6.1 Defining an array with [Ctrl]M
Arrays in Mathcad are basically of dimension one or two, i.e. they are vectors
or matrices. But in addition you can form nested arrays, which are arrays
whose elements are themselves arrays. This is very useful in many
connections, e.g. in graphics.
Arrays can be defined either by giving the components one by one in an input
array or by defining the components by means of a formula.
Say you want to write the matrix

1 4 7
_

2 5 8



3 6 9
,
Press [Ctrl]M. Alternatively, press the button on the Math toolbar to
get the palette
The press the button
You get a dialogue box:
_
Choose the number of rows (3) and columns (3) and click

on Create. Then you get the following array of

placeholders:
,
Then you can just fill in the values. To proceed from one element to the next,
press [TAB]. You'll be lead to fill out the array row by row.
A vector in Mathcad is by default a matrix with one column (not a row, as
most other programs prefer), and can be defined by the same procedure as
above.
Notice that an array has to have at least two elements when you use [Ctrl] M.
You can define a one element array, cf. next subsection.
25
You can assign an array to a variable by typing the variable name, pressing :
(or ~ for global assignment) and then do the procedure above.

1 4 7
_
2
_
1 4 7
_
2
_
A :

2 5 8

B :

3

A

2 5 8

B

3



3 6 9
,
4
,
3 6 9
,
4
,
1.6.2 Accessing the elements of an array
If you want to access one particular elements of an array, you have to use the
index operator, which you get by typing the left square bracket [. Array
indices in Mathcad start with 0 by default (this can be changed), so to get the
first component of the vector B, you type B[0= to get
B
0
2
Alternatively, press the button
Notice how this looks almost but not quite like the subscript operator (period),
which has purely cosmetic function:
B
0
on the matrix palette to get
For matrices you have to use two indices with comma in between:
A
0 0
1 A
2 2
9
, ,
1.6.3 The nth column vector of a matrix
To access the nth column vector of a matrix, you have the operator <>, which
you can get by pressing [Ctrl]6 on the alphanumeric keyboard, or by clicking
on the icon
in the matrix palette. For the matrices above:

1
_
4
_
7
_
2
_
0 1 2 0
A


2

A


5

A


8

B


3



3
,
6
,
9
,
4
,
There is no similar operator for the nth row, but you can get it by combining
the column operator with the transposition operator [Ctrl]1:
0 1
A
T
A
T
( )

T
( 1 4 7 )
( )

T
( 2 5 8 )
26
1.6.4 Defining an array by means of a formula
The method described above to define an array has a restriction: The total
number of elements in the matrix has to be between 2 and 100. For arrays
bigger or smaller than that you have to use other methods.
Say want want to define a vector X with 200 elements whose nth element is n
2
.
Then you do the following:
First, define an index set for the vector as a range variable:
n : 0 .. 199
Then define the value of the nth component, using the [ operator:
: X
n
n
If you try to evaluate the vector X by pressing X=, you get a long table which
eats a great deal of paper. It's better to evaluate the transpose, which will then
be a row vector. You get the transpose by pressing [Ctrl]1 after the variable
name (1 must be typed on the alphanumeric keyboard).
X
T

0 1 2 3 4 5 6 7 8 9
0 0 1 4 9 16 25 36 49 64 81 1
Mathcad will show just the first few elements, but you can click on the table
and scroll to see the rest of the components.
The same method works for matrices. Define index range variables:
i : 0 .. 2 j : 0 .. 12
and a formula for the element with indices (i,j):
Y
i , j
: i + j

0 1 2 3 4 5 6 7 8 9 10 11 12
_
Y

1 2 3 4 5 6 7 8 9 10 11 12 13



2 3 4 5 6 7 8 9 10 11 12 13 14
,
Sometimes it's necessary to define an array with just one element. If you try to
do this with [Ctrl]M, you'll get an error message "Zero or single element
matrix not allowed". However, nothing stops you from defining such a matrix
by means of a formula:
1 W
0
: 1 W ( ) W
0 0
1
,
Notice that Mathcad writes a one element matrix in parentheses - this is new in
version 8. Also, Mathcad has boolean functions that signals whether a variable
has a certain type - array, scalar or string:
IsArray W
( )
0 IsScalar W ( ) 1 IsArray W
0
( ) 0
IsScalar W
0
( ) 0 IsString("abc" ) 1
( )
1 IsString W
27
2
1.6.5 The first index of an array
By default, Mathcad starts to count indices at zero. This can be changed,
however, by assigning a new value to the variable ORIGIN, which is one of
Mathcad's built-in variables. Let's change it to 1:

1 4 7
_
A


2 5 8


A
1 1
5 ORIGIN : 1 A
1 1
1
, ,

3 6 9
,
In my experience, it's best to leave the value of ORIGIN at 0. Otherwise you
have to involve the value of ORIGIN in most of the programs with arrays that
you write.
1.6.6 The number of rows and columns
The functions rows and cols return the number of rows and columns of an
array. For a vector, the function length returns the number of components,
while the function last returns the last index of the array:
ORIGIN : 0

1 4 7
_
2
_
A

2 5 8

B

3

rows A ( ) 3

( ) 3 cols A
( ) 3 last B
3 6 9
,
4
, length B ( ) 2
( ) 1
In general,
last(B) ORIGIN + length B
1.6.7 Array operations
Many of the operators in Mathcad are polymorphic in the sense that they will
change according to the data types of its operands. This is the case with the
elementary operators +,-,*,/, as you can see from the examples below.

1 4 7
_
2
_
5 0 2
_
A

2 5 8

B

3

C :

4 2 2



3 6 9
,
4
,
1 0 0
,
Multiplication and addition with array operands becomes matrix
multiplication:

42
_
14 8 6
_
6 4 5
_
A B

51

A C

22 10 6

A + C

6 7 10




60
,
30 12 6
,
2 6 9
,
Multiplication with vector operands becomes scalar products:
B B 29
28
Absolute value with a vector argument becomes vector length:

2
_
B

3

B B B 29 29 5.385


4
,
Absolute value with a square matrix argument becomes determinant:

2 4
_
X :

X 2 A 0 C 4

3 5
,
Be aware, though, that this doesn't apply to arrays with one element, which are
interpreted as vectors:
a
0
: 1 a ( 1 ) a 1
Multiplication with one scalar and one array operand multiplies all the
elements of the array with the same scalar, and similarly for addition:

1 4 7
_
2 8 14
_
3 6 9
_
A

2 5 8

2 A

4 10 16

2 + A

4 7 10



3 6 9
,
6 12 18
,
5 8 11
,
A
-1
with A a square matrix gives the matrix inverse:

0 0 1
_


5 0 2
_
0 0 1
_

1 1 9

C

4 2 2

C
1


0.5 0.5 4.5

C
1


2 2 2

1 0 0
,
0.5 0 2.5
,

1 5


0


2 2
,
[Ctrl] 1 gives the transpose of a matrix. There is also a button on the Matrix
toolbar for that operation.

1 4 7
_
1 2 3
_
A

2 5 8

A
T


4 5 6



3 6 9
,
7 8 9
,
The function submatrix is of course used to define a submatrix, and has the
syntax submatrix(Matrix, FromRow, ToRow, FromCol, ToCol):

1 4 7
_
submatrix(A, 0 , 1 , 0 , 2)


2 5 8
,
29
1.6.8 Nested arrays
You can use at most two indices when defining arrays in Mathcad. If you need
matrices of higher dimensions, you have to use nested arrays. A nested array
is an array where the elements are themselves arrays. You can nest arrays in
several levels. Here is an example:

1
2
3
4
_

5
6
7
8
_

,
ORIGIN : 0 G
0 0 ,
: G
0 1 ,
: G ( {2,2} {2,2} )
As you see G= gives you only the dimensions of the component arrays, not the
values. This can be changed, however. Type G= again, and double click on the
result to get the usual Result Format box. Check Expand nested arrays. You
get:
G

1
2
3
4
_

5
6
7
8
_

,
1
1
]
If you need to access an element of one of the arrays that are components, you
have to use the space bar or parentheses to get the nested indices:

1
2
3
4
_

,
G
0
( )
0 0 ,
1 G
0 0 ,

(
G
0 1
)
1 1
,
,
8
1.6.9 Defining bigger arrays
With the [Ctrl] M method you can create matrices with 100 or less elements.
Using a formula, the size of the matrix is only limited by the size of your
machine's RAM. Some times you need to define matrices with more than 100
elements for which there is no explicit formula, e.g. to include the results of
repeated experiments in your file. If you have the data in a spreadsheet, say
Excel, you can import from there, but you can also go via an ASCII file. You
can use an ASCII editor to create a text file with the same number of numbers
in each row. Or you can write them in a text region in Mathcad and copy them
to an ASCII file. Let me demonstrate by an example. Below, I have written
some numbers in a Mathcad text region. There is a [Return] character at the
end of each row, which will correspond to going from one row to the next in
the matrix.
1.0 2.3 3.4 5.6 6.7 3.2 4.5 5.6 7.6 7.8
2.1 3.4 4.6 7.6 4.5 2.3 4.5 5.6 7.6 6.7
3.4 5.4 6.7 7.8 8.8 4.5 3.6 6.7 4.5 5.6
Then you copy this to the clipboard by selecting it and the choosing Edit -
Copy from the menu (or the equivalent copy button). Then you open Notepad
and paste the content of the clipboard back to the Notepad window. You may
have to do some editing: Press [Enter] at each of the black boxes and delete
the black box. Then you save it with some name, say data.txt. Then you go
back to Mathcad, and define a text variable say with the name file:
30
file : "data.txt"
(Press " immediately after the definition colon.)
Remember to include the full path to the file, if it isn't in the current directory.
Then you can get the data back as a matrix by means of the function
READPRN:
M : READPRN(file)

1 2.3 3.4 5.6 6.7 3.2 4.5 5.6 7.6 7.8
_
M

2.1 3.4 4.6 7.6 4.5 2.3 4.5 5.6 7.6 6.7



3.4 5.4 6.7 7.8 8.8 4.5 3.6 6.7 4.5 5.6
,
You can also defined matrices with more than a hundred elements by using the
functions stack and augment. The function stack works on two matrices with
the same number of columns and puts them underneath each other. The
function augment works on two matrices with the same number of rows and
puts one after the other:

2 3 4
_
1 1 1 1
_ C : ( 8 9 0 )
A :

B :


5 6 7
,
2 2 2 2
,

2 3 4
_
augment(A, B)


2 3 4 1 1 1 1
_

stack(A, C)


5 6 7


5 6 7 2 2 2 2
,

8 9 0
,
Exercises
1. Given the system of linear equations:
x
2
3 x
3
= 5 a. Define the system's augmented coefficient

matrix M, using the [Ctrl]M method.


2 x
1
+ 3 x
2
x
3
= 7
b. Use the submatrix function to define the
system's coefficient matrix A and the vector of
4 x
1
+ 5 x
2
2 x
3
= 10
right-hand sides B.
c. Solve the system by computing A
-1
B
2. The function rnd(x) returns a random number between 0 and x. Define a
random 100 x 100 matrix by means of this function and compute its inverse.
3. Use symbolic computation 4. Given the matrix

1 3 2
_
to find the inverse of the
A :

2 5 3

following matrices:

3 2 4
,

a b
_

1 a 2
_


c d
,

a 3 1


Find A
-1
, and compare with the result of
( )))
3 1 2
, rref(augment(A, identity 3
31
f x
f 1 f 0
f x
1.7 Functions
1.7.1 Defining your own functions
You have seen that Mathcad contains a library of common mathematical
functions. If this library doesn't cover your needs, you can define your own
functions.
To define a function, you write the function name, the list of arguments
separated by commas and surrounded by parentheses. Then you press the
colon : or the tilde ~ to get the assignment operator. Then to the right, you
write a valid formula, using Mathcad's built-in functions, or a previously
defined function of your own. The arguments of the functions cannot be typed
(as in Mathematica) - their data type are determined as soon as the function is
applied and Mathcad sees what kind of operators you use. The relation
between global and local definition is the same as for assigning values to
variables. Mathcad doesn't distinguish between variable names and function
names, so you have to take care not to use the same name for a variable and a
function. Example:
( ) : x
2
Then you can use the evaluation operators = or to get function values:
( ) 0 ( ) 1 f(2.5) 6.25 f(2.5) 6.25 f


5
_


25

2
,
4
Say you have a vector of arguments for the function:
i : 0 .. 10 x
i
: 0.5i
Then you can get the a vector of corresponding function values in one of two
ways: Either you define a vector y by:
y
i
: f x
i
( )
T
y ( 0 0.25 1 2.25 4 6.25 9 12.25 16 20.25 25 )
Notice that this procedure also works symbolically (new in version 2000):
T
y ( 0 .25 1.00 2.25 4.00 6.25 9.00 12.25 16.00 20.25 25.00 )
Or you use the vectorize operator, which you get either by pressing [Ctrl]- or
pressing the icon
from the Matrix toolbar
Now, type f(x) and get the vectorize symbol in one of the two ways just
described. The result is:

)
T
(
( ) ( 0 0.25 1 2.25 4 6.25 9 12.25 16 20.25 25 )
32
f x ( ) f x
Notice that the vectorize operation does not make sense symbolically:

( )
. ("Matrix dimensions are incompatible").
Many of Mathcad's built-in functions can be used on arrays without the
vectorize operation:

1
_
0.841
_
1
_
0
_
( )

0.909

t
2


4

ln t t :


sin t

( )


0.693 + 3.142i



3
,
0.141
,
9
,
1.099
,

0.785
_
However:


1
_
atan t ( )

1.107


t 3.742 t

2


1.249
,

,
This is because the expression |t| has a special meaning if t is a vector
The square of a matrix is another matrix: But:

1 2 3
_
30 36 42
_
1 4 9
_
A :

4 5 6

A
2


66 81 96

A
2


16 25 36



7 8 9
,
102 126 150
,
49 64 81
,
If you want the matrix of squares of elements from A, you need to use the
vectorize operator:
1.7.2 Drawing the graph of a function
To draw the graph of a function of one variable over an interval [a,b] you need
to do the following:
Define the function as described above, say
f x ( )
2
0.5 ( ) : sin x
Define a range variable, say with the name x, that runs through the
interval [a,b], say:
x : 0 , 0.1.. 2
(To get , type [Ctrl] P.)
This step may be omitted. Then Mathcad will choose a default range variable
in the interval [-10,10].
Get the Graph toolbar from the Math menu by clicking the icon
Choose Insert - Graph - XY-Plot from the menu or
The graph menu looks like this:
and you click the icon
or
Press @. This is the shortest way to the diagram.
33
In any case, you get the following input scheme:
There are six placeholders. The middle placeholders on each of the axes are to
hold the formulas for the function and the argument. So, write f(x) in the
middle placeholder on the y axis and x in the middle placeholder on the x
axis. Then press [Enter]. The result is as follows:
0 4 6
1
1
f x ( )
2
x
There is a lot of things you can do with this plot. To change the format, you
simply double click on the graph. This gives you a dialogue box, where you
can change many aspects of the diagrams format. I won't go into details about
this, you are referred to Mathcad's documentation. On of the options is to
change the axes to a more familiar format: Choose XY axes Crossed and you
get:
0 4 6
f x ( )
2
1
x
If you choose to use Mathcad's default range variable, use an undefined
variable, say u:
34
u
x
x
x
f( )
10 5 0 5 10
u
The four other placeholders above give you the opportunity to determine the
endpoints of the intervals manually. You may omit this - Mathcad will then
choose values that fit the actual values rounded up to some "nice" number.
However, there may be good reasons to choose the interval endpoints manually,
as in the following example:
1
sin( )
x 0

, .. 2
.

64
g( )
0 5 10
1
.
10
16
1
.
10
16
g x ( )
0 5
g( )
x x
Interval endpoints set by Mathcad Endpoints inserted manually.
Notice how Mathcad simply drops the x values where the function has a
singularity.
You can draw the graphs of several function in the same diagram: Just write the
expression in the middle placeholder on the y axis with comma between them:
0 2 4 6
2
x
2
cos x ( )
sin x
2
x
35
1.7.3 Drawing a parameter curve.
You can even use function expressions on both axes to draw the graph of a
parameter curve. Here is a circle (you may have to adjust the size of the
diagram to make it look like a circle, not an ellipse):
You can even use a list of

t : 0 , .. 2
expressions on each axis to plot a
64
series of parametric curves.
sin t ( )
sin x ( )
0 sin 2t ( )
( ) cos(t) , cos 3t cos x ( )
You can draw a family of functions depending on a parameter that is defined
in a range variable. Define:
A : 1 .. 5 x : 0 , 0.05.. 6.3
Asin x ( )
0 5
x
1.7.4 Drawing a polar curve
The method from the previous subsection can be used to draw curves that are
given on polar form as r = f(t). You just define Cartesian parameter curves
based on the polar function by x(t) = f(t) cos(t), y(t) = f(t) sin(t). You could
define the transition from polar to Cartesian coordinates in the following way:
( )cos t

f t ( )
_
P2C(f , t) :

or
( )sin t

f t ( )
,
( )
in complex notation.
CP2C(f , t) : f(t)exp it
36
Example: Cardioid.
f1(t) : 1 cos t ( )
0
P2C f1 t , (
1
)
P2C(f1, t)
0
Mathcad also has a tool which is intended to take care of polar curves in
particular. Choose Insert - Graph - Polar Plot from the menu, or press [Ctrl]
7, where 7 is on the alphanumeric keyboard. There is also a button on the
Graph Toolbar for it. Then fill in the placeholders with the polar function and
the parameter t:
90
150
210
330
1.5
0.5
120 60
This method will guarantee that
30
circles are drawn as circles, not
( )
180 0
ellipses, and you may draw grid lines
f1 t
as circles and radii instead of lines
parallel to the x and y axes. There is
240 300
a set of formatting options similar to
270
those for Cartesian plots.
t
Exercises.
1. Draw the graphs of the following functions:
1
x
sin x
xsin x ( )
( ) 1
( ) tan x
(x 1)(x 3)(x 4)(x 6) x
1 + x
2
2. Draw the following parameter curves:

sin t ( )
_


cos t ( )
_
( )
_
1
_
t
_
t sin t ( )
3
_


9 cos(t) cos 9t


t
,
t
,
1
,
1 cos t
( )
3
,


9 sin(t) sin 9t ( )
,


sin t
( )
,
3. Draw the following polar curves:
1
r = 1 r = sin 2t cos 2t ( ) ( ) r = 1 cos t ( ) r = r = t r = + cos t ( )
2
37
1 U
x
2 U
x
f x f x
f x
f x f x f x f x f x
f x
1.7.5 Functions as argument to a new function
Mathcad allows functions to be used as arguments in new functions in the
same way as you can in C++ or modern versions of Pascal. E.g. if you define:

b
Area1(f , a , b) : ( ( ) dx ( ) : x
2
then
Area1(f , 0 , 1)
1
3
a
and
Area1(f , 0 , 1) 0.333
so this works both numerically and symbolically.
On the other hand many of Mathcad's own built-in operators work on
expressions, not functions. The integral operator is one of them:

1
1
( f dx
doesn't work, but
( ( ) dx
is OK.

0

0
3
Furthermore the output of a Mathcad function is never a function (with one
exception: the function Odesolve), but an expression, so it is easier to define
the composition of functions whose arguments are expressions than whose
arguments are functions. Example:
D1(f , x) :
d
2
( ) 2
d
( ) + ( ) D2(f , x) :
d
( ) ( )
dx
2
dx dx
( ) ( ) :
(
x + x
2
)
e
x
Then
D1(f , x) expand 2exp x
is an expression, not a function, so you can't use it as a functional argument to
a new function. You have to define it as a new function:
Df x ( )
Then you can compute
( ) : D1(f , x) expand 2exp x
D2(Df , x) expand 0
Now, compare this with the following definitions
( ) :
d
2
U 2
d
U + U ( ) :
d
U U
dx
2
dx dx
Two of the x's are in red to indicate that the variable has not been defined, but
you can ignore this. Symbolic Mathcad will be able to use the functions 1
and 2 anyway. Then
( ( )) expand 2exp x
( ( ))) expand 0
or even 1 f x ( )
2(1 f x
1 x + x
2
)
e
x
]
1
expand 2exp x

(
(
( )
2

1 x + x
2
)
e
x
1
]
1
]
expand 0

So, using expressions is sometimes preferable. I'm going to do so consistently
with symbolic differential equations. But whenever it is possible, you should
use functions rather than expressions, because they are understodd both by
numerical and symbolic Mathcad.
If you have a function f, you can always get an expression by writing f(x).
But you can also go the other way:
38
x
U 2
H 0
x 1 + x
U lim


x g x U
g 2
If you define
U : sin( ) and ( ) : U
it won't work:
x
g t ( ) g 2 ( ) g( )
(Function not defined.)
( ) sin x ( ) sin x
but if you compute it symbolically:
h x ( )
it will be OK:
h

_
1 h t ( ) ( ) : U sin x ( ) sin t

2
,
Doing the symbolic evaluation gives the function a meaning in numerical
Mathcad. Here is a warning: It would be natural to define:
DD1(U, x) :
d
2
U 2
d
U + U
dx
2
dx
and then try to change to another variable name. However, this doesn't work:
DD1

(
t + t
2
)
, t
1
]
t + t
2
DD1
(
x + x
2
, x
)
3x + x
2
So you should make a decision about the name of the independent variable
and stick to it. If you have defined a function, it's easy to get a function value:
( ) : sin x ( ) 0.909 f 2 ( ) f x + 1) sin(x + 1) f x ( ) f 2 ( ) sin 2 (
How do you do this with an expression? Say you define
U : sin( ) x
Then, of course, you cannot do
U( )
and
U x + 1) sin(x)(x + 1) (
will be interpreted as a product, because U is not a function. But you can use
the substitute keyword:
U substitute, x = 2 sin 2 ( ) U substitute, x = x + 1 sin(x + 1)
or you can define a function based on U as above:
H x ( ) ( ) : U sin x
( ) 0 H 1 ( ) sin 1 ( ) 0.841 H 1 ( )
You may also need to use this in a program. Then you can use the limit
function:
lim U 0 lim U sin 1 ( )
x0 x1
However, you cannot substitute x+1 (or any other expression containing x)
for x:
lim U
("A value is invalid. It may be complex.")
xx 1 +
But then you can go via an intermediate variable:
Val(U, t) : lim lim U
tttt xttt
Val(U, x + 1) sin(x)cos 1 ( ) ( ) + cos(x)sin 1
Val
(
x
2
+ y
2
, x + 1
)
x
2
+ 2 x + 1 + y
2

39
f x
f a
1.8 Using Mathcad's programming
language
1.8.1 An example: The trapezoid rule
Using the summation symbol that was described in the previous section, you
can express the trapezoid rule by the following function:
n 1
( )

Trapez(f , a , b , n)
b a


( ) + f b
+

f a + i


b a

_
1
1
1
1

n 2

n
, ]
1

i 1
]
2
For example, with
f x
( ) you get:
( ) : sin x
Trapez(f , 0 , 2, 100) 0.6412750596
Trapez(f , 0 , 2, 10000)
0.642138102
Mathcad's built-in numerical

2
integral operator gives:
( ( ) dx 0.6421382282

0
To get 10 digits instead of the default three, double click on the result to get a
dialogue box for number format. In Number Format, change Number of
decimal places 3 to 10.
1.8.2 Using Mathcad's programming language
Although the program above works fine, you may agree that it has some
weaknesses. First, the quantity
b a
will be evaluated once for every value
n
of i, in addition to the first time outside of the parentheses. It would be better
to evaluate this quantity once and for all and put it into a variable say h. Here
is how this can be done with Mathcad's programming language:
First click on the icon
to get the programming palette:
Notice that Mathcad's programming language consists of only ten commands!
But then, of course, you can use the rest of Mathcad in addition.
40
f a
f a
Now, let's write a small program that evaluates
b a
once and for all: Define
n
a new function Trapez2(f,a,b,n): Type h (b-a)/n ( is assignment within a
program). Press [SPACE BAR] some times until the horizontal editing line
covers all of this expression. Then press the Add Line button to get a new
placeholder in the line below. Type the expression below.
b a
Trapez2(f , a , b , n) h
n

h


( ) + f b
n 1
(
_
2
( )
+

f a + ih)



i 1
,
You can see that this gives the same result as above:
Trapez2(f , 0 , 2, 10000)
0.642138102030335
Mathcad has no function for taking the time, so it may be difficult to see the
time gained by this new program. So, you may just consider it as an
illustration of the principles of Mathcad programming.
We have used two of the programming commands:
was used to indicate that we are starting to use the program
language in a program with more than one statement. It is also
used within a program to add new program lines, for instance in
a loop.
is the assignment operator that is used within programs. Notice
that this can be used only to assign a value to a variable. If you
need to call another function, this function must have been
defined outside of the current program.
Next, we illustrate the use of the for command. Notice that you
have to click the for button. It doesn't work to type it. Let's
rewrite the function Trapez2 in the following way:
b a
Trapez3(f , a , b , n) h
n
sum
( ) + f b ( )
2
for i 1 .. n 1
sum sum + f(a + ih)
sumh
41
f a
f a
Notice that the function Trapez3 returns the value that is computed in the last
program line.
This also agrees with the former definitions:
Trapez3(f , 0 , 2, 10000)
0.642138102030335
You could also have used a loop instead of a for loop:
Trapez4(f , a , b , n)

h
b a
_

sum
( ) + f b ( )

_
(i 1)

n
,
2
,
while i n <
sum sum + f(a + ih)
i i + 1
sumh
Notice that you can write several program statements on one line if you
enclose each of them in parentheses and multiply (which is the same as logical
and).
This also agrees with the previous versions:
Trapez4(f , 0 , 2, 10000)
0.642138102030335
Here we have used a while loop instead of a for loop. Notice that you have to
press the [Add Line] button when the cursor is on the placeholder after the line
with the while command in order to get an extra program line in the loop. You
get a vertical line that indicates where the while loop starts and where it ends.
These vertical lines make Mathcad programs very easy to understand - you can
easily understand the structure of the programs, and you're almost forced to
program correctly.
The button is used to break out of a loop when some
condition
is fulfilled. You can rewrite the Trapez4 in the following way:
Trapez5(f , a , b , n)

h
b a
_

sum
( ) + f b ( )

_
(i 1)

n
,
2
,
while 1
sum sum + f(a + ih)
i i + 1
break if i n
sumh
42
g x
Trapez5(f , 0 , 2, 10000)
0.642138102030335
Here the 1 after while means "true for ever", and the loop would go on for ever
if it wasn't for the break statement, which has the same effect as the condition
i<n in the previous version.
To illustrate the statement, let's write a program that extracts
only the even number out of the first n positive integers:
Even n ( ) : j 0
for i 0 .. n

0
_


continue if mod(i , 2) = 1

2

( )

4
x
j
i
Even 8
j j + 1


x

8
,
This example also illustrates the use of the if statement. Here is another
example that also involves the [otherwise] button. We define a function by
different formulae in different intervals:
( ) x
2
3 x 4 if x 3 <
x 4 if 3 x < 4
(x 4)
2
if 4 x < 5
(6 x)
2
otherwise
Two comments:
Before you press the or
button, press the space bar in order include everything to the left of it. This is
necessary when you have a statement rather than a value to the left of if.
Alternatively, press the [if] or [otherwise] button first.
The strict inequality signs < and > are on the keyboard. The others are on
the Evaluation and Boolean toolbar. Press
to get the Evaluation toolbar:
Let's draw the graph of the function g:
x : 2 , 2.05.. 6
43
2 4
5
5
g x ( )
3 6 5
x
is used if you want a function to return a value and halt before
the last program line. The next example also demonstrates how you can use the
function error to return an error message under a certain condition:
divideby(y , x) : return error("The denominator is zero" ) if x = 0
y
x
divideby(2 , 1) 2
Finally, let's demonstrate the use of
This button is used e.g. to handle exceptions where you give an input that is of
the wrong data type.
Square(x) error("Must be a real or complex number" ) x
2
: on error
Here "a" is a string variable, and thus cannot be squared.
Exercises.
1. Program a function which, given a natural number N, returns a vector with
N components, all of which are zero. Compare with the value of

identity N ( )
0
0
2. You have seen before how Mathcad interprets the sum of an array and a
scalar: The scalar is added to each of the components of the array. Use this and
the program from exercise 1 to define a function that return a vector of given
length with all the components equal to a given number.
44
3. Program a function Diag(x), which for a given vector x gives a square
matrix where the components of x are on the main diagonal.
4. Program a function PositiveComp(x) which for a given vector x returns the
vector whose components are the positive components of x.
5. Program a function GreaterThan(x), which, given a vector x and a number
a, returns a vector whose components are the the components of x which are
greater than a.
6. Program a function Max(x) which, given a vector x, returns the largest
component of x. Compare with Mathcad's built-in function max.
7. Program a function which, given a vector x, returns the largest component
of x and the index of the first component of x where this is found.
8. Program a function which, given a vector x, returns the largest component
of x and a vector of indices of the components that have this value.
9. Program a function which for a given matrix M returns a vector where all
the column vectors of M are put underneath each other.
10. Program a function which for a given array M returns the mean of the
components of m. Compare with the built-in function mean.
11. Program a function which for a given matrix returns the sum of its
components.
12. Program a function Det(x) which returns the determinant of a square
matrix x even if x is a 1 x 1 matrix.
13. Program the elementary row operations on matrix:
Multiplying a row by a scalar
Adding a multiple of one row to another row
Interchanging two rows.
Try the function on some examples, both numerically and symbolically. Use
the elementary row operations to solve the following system of equations by
naiv Gauss elimination:
2x + 4y + 6z = 18
4x + 5y + 6z = 24
3x + y 2z = 4
45
171!
1.9 Numbers
1.9.1 Functions for number theory and combinatorics
Mathcad has the two functions gcd (greatest common divisor) and lcm (least
common multiple). They both take arrays as arguments:

112 7
_
b :

gcd b ( ) 7 lcm(b) 336

42 14
,
The function mod(x,y) gives the remainder on dividing the real number x by y.
mod(7 , 4) 3 mod(3 , 4) 3 mod(5 , 4) 1
If you need a function that is always positive, you can define:
Mod(x , y) : mod(x , y) + y(x < 0)
Mod(7 , 4) 3 Mod(3 , 4) 1 Mod(5 , 3.5) 2
The function permut(n,k) gives the number of ordered k-tuples using
elements from a set with n elements:
permut(5 , 3) 60 permut(50, 25) 1.961 10
39
5!
60
50!
1.961 10
39
(5 3)! 25!
The function combin(n,k) gives the number of subsets with k elements from a
set with n elements:
5!
combin(5 , 3) 10 10
3!(5 3)!
n!
combin(n,k) can give results where the expression fails:
(n k)!k!
171! 171!
combin(171 , 2) 14535
but:
14535
169!2! 169!2!
The functions in this subsection only work numerically.
1.9.2 Functions for rounding and truncating
The function ceil(x) gives the least integer which is x:
ceil(2.78) 3 ceil 3 ( ) 3 ceil(2.2) 2 ceil(2.8) 2
The function floor(x) gives the greatest integer which is x:
floor(2.78) 2 floor(2.78) 3
46
The function round(x,n) rounds x to the nearest real number with n decimals:
round(2.78, 1) 2.8 round(e, 5) 2.71828 round(2.78) 3
If the second argument is missing, it's assumed to be 0:
round(2.78) 3
If the second argument is negative, the number is rounded to that many zeros:
round(344557, 3) 345000
trunc(x) gives the integer part of a real number by removing the fractional part:
trunc(2.78) 2 trunc(2.78) 2
Some times you may need the integer quotient:
div(x , y) : trunc


x
_

312
124.8 div(312 , 2.5) 124

y
,
2.5
1.9.3 Prime numbers
Prime number factorization
You can factor a number using the symbolic keyword factor. Examples:
92 factor 2
2
23 490 factor 257
2
Alternatively, you write the number you want to factor. From the Symbolic
menu, choose Derivation Format and then Horizontally to get the
factorization to the right of the number. Examples:
Number Factorization Number Factorization
123456 2
6
3643 19283618171 54488893539
Then, of course, you can use the command factor do decide whether a given
number is a prime or not:
30 is not a prime:
30 factor 235
2371 is a prime:
2371 factor 2371
Mersenne numbers
Mersenne numbers are numbers of the form 2
n
-1. Their properties with
respect to factorization have been studied extensively. You find:
Number Factorization Number Factorization
2
13
1 8191 2
41
1 16451135313367
2
17
1 131071 2
61
1 2305843009213693951
2
18
1 3
3
71973 2
89
1 618970019642690137449562111
47
Eratosthenes' sieve
To list the prime number less than a given number N, you can use
Eratosthenes' sieve. Here is a program for this:
( ) for i 2 .. n 1 +
So, here is a list of the
Erathostenes n
primes less that 4000:
n
for k 2 ..
i
Erat : Erathostenes(4000)
S
k i
1

m 0
for j 2 .. n
if S
j
= 0
Erat
P
m
j
m m + 1
P
0
0
1
2
3
4
2
3
5
7
11
The prime number function
Given the vector x above that contains all the prime numbers less than 4000,
we can define prime number function for values up to 4000 as follows:

Prime(n) :

Erat n Prime(3200) 452 Prime(3800) 528


i : 1 .. 40 M
i 0
: 100i M
i 1
: Prime
(
M
i 0
)
, , ,
M
T

0 1 2 3 4 5 6 7 8 9
0
1
0 100 200 300 400 500 600 700 800 900 1
0 25 46 62 78 95 109 125 139 154
You can scroll the table in order to find the value you want.
Fibonacci numbers
The sequences of Fibonacci numbers can be programmed as follows:
Fibonacci n ( ) : x
0
1
x
1
1
Then you get the first 60
for i 2 .. n 1
Fibonacci number by writing

( )
and then
x
i
x
i 1
+ x
i 2
f : Fibonacci 60

f=. I omit it here, to save space.
x
48
1.9.4 Numbers in various number bases
Conversion from decimal to other number systems
Mathcad can show numerical results in four different base systems: Decimal,
octal, hexadecimal and binary. If you want to see what a decimal number
looks like in hex, oct or bin, you just write it on the screen and press =. Then
you double click on the result to get the dialog box for numerical format. At
the option Display Style - Radix you can choose from a list of radices:
Decimal, Hexadecimal, Octal and Binary.
Examples:
234.4 0ea.666h 3456 6600o 256 100h
10 0ah 10.1 12.063146314631463o 10 1010b
Conversion from hex, oct or bin to decimal
Conversion from hex, oct or bin to decimal is even simpler: Just write an h, o
or b after the number and press =. Notice, however, that you have to put a
zero in front of a hexadecimal number that otherwise would have started with
one of the letters a-h. This is in order to distinguish it from a variable name.
Examples: 0eah 234 101b 5 123.45o 83.578
You can also combine the two methods to go directly between hex, oct or bin:
0ea.ah 352.5o 6600o 0d80h 100h 400o
Exercises
1. A pair of prime number twins is a pair of prime numbers whose difference is
2. Write a program that for a given natural number n lists all prime number
twin pairs less than n in a matrix with two rows. Build on the function
Eratosthenes in the text above.
2. A Pythagorean triple is a a triple (x,y,z) of integers such that x
2
+y
2
=z
2
.
Write a function that, for a given n, lists all Pythagorean triples whose
members are all at most n:
a. Write a function In(x,X) which, for a given number x and a vector X,
returns -1 if x is not a component of X, and otherwise returns the first n such
that x=X
n
.
b. Write a function that lists the the Pythagorean triples: For every pair (a,b)
such that a<bN, use the function In to see if a
2
+b
2
is a square, i.e. a member
of the vector of squares.
c. Program a function that extracts only those columns of a matrix that are
non-proportional. Use the fact that two three dimensional column vectors are
proportional if and only if their vector product is zero.
49
1.10 Sums and products
The sum and product symbols are built into Mathcad. By definition,
n n n

x
i
=

x
k
= x
1
+ x
2
+ .. + x
n

x
k
= x
1
x
2
.. x
n
i 1 k 1 k 1
If you use Postscript, the summation sign may have a rectangle in its lower
part. To get rid of that you have to use another printer driver.
1.10.1 The summation symbol
In Mathcad, the summation symbol comes in three variations:
Name: Summation Range sum Vector sum
Screen
image:
Icon:
Keyboard
shortcut
Typical
use:
Examples:



[Ctrl][Shift]4
$
General Sum with
predefined
index range
variable
10

i
2
385 i : 1 .. 10
i 1

i
2
385
i
n

i
2
expand
1
factor

6
n(n + 1)(2 n + 1)
i 1

[Ctrl]4
Sum of the
componen-
ts of a
vector.

1
_


3

v :

7


5



3
,

v 19
50
1.10.2 The product symbol
Similarly, the product symbol comes in two variations:
Name: Product Range
product
Screen


image:
Icon:

Keyboard [Ctrl][Shift]3 #
shortcut
Typical General Product with predefined
use index range variable
10
Examples:

i 3.629 10
6
i : 1 .. 10
i 1
i 3.629 10
6

i
Exercises
Compute the following sums and product. You get the infinity symbol by
pressing [Ctrl] Z. Simplify the expression when needed.
n 20
1

1
1
_

a k
n

i
i 1 k 2

k
3
,
n 1 i 1

1
+
n n
1

( )
i 1

k
2

k
3

i
i 1 k 1 k 1 k 1
k
2

1 1

( )
k

ln


1
_


n!
k 1
k
3
k 1
k
2
n 1

n
,
n 1
1000
n
51
1.11 Three dimensional plots
1.11.1 The graph of a function of two variables
Say you want to draw the graph of the function:
( F x , y) : cos
(
2 x
2
y
2
+
)
The simplest way to do this is to compute a nested array of coordinate matrices
that can be used to draw a quadrangle mesh by means of the function
CreateMesh:
M : CreateMesh F ( )
Then you can plot the surface by choosing Insert - Graph - Surface Plot from
the menu. Alternatively, press [Ctrl]2. Then write M is the placeholder:
M
With just one argument for CreateMesh Mathcad chooses the mesh in its own
way: Both the x interval and the y interval is [-5,5], and the number of
subdivision points in each direction is 20. However, you can define your own
grid by adding more arguments. One possible syntax is
CreateMesh(F,a,A,b,B,Nx,Ny), where [a,A] and [b,B] are the x and y intervals,
and Nx and Ny are the numbers of subdivision points in each direction. E.g.
M2 : CreateMesh(F, 4 , 4 , 5 , 5 , 20, 50)
M2
52
There is also a lot of formatting options for surface plots. You can access them
by double clicking on the diagram to get a dialogue box. I shall not go into
details. You can refer to Mathcad's documentation or try out the possibilities.
1.11.2 Contour plots and 3D bar charts.
You can also draw a contour plot of a function of two variables. You
proceed as before to produce a matrix of function values over a grid of
points. But then you choose Insert - Graph - Contour Plot (or press
[Ctrl]5) from the menu or press [Ctrl] 5. With the example above you get:
M2
You can also draw a 3D bar chart by choosing Graphics - Create 3D Bar
Chart from the menu. With the example above:
M2
53
1.11.3 Parameter surfaces
You can use the Surface Plot tool with another type of function argument than
a scalar function of two variables. Say you want to draw a sphere. A sphere is
defined by means of three parameter
( ( ) y u , v) : sin(u)sin v ( ( ) x u , v) : sin(u)cos v ( ( ) z u , v) : cos u
Equivalently, you can define a 3 D vector function of two variables:

sin(s) cos t ( )
_
(

( )

R s, t) : 2

sin(s)sin t

cos s ( )
,
Then define:
, , 0 , 2, 10, 20) or, alternatively
M1 : CreateMesh(R 0 ,
M2 : CreateMesh(x , y , z, , 0 , 2, 10, 20) 0 ,
Then use Insert - Graph - Surface Plot. The result is:
M1 M2
You can draw several such surfaces in the same diagram. Here is a torus:
( ))cos u

(4 + cos v ( )
1
T u , v) :

(4 + cos v ( )
1
(

( ))sin u
1

sin v ( )
]
M3 : CreateMesh(T, 0 , 2, 0 , 2, 40, 10)
Then to draw the sphere and the torus in the same diagram, define either
M4 : stack(M1, M3)
or
M5
0
: M1
0
M5
1
: M3
0
54
M4
M5
Notice that the variables M1, M2 and M3 are actually nested arrays with one
component, which is itself a nested array with three component, each
component giving a matrix of coordinates, which is used to draw the
quadrangle mesh.
You don't have to start with a function and draw its graph in order to use the
surface Plot tool. Say you want to draw a surface of revolution generated by
rotating a polygon P in the plane about the y axis. Then you can write a
program to compute the necessary coordinate matrices:
( ) RevSurf(P, N) : M last P
for m 0 .. M
for n 0 .. N
v
n
2

n
N
x
m n
Re P
m
( )
,
( )
cos v
n
y
m n
Re P
m
( )
,
( )
sin v
n
z
m n
Im P
m ,
( )

x
_


y


z
,
For example, here is a "circular hut"
M6
0
: RevSurf
(
( 0 1 1 + 2i )
T
, 20
)
M6
1
: RevSurf
(
[ 3i 1.5(1 + i) ]
T
, 40
)
55
M6
Exercises.
1. Draw the graphs of the following functions of two variables:
4
3
( z x , y) :
2
(
(
1 + x
2
+ 2y
2
z x , y) :
(
x
2
+ y
2
)
4 x
2
+ y
2
)
z x , y) :
1
z x , y) :
x y
(
x
2
y
2
)
z x , y) : 1 + cos
(
x
2
+ y
2
)
( (
(
( x
2
+ y
2
1 x
2
+ y
2
z x , y) : xy
z x , y) : e
y
cos x ( ( )
z x , y) :
x y

x + y
(
( z x , y) : x
2
x
4
y
2
2 2
Try various formatting options.
2. Draw the surfaces the following parameter function:

ucos v ( )
_
R u , v) :

usin v (

( )



cos 4u ( )
,
3. If a function f(x,y) depends only on
x
2
+ y
2
, it is symmetric with the z axis
as a symmetry axis. Write a program to draw the graph of f over a circular
region, using cylindrical coordinates. Then draw the graphs of the following
functions over a circular region:
( ( f x , y) : x
2
+ y
2
g x , y) : cos
(
4 x
2
y
2
+
)
56
1.11.4 Space curves
Space curves can be drawn in a manner similar to surfaces, but using Insert -
Graph - 3D Scatter Plot. There is a function CreateSpace similar to
CreateMesh that can be used to create three coordinate vectors that Mathcad
can use to draw a space curve. Say you want to draw a circular helix, which is
defined by the following vector function of one variable:

cos t ( )
_
f t ( )

Then define
( ) :

sin t


0.5t

,
M1 : CreateSpace(f , 0 , 8, 80)
and choose Insert - Graph - 3D Scatter Plot from the menu. Write M1 in the
placeholder.
M1
Exercise. Draw the space curves defined by the following vector functions:

sec t

cos t ( )
_

t + 1
_

( )
_


( )

t
2
1



tan t

sin t
( )


4



sin 2t ( )
,

2t
,


3
t


2 ln(t + 1)
_


t
2


ln
(
t
2
+ 1
) _


3t
3 t
+ 1
_


atan t ( )


t
2


1
2
+ t


t
2
,


2
,
57
1.11.5 Drawing several three dimensional objects
You can draw 3D objects of different kinds in the same diagram. You can
mix, surfaces, space curves and Contour plots. Here are a couple of
examples:
Example:
A sphere with radius 2: A torus:
R2 : 4 r2 : 0.5

cos(u)cos v ( ))cos v ( )
_
(R2 + r2cos u ( )
1
(

( )


T u , v) :


(R2 + r2cos u ( )
1
1
R u , v) : 2

cos(u)sin v ( ( ))sin v
( )
,
r2sin u

sin u ( )
]
M
0
: CreateMesh

R ,

,

, 0 , 2, 10, 20

_

2 2
,
0
M
1
: CreateMesh(T, 0 , 2, 0 , 2, 10, 40)
0
( )
_
A circular helix:

2.5cos t
H t ( ) :

2.5sin t

( )



0.2t 2
,
M
2
: CreateSpace(H, 0 , 8, 80)
0
M
For the various formatting options, refer to Mathcad's documentation. Or try
them by double clicking on the diagram.
58
You can also use the same surface with different formats to get special
effects:

ucos v ( )
_

F u , v) :

usin v
(
( )

M2
0
: CreateMesh(F, 2 , 2 , 2 , 2 , 20, 20)
0


u
2
,
M2
1
: M2
0
M2
The three dimensional graph tool is very fascinating, but it is beyond the
scope of this book to explore its possibilities further.
Exercises.
1. Draw two toruses. The second copy goes through the center of the first.
2. Draw a torus which intersects a sphere.
3. Draw three identical ellipsoids that have their longest axis parallel to the
respective coordinate axes.
4. Draw Archimedes' diagram: A sphere, a cylinder and a cone, all with the
same diameter. Make the surfaces transparent, so that all surfaces are visible.
5. Draw the graph of a function, say
f x , y) : x
2
+ y
2
and its tangent plane
(
in some point. Write a suitable program that automates this job.
6. Draw a space curve, say a circular helix, and a tangent line in one of its
point. Write a suitable function that automates this job.
59
1.12 Text
1.12.1 Text blocks
One of Mathcad's strongest points is its flexibility when it comes to mixing
mathematical formulae and text. You are not restricted to having just text or
just formulae in one row, as you are in most other mathematics packages.
All of this book was written entirely with Mathcad, except for the index and
the table of contents. Actually, the book is just a collection of Mathcad files. .
You start a text region by pressing " ([Shift] 2) or by choosing Insert - Text
region from the menu. Then you just start typing. The text will continue till
you hit the right margin. If you need to have a narrower block than this, it is
recommendable to adjust the size of the block after you have finished the text.
You might be tempted to press [Enter], but don't - that would make it more
difficult to change your mind if you want the block to have yet another size.
You can force a text region to occupy the whole page width from the left to the
right margin: While the cursor is in the block, click the right mouse button,
choose Properties and click on the tag Text. Then check Occupy Page
Width.
It is possible to write a formula in the middle of a text region by choosing
Insert - Math Region from the menu. Or you can press [Ctrl] a. After having
written the formula, you must click outside the formula to continue writing
text. If the formula was the last thing you wrote in the text region, you have to
click before the formula and then use the [End] key. It is often more
convenient to write more text first and then insert the formula afterwards.
You can format text regions or part of them in various ways using the
following buttons on the formatting toolbar.
I shall not go into details about this, you should consult Mathcad's Reference
Manual or simply test the possibilities. They work as you would expect them
to work, based on experiences you may have from other Windows programs.
Notice, however, that you have the opportunity to make subscript and
superscript in a text region. Select the region that you want to subscript or
superscript, click the right mouse button, and choose Subscript or
Superscript.
Special characters in a text block
You may often want to use mathematical symbols that are not represented on
the keyboard. You have to use special key sequences followed by Ctrl/G,
which translates the sequence to the sign you want: The most common special
characters are as follows:
60
Logical symbols "[Ctrl]G $ [Ctrl]G

[Ctrl]G

[Ctrl]G

[Ctrl]G \ [Ctrl]G

[Ctrl]G

[Ctrl]G

[Alt/0222] [Ctrl]G

[Ctrl]G

[Alt/225 [Ctrl]G or [Alt/0223 [Ctrl]G
Set Theory

[Ctrl]G

[Alt]128 [Ctrl]G or [Alt]0199 [Ctrl]G

[Ctrl]G

[Ctrl]G

[Ctrl]G
' [Ctrl]G

[Ctrl]G

[Ctrl]G

[Ctrl]G

[Ctrl]G

[Ctrl]G
Comparison

[Ctrl]G

[Alt]0179 [Ctrl]G @ [Ctrl]G

[Alt]167 [Ctrl]G

[Alt]0185 [Ctrl]G [Alt]0187 [Ctrl]G
Open intervals

[Ctrl]G

[Ctrl]G
Binary operations
[Alt]0215 [Ctlr]G

[Ctrl]G

[Ctrl]G
[Alt]0215 Write t and erase the t.

[Alt]0184 [Ctrl]G

[Alt]250 [Ctrl]G
Arrows

[Alt]0171 [Ctrl]G

[Alt]0173 [Ctrl]G

[Alt]0174 [Ctrl]G

[Alt]168 [Ctrl]G
|
[Alt]0189 [Ctrl]G
You can also copy symbols from a Quick Sheet: Choose Help - Resource
Center - Quick Sheets and Reference Tables - Extra Math Symbols from th
menu. Use the right mouse button to copy a symbol from the Quick Sheet.
61
1.12.2 Text variables
Mathcad has a built-in data type for text strings. You can define a variable to
have a text string constant as its value. You just start with a quotation sign "
right after the assignment operator :=.
text1 : "This " text2 : "is a " text3 : "text."
Mathcad has the following functions for manipulating strings:
concat(S1,S2) joins S1 and S2 to a new string
concat(text1, text2) "This is a "
strlen(S) gives the number of characters in the string S:
strlen(text1) 5
search(S1,subS,m) gives the start index for the substring subS in the string S
from character number m on:
search(text1, "hi" , 0) 1
substr(S,m,n) gives the substring of length n starting with character number m
in the string S:
substr(text1, 1 , 2) "hi"
str2num(S) converts the string S to a number. S may contain digits, decimal
point, the imaginary unit and numbers of the form 2e4. Spaces are ignored.
str2num("1+3i" ) 1 + 3i str2num("1e34" ) 1 10
34
num2str(t) converts a number to a string.
( )
"1e+307" num2str
(
110
34
)
"1e+034" num2str
str2vec(S) converts a string to a vector of the corresponding ascii codes.
str2vec(" abc" )
T
( 32 97 98 99 230 248 229 )
vec2str(v) converts a vector of ascii codes to the corresponding string.
vec2str
(
( 32 97 98 230 248 )
T
)
" ab"
Mathcad's documentation mentions assignment of Mathcad variables to
filenames as the main application of text variables. You can also use them to
write text on a two dimensional graph, as I will discuss briefly in the following
subsection.
62
1.12.3 Text on a two dimensional graph
Mathcad has not built-in the possibility to write text on a two dimensional
graph. You have to write your own functions to do that. I have done so. The
necessary functions are hidden in the areas below
Font information
Functions for text on graphs
These functions are in the file TextFunctions.mcd, and can be copied from
there. The main function is the following:
Write(text, loc, it, sp, wi, he, ha, va, an)
Here,
text is the text to be written. This is either a single text or an array of texts
loc is the location of the anchor point of the text expressed as a complex
number. This is either a single complex scalar or an array of complex
scalars of the same dimension as text.
it is a factor giving the italicization of the text.
sp is a number giving the space between the characters
wi is a factor that determines the width of the characters
he determines the height of the characters
ha is the horizontal alignment of the text relative to the anchor point: 0,1
and 2 mean left, center and right respectively
va is the vertical alignment of the text relative to the anchor point: 0,1 and
2 mean bottom, center and top respectively.
an is the angle between the base line and the x axis.
Example. Define two write functions
write1(text , loc) : Write(text , loc, 0.1, 0.2, 0.3, 0.3, 0 , 0 , 0)
write2(text , loc) : Write(text , loc, 0 , 0.2, 0.15 , 0.2, 0 , 0 , 20deg)
If you need to write subscripts, write them between a pair of underscores. If
you need to write superscripts, write them between a pair of ^'s:
and draw the text:
TT : write1("This is a text." , 0)
TS : write2("Here is an equation: x_1_^2^+a x_1_+b = 0" , 0.5i)
0
1
2
Im TT (
Im TS (
)
)
0 1 2
Re(TT) , Re(TS)
63
Notice that for this to work, you have to use the trace type Draw for the text,
and you have to set the right endpoint of the x-axis interval manually (and
possible more endpoints, depending on the parameter an), because the
functions uses distant points that have to be cut.
The function Write has been written so that it accepts arrays as the arguments
text and loc. This useful when you need to draw a number of texts at various
locations.
Here is an example, where I draw a quadrangle and name vertices:
:



0
2
_



2 i +



i



0
,
:

0.3 0.3i
2.2 + 1.1i
2.2 0.3i
0.3 + 1.1i
_

"A"
"C"
"B"
"D"
_

,
T : loc
Q
Te : write1(T, loc)
2
0
1
Im Q ( )
Im Te ( )
2 4
1
( ) , Re Te Re Q ( )
In version 2000 you can also write the texts outside of the graph and drag them
into the graph afterwards. This works fine for a modest number of text whose
locations is judged by the eye. If you need to compute the locations of the
texts mathematically, the method above is probably preferable. Here is the
same quadrangle with the text inserted by this method:
2
0
C
D
A B
2
Im Q ( )
4
Re Q ( )
64
1.13 Animation
Animations are very useful while teaching and learning mathematical
concepts. Once you have seen an animation of a cycloid, you never forget how
it is defined.
In Mathcad, the key to animation lies in the variable FRAME. This is a
predefined variable which works like a range variable with integer values. But
you can use it as a variable last value for another range variable.
Say you want to draw the trajectory of a projectile which is thrown with the
initial speed v0 at elevation angle .:
v0 : 100 : 45deg g : 10
The the trajectory can be described by a set of parameter functions
1
( ) : v0cos ( ) : v0sin x t ( )t y t ( )t
2
gt
2
Then you can draw the trajectory and the projectile at a given time T as
follows:
T : 10 t : 0 , 0.1.. T
200
y t ( )
y T ( )
0 200 400 600 800 1000
( ) , x T x t ( )
Now, define
T : FRAME t : 0 , 0.1.. T
and write
y(t),y(T)@x(t),x(T) as before
200
y t ( )
y T ( )
0 200 400 600 800 1000
( ) , x T x t ( )
Notice that you have to fix the interval endpoints manually, since you don't
want the axis intervals to change. Now, click on the diagram and choose View
- Animate from the menu. You get the following dialogue box:
65
x T
Say you change the To: field to 15 to get pictures of the first 15 seconds. You
have to select the part of the diagram that you want to include in the animation
(maybe you have to move dialogue box to do this). Then choose Animate.
button. This will give an animation of the projectile's trajectory.
Mathcad will then create an avi-file, which can be run using the
When Mathcad has produced its avi-file, you can store it for later use by
pressing the Save As button. You can create a hyperlink to this file in the
following way: Click on the graph, and choose Insert Hyperlink. Then write
the name of the avi-file. After this step, you can double click on the animation
to make it run.
Here is another example - the cycloid:
A point on the cycloid:
T : FRAME t : 0 , 0.05 .. T
( ) : (t sin t ( ) : 1 cos t x t ( )) y t ( )
An approximation
N : 20 n : 0 .. N z
n
: exp

i

n

_
+ i + T
to the circle:

10
,
A radius:
r :


i + T
_

( )
,
( ) + iy T
5
0 5 10
y t ( )
Im z ( )
Im r ( )
15
( ) , Re z ( ) x t ( ) , Re r
66
2 Algebra
2.1 Tools for symbolic algebra
Mathcad has two ways to do symbolic mathematics:
Either, you do it from the Or you do it from the Symbolic
Symbolics menu. Choose toolbar. Press the icon
Symbolic to get the
following menu:
to get the following palette:
The two ways to do symbolic mathematics give much the same results, but
also have some significant differences in the ways they can be used. The
symbolic toolbar is generally the most useful tool, and computations produced
this way will be recalculated if they are edited. Using the menu has the
advantage that it can be used on a subexpression, but the results will not be
recalculated if you edit the original expression. An example:
(a + b)
2
+ (a + 1)
3
expand , a 4 a
2
+ 2 ab + b
2
+ a
3
+ 3 a + 1
(a + b)
2
+ (a + 1)
3
expands to
(a + b)
2
+
(
a
3
+ 3 a
2
+ 3 a + 1
)

Here, in the first version you use the button
Alternatively, you can press [Ctrl] [Shift] [Period] and then type expand,a
In the second version you have to let the blue frame include the expression
(a + 1)
3
before you choose Symbolic - Expand from the menu.
67
2.2 Algebraic expressions
2.2.1 Evaluating an expression.
In section 1.3.2 you've already seen how algebraic expression can be evaluated
by using the symbolic evaluation operator instead of the numerical
evaluation operator =. Use [Ctrl][Period] or the button marked on the
Symbolic or Evaluation toolbar.
2 3 17
+
3 4 12
Here is an alternative way: Write the expression, and choose Symbolics -
Evaluate - Evaluate symbolically from the menu. Alternatively, you can
press [Shift] [F9]:
2 3 17
+
yields
3 4 12
To get the result in this format, you have to choose Symbolics - Evaluation
Style - and then check Horizontally and Show Comments.
Notice that the frame consisting of the horizontal and the vertical editing bar
(let's call it the editing frame) has to be expanded to include the whole
expression on the left for this to work - Mathcad will only evaluate whatever is
above the horizontal editing line. This makes it possible to evaluate not only
the whole of an expression, but also only part of an expression:
1 1
1 1
1 1
+
yields
+
when
+
is in the frame

1
+
1
_
12

7
_
12
3 4



3 4
,

12
,
1 1
12 1
1
+
yields
+
when is in the frame
1 1 12
7 12
1 1
+ +
3 4 3 4
1 1
151
+
yields when the whole expression is in the
1 1 12
84
frame.
+
3 4
1 1 151
You should compare this to
+
1 1 12 84
+
3 4
Using the menu gives you the opportunity to evaluate only part of an
expression, using the toolbar does not.
68
2.2.2 Simplifying an expression
To simplify an expression you can write it, see that the editing frame contains
exactly what you want to simplify and then choose Symbolic - Simplify from
the menu:
When the whole expression is within the frame,
x
2
3 x 4
+ 2 x 5
simplifies to
3 x 4
x 4
x
2
3 x 4
When only the expression is in the frame.
x 4
x
2
3 x 4
+ 2 x 5
simplifies to
x + 1 + 2 x 5

x 4
If you forget to expand the frame at all, simplification will do nothing:
x
2
3 x 4 x
2
3 x 4
+ 2 x 5
simplifies to
+ 2 x 5
x 4 x 4
when the cursor is on the number 5, as it is when you have just written the
formula.
There is a toolbar analogue of this: Press the button marked [simplify] on the
Symbolic toolbar. You get:
x
2
3 x 4
+ 2 x 5 simplify 3x 4
x 4
With the toolbar can only simplify the whole expression - not just a part of it.
This is a general principle: Use the menu when you need to manipulate only a
part of an expression, otherwise use the toolbar..
Exercises. Simplify the following expressions:
a
2
sin x ( )
2
x + 2x + 3 x 5 x atan(tan x ( )
2
+ cos x ( ))
tan(atan x ( ))
69
2.2.3 Expanding an expression
Expanding an expression means to transform a short but possibly complicated
expression into a longer expression with less complicated terms. To do this
with Mathcad, write the expression, make the editing frame include the part of
the expression that you want to expand, and choose Symbolics - Expand.
Examples:
With
(a + b)
2
in the frame.

(a + b)
2
1
]
(a b)(a bc)
expands to

(
a
2
+ 2 ab + b
2
)
(a b)(a bc)
With
(a + b)
2
(a b)
in the frame.

(a + b)
2
(a b)
1
]
(a bc)
expands to (
a
3
+ a
2
b a b
2
b
3
)
(a bc)

When the whole expression is in the frame.


(a + b)
2
(a b)(a bc)
expands to
4
a a
3
bc + a
3
b a
2
b
2
c a
2
b
2
+ a b
3
c b
3
a + b
4
c
Just as with simplification, you use the button marked expand on the toolbar to
expand an expression. Alternatively, press [Ctrl] [Shift] [Period], and type the
word expand in the placeholder.
(a + b)
2
(a bc) expand a
3
a
2
bc + 2 a
2
b 2 ab
2
c + b
2
a b
3
c
Expand can take an expression as a second argument. This will indicate which
factor that is not to be expanded:
(a + b)
2
(a bc) expand , (a + b)
2
(a + b)
2
a (a + b)
2
bc
Exercises. Expand the following expressions:
(x + y)
5
sin(x + y) sin(x + 2y) tan(x + y) e
x+y
ln
(
x
2
2yz
5
)
cos(5x)
70
2.2.4 Factoring an expression
Expanding an expression is in a sense a trivial thing to do, once you know a
few rules. The converse operation is far less trivial, and may not even be
possible in principle. Mathcad has a menu choice for it: Symbolics - Factor.
Example:
x
3
4 x
2
+ x + 6
by factoring, yields
(x + 1)(x 2)(x 3)
As you might expect, there is an alternative button marked [factor] on the
Symbolic toolbar that does the same as the menu choice, but only for the
whole of an expression:
a b + a c factor a(b + c)
The keyword factor also works on integers, where it produces a prime number
factorization, as you have seen in section 1.9.3
2
30
1 factor 3
2
71131151331
If you use factor on a sum of fractions, you get a single fraction:
1 x 2 x
(
2 x
2
x + 2 + x
3
)

+ + factor 3
x 1 x + 3 x + 2 [ (x 1)(x + 3)(x + 2) ]
Mathcad tries to factor over the rationals.
x
2
2
is irreducible over the
rationals, so you get just:
x
2
2 factor x
2
2
. However, you can add a
radical as a second argument to factor to get
x
2
2 factor, 2
(x + 2)

(x 2) . If you use the complex unity i


(which is written as 1i) or
1
as the radix, you can get:
x
2
+ 1 factor x
2
+ 1 x
2
+ 1 factor, 1 (x + i)(x i)
Exercises.
1 Factor the following expressions using either method:
a
2
+ 2 ab + b
2
x
2
+ 1 x
3
4 x
2
+ x + 6 x
9
1 2345345
2. Expand
(x + 1)(x 2)(x 3)
. Then factor the result,
x
3
4 x
2
+ x + 6
when
x
3
4 x
2
is in the editing frame, and when

x
3
4 x
2
+ x
is in the frame.

3. Factor
x
2
+ 4
over Q[
2
].
71
2.2.5 Collecting on a subexpression
Suppose you have an expression
4
a a
3
bc + a
3
b a
2
b
2
c a
2
b
2
c a
2
b2 + a b
3
c b
3
a + b
4
c
and you want to write this as a polynomial in one of the variables, say a. Then
you write the expression, put the cursor on any occurrence of the variable a
and choose Symbolic - Collect on subexpression. The result is the following:
4
a a
3
bc + a
3
b a
2
b
2
c a
2
b
2
c a
2
b2 + a b
3
c b
3
a + b
4
c
by collecting terms, yields
a
4
+ (bc + b)a
3
+
(
2b 2 b
2
c
)
a
2
+
(
b
3
c b
3
)
a + b
4
c
You can use the variable b instead of a:
4
a a
3
bc + a
3
b a
2
b
2
c a
2
b
2
c a
2
b2 + a b
3
c b
3
a + b
4
c
with b in the frame by collecting terms, yields
b
4
c + (a c a)b
3
2 a
2
b
2
c +
(
a
3
c + a
3
2 a
2
)
b + a
4

The button marked collect on the Symbolic Toolbar work in much the same
way. Supply the subexpression as a second argument after a comma:
x
2
y
3
+ x
3
y
2
+ x
4
y
3
+ x
3
y
5
collect , x x
4
y
3
+
(
y
2
+ y
5
)
x
3
+ x
2
y
3
x
2
y
3
+ x
3
y
2
+ x
4
y
3
+ x
3
y
5
collect , y x
3
y
5
+
(
x
2
+ x
4
)
y
3
+ x
3
y
2
Exercise. Do the collect operation on the following expressions:
( )
2
x
2
+ cos x ( )
2
x
8
with cos(x) in the frame
cos x ( )x
2
+ cos x
( )
2
x
2
+ cos x ( )
2
x
8
with x in the frame
cos x ( )x
2
+ cos x
x
2
y
3
+ x
3
y
2
+ x
4
y
3
+ x
3
y
5
with the cursor on x
Repeat the exercise with the [collect] button on the Symbolic toolbar.
72
2.2.6 Partial fractions
One of the examples of factorization above was:
1 x 2 x
(
2 x
2
9 x 6 + x
3
)

+ factor
x 1 (x + 3) x + 2 [ (x 1)(x + 3)(x + 2) ]
Sometimes you need to go in the other direction, e.g. when you integrate a
rational function. For this, you have the menu choice Symbolics - Variable -
Convert to Partial Fractions. You have to place the cursor on the variable
that is to be considered as the variable of the expression. Therefore the
expression may involve one or more parameters in addition to this variable:

(
2 x
2
9 x 6 + x
3
)
(x 1)(x + 3)(x + 2)
1 3 4
expands in partial fractions to
1 + +
(x 1) (x + 3) (x + 2)
Here is an example with two parameters in addition to the variable x:
1
with the cursor on the x, expands in partial fractions to
(x a)(x b)
1 1
+
[(a b)(x + a)] [(a b)(x + b)]
The function you expand in partial fractions, needs to be a rational function in
the variable, but its parameters can contain transcendental functions:
1
expands in partial fractions to
x
2
sin y ( )
2
1 1

[ 2sin(y)(x sin y ( )) ] ( )) ] [ 2sin(y)(x + sin y
The toolbar analogue of this is the button marked parfrac, and you supply the
relevant variable as a second argument after a comma:
1 1 1
convert, parfrac, x
x
2
a
2
[ 2 a(a x) ] [ 2 a(a + x) ]
Notice that you don't have to perform conversion to partial fractions first, in
order to integrate a rational function. Mathcad will do it implicitly.
73
2.2.7 Substituting an expression for a variable in
another expression
Suppose you have the two expressions
z
2
+
2
and
x + 3
z
and you want to substitute the second expression for the variable z in the
first expression. Then you proceed as follows:
Select the second expression and copy or move it to the clipboard by means
of one the buttons
Then place the cursor on the variable you want to substitute and choose
Symbolics Variable - Substitute from the menu. The result is like this:
x + 3 z
2
+
2
by substitution, yields
(x + 3)
2
+
2
z (x + 3)
Alternatively, use the [substitute] button on the toolbar:
z
2
+
2
substitute, z = x + 3 (x + 3)
2
+
2
z (x + 3)
Suppose you would transform this expression to a single fraction. Then you
could either press the factor button when the cursor is in the last expression
to get:
2 2
(
x
2
+ 6 x + 1
z + substitute, z = x + 3 x + 3 + factor
z (x + 3) (x + 3)
If you are not interested in the intermediate result, you can press the factor
button just after you have written z=x+3:
2
substitute, z = x + 3
(
x
2
+ 6 x + 11
)

z +
z
factor
(x + 3)
You can use a series of toolbar commands in this way.
substitute, z = x + 3
2
2
2
2
z +
factor
x + 6 x + 9 +
z (x + 3)
convert, parfrac, x
74
Subs x
2
x , x + ,
(
D U
x
x
f z
f x f x
g n
1
)
If you need to substitute an expression for another expression in a function
that you are going to use symbolically, you can define the expression as a
function.
2 2
( ( ) : z +
Then
f x + 3) x + 3 +
z (x + 3)
d
2
You can then define
D2(f , x) : ( ) + ( ) g x ( ) ( ) : sin x
dx
2
D2(g , x) 0 h x ( ) D2(h , x) x ( ) : x + sin x
This is useful when solving differential equations
Similarly, for difference equations, you can define:
( ) D1(f , n) : f(n + 2) 4f n
( ) : 2
n
D1(g , n) simplify 0
You can also substitute in an expression by means of the limit operator
Subs(U, x , u) : lim U
xu
This will work fine, except when u contains x:
Subs
(
x
2
, x , t
)
t
2
but
Subs
(
x
2
, x , x + 1
)

gives an error.
In such cases you can go via an intermediate variable:
Subst(U, x , u) : lim lim U Subst
(
2
x
, x , x + 2
)
4 2
x

tttu xttt
Then Subst
(
x
2
, x , t
)
t
2
Subst
(
x
2
, x , x + 1
)
x
2
+ 2 x + 1
So, you can define a differential operator:
( ) :
d
U 2 U
and get
D e
2x

( )
0
dx
or a difference operator:
DD(U) : Subst(U, x , x + 2) 4U
( )
0 DD

( )
x
1
0
and get
DD 2
x

2
]
75
2.2.8 Getting a floating point value from a symbolic
expression.
By default, symbolic Mathcad gives exact results, which means that function
values that are not rational, are not evaluated as a floating point number.
Examples:
1
sin(1) sin 1 2 2 ( ) ( ) atan 1
4
Of course, sometimes you'll want to see a floating point approximation to an
exact value. This can be done by writing the expression and then choosing
Symbolics - Evaluate - Floating from the menu. Remember to have the
editing frame around whatever subexpression you want to evaluate.
( )
floating point evaluation yields
.84147098480789650665
sin 1

floating point evaluation yields
3.1415926535897932385
Alternatively, from the symbolic toolbar, click on the [float] button on the
Symbolic toolbar, and write the number of decimals as a second argument:
float , 40 3.141592653589793238462643383279502884197
sin(1) float , 40 .8414709848078965066525023216302989996226
2.2.9 Polynomial coefficients
Given a polynomial, say
x
3
+ 2x
2
3x + 1
, you may need to operate on
the coefficients. For instance, there is a built-in equation solver Polyroots
that takes this vector as an input to solve a polynomial equation. Write the
equation, place the cursor on the variable, and choose Symbolics -
Polynomial Coefficients from the menu. The result is:
x
3
+ 2 x
2
3 x + 2
has coefficients

_
Notice that the first
(Cursor at an x)

3

component is the
2
constant term.


1
,
Alternatively, you can use the button marked coeffs on the Symbolic
toolbar. The variable of the polynomial is to be inserted as the second
argument:

2
_
x + 2
_

x
2
y
2
+ x + 2 coeffs , x

1

x
2
y
2
+ x + 2 coeffs , y

0


y
2
,

x
2
,

76
2.3 Equations
2.3.1 Solving one equation with one unknown
numerically
The underlying algorithm for Mathcad's numerical equation solver root is the
secant method. Given a function, say:
f x ( ) x
for which you are
( ) : cos x
going to find a zero. The first thing you do, is to find an approximation to a
zero by drawing a graph of the function with
x : 1 , 0.95 .. 4
1 0 1 4
5
5
f x ( )
3 2
x
The graph indicates that you have a zero somewhere in the interval [0,1]. Then
you can choose x=0.5 as a starting point for an iterative search towards a zero.
As you may know, the secant method requires two start values, but Mathcad
will compute a second value based on the first value and the value of the
built-in variable TOL, which is used in the break criteria for some numerical
algorithms. The second value is chosen as x+TOL x if x00. If x=0, it's
chosen to be x+TOL. You define the variable x as 0.5 and use the built-in
function root to compute the solution:
( ) , x) x0 0.739081777771822 x : 0.5 x0 : root(f x
Check the function value:
f x0) 5.616 10
6
(
So, the function value is close to zero. The search loop is broken when the
function value is less than
TOL 1 10
3
Now, define TOL to be less than that
TOL : 10
10
and see what you get:
x : 0.5 x1 : root(f x ( ) 0 ( ) , x) x1 0.73908513321516 f x1
Exercises.
1. Solve the following equations by means of the root function:.
x
( ) = 1 x
2
3x
2
e = 0 3x
2
x 1 = 0 tan x
2. Find the point of intersections between the circle with radius 2 centered at
the origin and the graph of the function sin(x)/x.
77
2.3.2 Solving one equation with one unknown
symbolically
The root function works for any function, even if the solution cannot be
expressed in terms of elementary function. Of course, many equation can be
solved in terms of elementary functions, and for such equations you often want
a symbolic expression for the solution. There is a menu choice for this:
Symbolics - Variable - Solve Variable. The cursor must be on the name of
the unknown variable .
Example:



2
1
p +
1
p
2
4 q
( )
1
1
2
x
2
+ p x + q = 0
has solution(s)

p
2
4 q
( )
1

1
p
1

1

2 2
]
The = sign here looks a little different from the usual evaluation sign. It is
typed using [Ctrl]+. Alternatively, click on the button
to get the Boolean toolbar
The comparison operator is the first
of these.
This symbol is shown as a bold equality sign to distinguish it from the
numerical evaluation operator =. It is used in equations and in logical
expressions to test equality. It also works with arrays. You can consider = to
be a function that returns 1 if the two operands are equal and 0 if they are not:

1 3
_
1 3
_
1 3
_
2 4
_
1 = 2 0 1 = 1 1

=

1

=

0

2 4
,
2 4
,
2 4
,
3 5
,
In these computations, the first = is the bold comparison function, while the
second is the numerical evaluation operator, which returns either 0 or 1 for a
Boolean expression..
Exercises. Solve the following equations symbolically:
sin x ( ) = 1 x
3
1 = 0 x
5
+ 2x
3
x
2
2 = 0 3x
2
x 1 = 0
23

x
3
_

=
53
2x
3
23x
2
+ 86x 1005 = 0

2
,
12
2500x
5
15000x
4
+ 35875x
3
42750x
2
+ 25381x 6006 = 0
x
4
56x
3
+ 251x
2
7x 6 = 0 x
4
56x
3
+ 251x
2
7x 6.0 = 0
78
2.3.3 Polynomial equations solved numerically
For polynomial equations of degree five or higher, we know that the solution
cannot in general be expressed by means of radicals (roots). For such cases,
Mathcad has an equation solver named polyroots, which returns numerical
approximations to the solutions of a polynomial equation of any degree. The
argument to the function is the vector of coefficients of the polynomial,
starting with the constant term: For the example above:

2
__

0

0.5 0.866i
_

0.5 + 0.866i

polyroots


1.414i

2

0


1.414i



1
,

1
,,
Notice that you have to write zero components for the terms that are missing
(i.e. have zero coefficient) in the polynomial.
Exercises.
Solve the polynomial equations from the previous subsection by means of the
function polyroots.
2.3.4 Several equations with several unknown solved
numerically
Mathcad has built-in a generalization of the secant method called the
Levenberg-Marquardt method. It works like this:
Say the problem is to find the intersection between the circle
x
2
+ y
2
= 1
and the straight line y=x + 1/2 in the first quadrant.
First you find approximate values for a solution e.g. by drawing a diagram or
simply guessing. In this case, let's start with.
x : 1 y : 1
Then you write the code word Given in a math region by itself:
Given
and then the equations and conditions that x and y has to satisfy:
2 2
x + y = 1
y x = 0.5
Then you get the result by using the function Find:
79

0.411
_
z : Find(x , y) z


0.911
,
You may check that
( )
2
+
( )
2
1 z
1
z
0
0.5 z
0
z
1
To find the second solution, start with other guess values:
x : 1 y : 1
Given x
2
+ y
2
= 1y x = 0.5 z : Find(x , y) z

0.911
_

0.411
,
You may check that
( )
2
+
( )
2
1 z
1
z
0
0.5 z
0
z
1
In particular, this method can be used to solve a set of linear equations:
x : 0 y : 0 z : 0
Given x y 2 z = 5 2 x y z = 2
x 2y + z = 1 z : Find(x , y , z)

0.667
_
z

1

2.333
,
2.3.5 Linear equations
You just saw how a system of linear equation can be solved numerically by
means of a Given - Find block. Mathcad also has other ways to solve such
systems of equations. Look at the system above again, and define the matrix of
coefficients A and the vector of right-hand sides B:

1 1 2
_
5
_
A :

1 2 1

B :

1



2 1 1
,
2
,
Then use the function lsolve ( which works only numerically. This is
equivalent to computing the matrix inverse of A and multiply by B:

0.667
_
0.667
_
X : lsolve(A, B) X

1

A
1
B

1

2.333
,
2.333
,
80
E t
2.3.6 Several simultaneous equations solved
symbolically

2
_

3
The matrix inversion method from the example
A
1
B


above can be used symbolically:

7



3
,
You may even use matrices with undetermined parameters in the coefficient

t 2
_
matrix: To solve the system tx+2y=2, -tx+3y=-2 define:
D t ( ) :

t 3
,
and use the menu choice Symbolic - Matrix Operations - Invert Matrix to
get the inverse of a matrix with a parameter.

t 2
_
1

3 2
_
( ) :

by matrix inversion, yields
( ) :

D t

t 3
,
(5 t)

t t
,


2
_
Then you can multiply:
E t ( )


2
_


Check:
D t


2
_

2
,
( )

t

2
,

0
,
0
,
However, it's more efficient to use a symbolic version of the Given- Find
block:
Given
Notice that with the symbolic Given-Find block you
don't give start values for the unknown. On the
t x + 2 y = 2
contrary: You have to cancel any previously assigned
tx + 3 y = 2
value of the unknown by defining it recursively to be

equal to itself.. This method will try to solve your



2
_
equations symbolically much the same way as you
Find(x , y)

t

would do it manually yourself, and is not limited to

linear equations. Let's use it on the nonlinear example

0
, above:
Given x
2
+ y
2
= 1 y x =
1
2

1 1
7
1

1
7
_

4
+
4 4 4


0.411 0.911
_
Find(x , y)



1
+
1
7
1

1
7


0.911 0.411
,

4 4 4 4
,
So you got the same solutions.
81
Exercises
1. Solve the following equations by means of the root function:
x
x = e x
3
x
2
x 1 = 0 x
72
2 = 0 x
3
+ 2x
2
+ 10x 20 = 0
2. Solve second and the fourth of the equations above using polyroots.
3. Find the points of intersection between the two circles
x
2
+ y
2
= 1
and
2 2

x
1
_

+

y
1
_

= 1

2
,
2
,
4. Solve the following systems of linear equations numerically and
symbolically:
a.
2x + 4y + 6z = 18
b.
2x + 4y + 6z = 18
4x + 5y + 6z = 24 4x + 5y + 6z = 24
3x + y 2z = 4 2x + 7y + 12z = 40
c.
x + 3y 5z + u = 4
d.
x 2y + 3z = 11
2x + 5y 2z + 4u = 6 4x + y z = 4
2x y + 3z = 10
e.
2x + y + 6z = 18
f.
3x + 6y 6z = 9
5x + 8z = 16 2x 5y + 4z = 6
3x + 2y 10z = 3 x + 16y 14z = 3
g.
x + y z = 7
h.
x y z = 7
4x y + 5z = 4 4x y + 5z = 4
2x + 2y 3z = 0 6x + y + 3z = 4
i.
x + y z = 0
j.
3x + 6y 6z = 9
4x y + 5z = 0 2x 5y + 4z = 6
6x + y + 3z = 0 5x + 28y 26z = 8
82
u
3 Calculus
3.1 Limits
Mathcad has three built-in limit operators. You access them by clicking on the
calculus menu button:
and then one of the buttons
Alternative keystrokes: [Ctrl]+L [Ctrl]+A [Ctrl]+B
The buttons are self explanatory. These operators will help you find most of
the limits you need for functions of one variable. To find a limit, type the
expression and press [Ctrl] [Period] to get symbolic evaluation. Alternatively,
make the editing frame contain the whole expression and choose Symbolic -
Evaluate - Evaluate Symbolically from the menu or press [Shift] F9 . Notice
that you cannot use numerical evaluation. Here are some examples (press
[Ctrl]Z to get ).
n
Example
lim

1 +
1
_

exp 1 ( )
n
n
,
Exercises. Find the following limits:
n x
lim

1 +
x
_

lim
sin(ax)
lim
a 1
n
n
, x0
x
x0
x
x x
lim lim

x0
+
x
x0
x
3.2 Differentiation
3.2.1 The derivative as a limit
You could use the limit operator to find the derivative of a function by means
of the definition of the derivative:
( ( ) f x + h) f x
( D f , x) : lim
h0
h
f x ( ) D f , x) cos x ( ) : sin(ux) D f , x) cos(ux)u ( ) : sin x ( ( ) f x (
83
g x f x
g x f x
f s
3.2.2 The built-in differentiation operator
However, differentiation is a built-in operator in Mathcad. Like so many other
operators in Mathcad, the differentiation operator occurs in two variations in
Mathcad: A numerical and a symbolic version. Both versions are accessed the
same way: Press the icon for the calculus menu:
and then press the button:
Or: Press the question mark ? In both cases you get the symbol
d
d
The two placeholders are of course for the expression and the variable name.
To force a numerical method to be used, you first define the point where the
differentiation is going to take place and then use the operator:
d
f x ( ) s : 1 ( ) 0.540302305868126 ( ) : sin x
ds
d
You can also define the derivative as a function:
( ) : ( )
dx
g 1 ( ) 0.540302305868126
The function g doesn't yet exist as cos(x):
cos(1) 0.54030230586814
which is a little different from the value above. However, as soon as you
evaluate it symbolically, it becomes cos(x):
d
( ) g 1 ( ) : ( ) cos x ( ) 0.54030230586814
dx
Differentiation with respect to a single variable and partial differentiation is
really the same operation from Mathcad's point of view. However, it is
possible to make a differentiation look partial if you want to. You just click on
the expression with the right mouse button. The first line of the menu you get,
is "View Derivative As" which gives you the opportunity to change to partial
derivative. E.g.:
(
2 2
( (
2
f x , y) : x y + y + x y f x , y) 2 xy + y f x , y) x + 2 y +
x y
You can also you the Symbolic menu. Write the function you want to
differentiate, place the cursor on an x and choose Symbolics - Variable -
Differentiate.
( ) by differentiation, yields
2sin x
2
cos x
2
( )
x
However, this won't enable you to directly define the derivative as a new
function, so it is normally better to use the Symbolic toolbar.
84


h6 1 ( )
f x
h x f x
f x f x
Exercises. Find the derivative of the following functions:
sin


x
_

cos x ( )) x
2
cos

_
( )
3
cos(sin x

2
,

x
,
1 cos 2x ( ) +
3.2.3 Higher order derivatives
For the higher derivatives, you have similar options. Press the
button, and then
Alternatively, press [Ctrl] [Shift]? ([Ctrl] [Shift]* on some national
keyboards). The symbolic version can be used for any order:
d
10
( ) : sin 3x f x ( ) ( ) : ( ) 59049sin(3x)
dx
10
h 1 ( ) 8.333 10
3
In the numerical version, this can be used only for n up to 5:
d
5
d
6
( ) : ( ) h5(1) 240.568
is OK, but
h6 x h5 x ( ) : ( )
dx
5
dx
6
h6 1 ( )
gives an error message.
. For higher n's you have to compose more operators.
d
3
d
3
h6_3 x ( ) : ( ) h6_3(1) 102.876476656908
dx
3
dx
3
Notice that this has only 4 correct digits, so you should use symbolic
derivatives whenever possible.
Exercise. Find the derivatives of order two and three of the functions in the
exercises after the previous subsection.
3.2.4 Differential formulae
Mathcad knows the standard rules of differentiation:
( ) + v x ( ) + v x Example.
d
(u x ( ))
d
u x
d
( )
dx dx dx
Exercises. Obtain similar results for the derivatives of:
( )v x
u x
u x ( )
m
( )
n
ln( u x u x ( )
( )
( )
n
v x
u x
( ) )
( )
v x
v x
( )
m
( )
v x
ln
(
u x ( )
b
w x ( )) u x
( )
( )
a
v x ( )
c
)
cos(sin x
85
y
g x g x
y
g x
3.2.5 Differentiation of implicit functions
If y is defined as function of x implicitly by some equation U(x,y)=0, then the
U
x
derivative of y with respect to x by implicit differentiation is given as .
U
y
You can define the following function for this:
_

U

Notice that I've used a non-standard syntax
DImp(U) : simplify

x

for the function simplify. This version

comes from Maple, which Mathcad uses for

U

symbolic computations.

y
,
(
Example:
f x , y) : DImp
(
x
2
+ y
2
1
)

x
f
(
0.5, 1 0.5
2

)
y
This should be compared with:
d
1
( ) : 1 x
2
g1 x ( ) : ( ) x
dx
1
_

(
1 x
2
)

2
,
For the second derivative you get by differentiating implicitly once more:

2
2
1 1


U
_

2
+


2
U
_


U
_

...
1
1


x
2

y
,

y
2
,

x
,
1
1


_ _ _
1
1

+ 2

U


U
1
1
D2Imp(U) : simplify


x y
,
x
,
y
, ]
1

_
3
1

1

y
, ]
(
Example:
f x , y) : D2Imp
(
x
2
+ y
2
1
)

(
y
2
+ x
2
)
3
y
This should be compared with:
d
2
1
g2 x ( ) : ( ) simplify
dx
2


1
_

(
1 + x
2
)

(
1 x
2
)

2
, 1
]
Exercise. Find y' and y", given that a) y
2
=x, b) x
2
-xy+y
2
=7 by implicit
differentiation.
86











3.2.6 Tangent and normal
A curve in the plane can be given either as the graph of a function f, or as the
graph of a pair of parameter functions, which is equivalent to a two
dimensional vector function.
Tangent and normal to a curve
In the functions below, R is either a function of one variable, or a two
dimensional vector function giving a parameter curve.
d _ 1

R t ( )
0
1

1
_

( ) + s

dt

R t
Tan(R , t , s) :

R t

d

1
1
on error

_
+ s


d
R t

( )
,
( )
( )
1
1

dt
,

R t

dt
, ]

d
R t
_ 1

( )
1
1
t

d
R t
_
Nor(R , t , s) :

R t

( ) + s


d
dt

1
1
on error


R t
_

+ s


dt
( )

( )
,
( )
0
1

1
,

R t

dt
, ]
Here are programs that can be used to draw families of tangents and normals.
The parameter F is Tan for tangents and Nor for normals.
Family(R , a , A, N, F) :

dt
A a

_
(t a)

N
,
for n 0 .. N
M F(R , t
X
0 n
M
0 ,
,
Y
0 n
M
1
M F(R , t
X
1 n
M
0 ,
Y
1 n
M
1 ,
t t + dt

X
_


Y
,
, 10)
, 10)
87
R x
f x
T t
f x
f x f x
Example 1. Tangent and normal to the parabola
( ) : x
2
Tan(R , t , s)


t + s
_

Nor(R , t , s)


t 2ts
_


t
2
+ 2 ts
,
t
2
+ s
,
( ) : x T t ( ) : Nor(f , 0.5, t)
2
( ) : Tan(f , 0.5, t) N t
Range variables:
t : 5 .. 5 x : 2 , 1.9.. 2
1
( )
1
N t ( )
1
( )
0 1
( )
0
, N t T t ( )
0
, x
Families of tangents and normals:

X
_

: Family(R , 4 , 4 , 40, Tan)

Y
,
4
2
Y
( )
0
2
2 0 2
X x ,

U
_

: Family(R , 4 , 4 , 80, Nor)

V
,
4
2
V
( )
0
2
2 0 2
U x ,
88
y t
y t
y t

cos t ( )
_

Example 2 An ellipse:
R t ( ) :

t : 0 , .. 2

2sin t ( )
,
32

cos(t) sin t
Tan(R , t , s)

( ) s

_
: Family(R , 0 , 2, 40, Tan)
( ) + 2cos t

2sin t ( )s
,
Y
,

cos(t) 2cos t
Nor(R , t , s)

( )s
_


U

_
: Family(R , 0 , 2, 40, Nor)

2sin t ( ) s
,
V
,
( ) sin t
2
0
2
Y
R t ( )
1
2
V
R t
0
( )
1
2
2 0 2 2 0 2
X R t , ( )
0
, ( )
0
U R t
Exercises. Draw families of tangents and normals to the curves given by the
following parameter functions:

sin t ( )
_


cos t ( ) cos 9t ( )
_
t sin t ( )
3
_


9cos t ( )
_

( )
,

( )
3
,


9 sin(t) sin 9t

t
,
1 cos t

sin t
( )
,
3.2.7 Curvature and evolute
The evolute of a curve given by two scalar functions can be written in the
following way:
Evolute(x , y , t) :

D1
d
x t
_
( )

D2
d
( )
_


dt
,
dt
,

x t

D3
d
2
( )


D4
d
2
( )

_

dt
2
,
dt
2
,
D1
2
+ D2
2
DD
D1D4 D3D2

x t ( ) DDD2
_


( ) + DDD1
,
89
y t y t
y t


x t ( )
d
( )
_


d
2
( ) +


d
( )
_


d
2
x t

dt
, dt
2

dt
, dt
2
Curvature(x , y , t) :
3
2

d
x t
_
2
d
( )

_
2
1
1


( )

+


dt
,
dt
, ]
Example 1. The evolute of a cycloid is another cycloid
( ) : t sin t ( ) : 1 cos t x t ( ) y t ( )
1
Curvature(x , y , t) simplify

_
1


2(2 2cos t ( ))

2
,
1
]

t + sin t ( )
_

Ev(t) : Evolute(x , y , t) simplify



t : 0 , .. 6

1 + cos t ( )
,
16
0 5 10 5 0
2
2
y t ( )
Ev t ( )
1
1 2
( ) , Ev t x t ( )
0
Exercise. Find evolute and curvature of the curves from the previous
subsection.
90
Curvature and evolute for the graph of a function u=f(x)
3
2
CurvatureF(u , x) :


d
2
u x
_
( )

1 ( )

1 +


d
u x
_
2
1

dx
2
,

dx
, ]
(I use

instead of to save space. Press [Ctrl]/ or [Ctrl]*.)
( )

_
2
1
1


d
2
u x
_1

d
u x
_
EvoluteF(u , x) :

_
+


1 +


d
u x ( )
1


dx
( )

u x ( )
,


dx
, ]

dx
2
,]


1
,
Example 1
f x ( ) ( ) : 5cos x
cos x
CurvatureF(f , x) 5
( )

3
_

( )
2
)

2
,
(
1 + 25sin x

( )
(
1 + 25sin x
x sin x
( )
2
) 1
1
cos x
Ev(x) : EvoluteF(f , x)


( )
( )
2
)
1
1
1
( )
1

(
1 + 25sin x

5cos x

5 cos x ( )
]
Exercise. Find curvature and evolute for the function y=sin(x) and y=e
x
Curvature and evolute for a polar curve
( ) :

X1
d
r t
_

( )

_
CurvatureP r, t ( )

X2
d
2
r t

dt
,

dt
2
,
1
2
(
r t ( ) X2
)

(
r t ( )
2
+ 2 X1
2
r t ( )
2
+ X1
2
)
EvoluteP r, t ( )

X2
d
2
r t
_

( )


cos t
1
( ) :

X1
d
r t
_

( )


X4 r t
( )
_ 1

dt
,

dt
2
,

sin t ( )
, ]
r t
( )
_ 1
X4
( )
2
+ X1
2


X4 + X1


sin t
1
( )
2
+ 2 X1
2
r t
( )
, ]
r t ( ) X2

cos t
91
b
Example 2 Cardioid with Evolute r1(t) : 2(1 cos t ( ))
( ))
CurvatureP(r1 , t) simplify 6
(1 + cos t

1
_

( ))

2
,
(2 2cos t

3
( )
2
+
2
cos t
3
1

2
cos t ( )
4
1
3
Ev(t) : EvoluteP(r1, t) simplify
1

2
(cos t ( )
1
( ) + 1)sin t

3
]
Here is the cardioid with its evolute, which is also a cardioid:

t : 0 , .. 2 X t ( )
0
Y t ( )
1
( ) : Ev t ( ) : Ev t
64
90
r1 t ( )
X t ( )
2
Y t ( )
2
+
180
30
60 120
150
210
240 300
330
4
3
2
1
0 0
270
( ) , Y t t , atan2(X t ( ))
Exercises. Find the evolute and curvature of the following curves. Draw the
curve and its evolute in the same diagram
Four-leafed rose:
r2(t) : sin(2t)
Hyberbolic spiral:
r4 t
1
( ) :
t
1
Limacon:
r3 t ( ) ( ) : + cos t
2
Pascal's snail:
r5(t) : acos v ( ) + b
92
h t
h t
f t
3.2.8 Envelope of a family of curves
Given two differentiable functions f and h, then the function F(f,h,x,t) defined
( ( ) x + ( )
defines a family of straight lines: For a given t, by:
F f , h , x , t) : f t
the function F with varying x, gives a line through (t,h(t)) with slope f(t). The
envelope of the family of lines is a curve whose tangent at every point belongs
to the family of curves. It can be shown that the equation of the evolute is:
T

( )
d
( )
d
h t
_
Envelope(f , h , t) :

dt

dt
f t ( )


d d
( ) + h t

f t ( ) ( )


dt dt
,
Example 1.
f t ( ) h t ( ) ( ) : tan t ( ) : 2sin t
F f , h , x , t) : f t ( ) G t , x) : f t ( ) tan t ( ) ( ( ) x + h t ( ( ) x + h t ( ) x + 2sin t
Then you plot the family of straight lines:
and the envelope:
u : 0 , 0.1.. 6.3 t : 1.5, 1.45 .. 4.5 x : 10, 9.9.. 10

2cos t
Env(t) : Envelope(f , h , t) simplify

( )
3
_


2sin t ( )cos t

( ) 2sin t ( )
2
,

2
G t , x)
0 Env u
(
( )
1
2
2 0 2
x Env u
2
2
2
0
( )
0
Exercise. Draw the family of curves defined by f(t)=t
2
and g(t)=t
3.
Find the
enevelope and draw it. Do the same for the functions -t and
2 t
93
but this will only give one of the two solutions.
g x ( ) 0 = solve x ,
2
3
float 5 , 2.0944
Notice that you can try to use the symbolic solve-function:
xmin 4.189 xmin root g t ( ) t , ( : t 4.2 :
Likewise, f must have a local minimum at about 4.2, so you find it by means
of root:
xmax 2.0944 xmax root g t ( ) t , ( : t 2.1 : TOL 10
10
:
From the graph of f (or the derivative g)
maximum at about 2.1, which you can find by means of the function root:
0 2 3 4 5
2
f t ( )
g t ( )
h t ( )
t
t 0 0.1 , 5 .. :
Then draw the graphs of the function and its derivatives:
h x ( )
2
x
f x ( )
d
d
2
sin x ( ) : g x ( )
x
f x ( )
d
d
cos x ( )
1
2
+ :
Start by finding the derivatives:
over the interval [0,5]
f x ( ) sin x ( )
x
2
+
3
2
:
Say you want to find zeros, extrema and points of inflection of the function
3.2.9
)
)
you see that f must have a local
1
Extrema of functions
94
F x
It remains to see if these point are global or just local extrema. You have to
compare with the values at the endpoints of the interval:
f 0 ( ) 0.041 f(xmin) 0.272 ( ) 1.5 f(xmax) 0.413 f 5
The conclusion is that (0,-1.5) is a global minimum, while (xmax,f(xmax)) is
a global maximum point.
There is another way to find local extremes without differentiating, or at
least you leave it to Mathcad to differentiate. Give the independent variable
start value near a local extremum, and use the pair Given - Maximize/
Minimize.
The global maximum:
t : 5 Given t 0 t 5
( tH : Maximize(f , t) tH 2.0944 f tH) 0.413
The global minimum:
( tL : Minimize(f , t) tL 4.189 f tL) 0.272
Points of Inflection
If you are asked to find the points of inflection, then you find the zeros of
the second derivative either by looking at the graph of f above or by looking
at the graph of the second derivative. You see that there are two zeros at
about 1 and 4, which you can find by means of the root function:
( ) , t) x1 5.07 10
13
t : 1 x1 : root(h t
( ) , t) x2 3.142 t : 4 x2 : root(h t
Exercises.
1. Find zeros (use the function polyroots), local extrema, global extrema and
points of inflection for the function
( ) : x
3
6 x
2
+ 10x + 5
over the

interval [-5,5].
2. Same exercise for the function
G x ( ) +
1
x
2
1
over [0,4].
( ) : sin x
10
95
f
x6
0 2 , ( )
3.2.10 Partial derivatives
Partial differentiation is done the same way as ordinary differentiation in
Mathcad. In version 2000, you can make partial derivatives look different
from ordinary derivatives, cf. section 3.2.2. So, everything that was said
about ordinary differentiation in sections 3.2.2 and 3.2.3, applies to partial
differentiation as well.
Example
f x , y) : x
3
2 xy
2
+ 3 y
4
(
f
x
(x y) : f x , y) 3 x
2
2 y
2
f 0 , 2) 48 f 0 , 2) 48 , ( ( (
x
6
f
x6
(x y) : f x , y) f
x6
(0 2)
gives error message, but:
, ( ,
6
x
6
f
x6
(x y) : f x , y) 0 f
x6
(0 2) 0
is allright.
, ( ,
6
x
3.2.11 Series
The keyword series can be used to find the Taylor series of a function of one
or several variables. You have to supply information about what variables
that are free, the highest order of the terms and the point of development.
Examples
ln(xy + z) series , x = 0 , y = 0 , z = 1 , 3 z 1 + x y
1
(z 1)
2

2
Notice that x=0,y=0,z=1 means that the Taylor series is around the point
(0,0,1). The final 4 means that the highest order is < 4, i.e. only terms whose
sum of exponents is less than 4 are included.
2
ln(xy + z) series , x = 0 , 3 ln z ( ) +
y
x
1

y
x
2
z 2
2
z
Notice that y and z are considered to be constants in this example, so e.g. the
term x
2
y
2
is actually of the second degree in the free variable x.
Exercise.
Find the Taylor series with terms of degree less than 5 of the function
sin(xy)z
about the point x=0,y=1 with x and y as free variables.
96






3.2.12 Extrema of functions of two variables
You can use SmartMath to decide what kind of an extremal point a given
stationary point is. Say you have a function (which is simple enough for the
symbolic Given - Find):
f x , y) : x
3
2 xy
2
+ 3 y
4
(
Find the partial derivative of the first and second order:
f
x
(x y) : f x , y) 3 x
2
2 y
2
f
y
(x y) : f x , y) 4xy + 12y
3
, ( , (
x y
2 2
2
, ( , ( f
xx
(x y) : f x , y) 6 x f
yy
(x y) : f x , y) 4x + 36y
2 2
x y
, ( f
xy
(x y) : f x , y) 4y
x y
2
Also, define the quantity
f
xx
f
yy
f
xy
2 _ 2 _
_
2
( ( ( ( D u , x , y) : u x , y) u x , y)

u x , y)


x
2
,
y
2
,

x y
,
Di(x , y) : D(f , x , y) 6x
(
4x + 36y
2
)
16y
2
Then find the stationary points:

0 0
_


0 0



M :


3 x
2
2 y
2
= 0

_
solve , x , y

2 1
6

4xy + 12y
3
= 0

,
9 9


2 1
6

9 9
,
To determine what kind of stationary points you have, compute:
i : 0 .. 3 D
i
: Di
(
M
i 0
, M
i 1
)
fxx
i
: f
xx
(
M
i 0
, M
i 1
)
ff
i
: f M
i 0
, M
i 1
)
, , , ,
(
, ,
D
T
( 0 0 1.185 1.185) fxx
T
( 0 0 1.333 1.333)
ff
T


0 0
4 4
_


(
0 0 5.487 10
3
5.487 10
3
)

729 729
,
Therefore, this test gives no decision for the first stationary points while the
two other points are both minimum points. We find the function values:
97








However, the point (0,0) must be a saddle point, since
( (
(
, ,
f x , 0) x
3
f 0 , y) 3y
4
f M
2 0
, M
2 1
)
5.487 10
3
From this you see that the function is both positive and negative in every
neighborhood of (0,0). You can check that the results are reasonable by
drawing a contour diagram:
F CreateMesh f 0.5 , 0.5 , 0.5 , 0.5 , 20 , 20 , ( : )
To find global extrema, you can use a numerical solve-block with the
functions Maximize and Minimize:
x : 1 y : 1 Given x 1 x 1 y 1 y 1

x1
_
x1
_
0.816
_
(

: Maximize(f , x , y)


f x1, y1) 4.089

y1
,
y1
,
1
,
x : 1 y : 1 Given x 1 x 1 y 1 y 1

x2
_
(

: Minimize(f , x , y)


x2


0.222

_
f x2, y2) 5.487 10
3

y2
,
y2
,
0.272
,
The points you got, were correct, but there are more symmetric points. Change
the guess values to x:=-1, y:=-1 to find them.
Exercise. Find the local and global extrema of the function
f x , y) : 2 + 2x + 2y x
2
y
2
inside the triangular plate defined by
(
x 0 , y 0 , x + y 9
98
3.2.13 Extrema of functions with three or more
variables
Suppose you have a function of more than two (say three) variables:
f x , y , z) : x
3
2 xy
2
3 y
4
z y + 6 zx (
To find the stationary points, find the partial derivatives of the first order:
f
x
(x y , z) : f x , y , z) 3 x
2
2 y
2
+ 6 z , (
x
3
f
y
(x y , z) : f x , y , z) 4xy 12y z , (
y
f
z
(x y , z) : f x , y , z) y + 6 x , (
z
Then find the stationary points::

f
x
(x y , z) = 0
_


0 0 0
_

,

0

, M :


f
y
(x y , z) = 0


solve , x , y , z



0
71
0
71 115943

,

f
z
(x y , z) = 0
,


5184 864 53747712
,

Hessian matrix
To determine what kind of extremal points these are, define the Hessian
matrix:
_
( ( (

f x , y , z) f x , y , z) f x , y , z)


x x y x z x


( ( ( Hessian(f , x , y , z) :

f x , y , z) f x , y , z) f x , y , z)


x y y y z y


( ( (

f x , y , z) f x , y , z) f x , y , z)


x z y z z z
,
For the example above you find:

6 x 4y 6
_


( H x , y , z) : Hessian(f , x , y , z)
4y 4x 36y
2
1


6 1 0
,












99

0
_

0
_

eigenvals(H(0 , 0 , 0))

37


6.083

37

,

6.083
,

0.079
_
eigenvals
(
H
(
M
2 0
, M
2 1
, M
2 2
))


5.996

, , ,

6.188
,
Both H(0,0,0) and H(M
0,2
,M
1,2
,M
2,2
) are indefinite, so both are saddle points.
To find the global extrema within a volume given by a number of inequalities,
you can use a solve block. E.g. here is how to find the global extrema inside
the unit sphere:
Maximum:
x : 0 y : 0 z : 1

x1
_
x1
_
0.767
_
Given x
2
+ y
2
+ z
2
1

y1

: Maximize(f , x , y , z)

y1

0.062


( f x1, y1, z1) 3.424
z1
,
z1
,
0.639
,
Minimum:
x : 0 y : 0 z : 1

x2
_
x2
_
0.767
_
Given x
2
+ y
2
+ z
2
1

y2

: Minimize(f , x , y , z)

y2


0.062


( f x2, y2, z2) 3.424
z2
,
z2
,
0.639
,
Both extrema are on the bounding sphere:
x1
2
+ y1
2
+ z1
2
1 x2
2
+ y2
2
+ z2
2
1
Exercises. Find local and global extrema of the following functions inside the
unit ball:
f x , y , z) : xy + y z + x z (
2
h x , y , z) : x
2
+ x y + y z +
1
z
2
g x , y , z) :

x
1
_

+ y
2
+ z
2
( (
4

2
,
Also, find the same extrema, but this time inside the cube centered at the origin
with side lengths 2.
100
3.2.14 Extrema with side conditions
Method of substitution
Example 1:
Find the point on the plane 2x+y-z-5=0 that lies closest to the point (1,1,2).
Solution:
The function to minimize is
f x , y , z) : x 1 (
2
y (
2
+ z (
2
+ ) 1) 2)
or
(
you may as well take the square:
u x , y , z) : (x 1)
2
+ (y 1)
2
+ (z 2)
2
(
From
2 x + y z 5 = 0
you find
z = 2x + y 5
Substituting this into u you find
( v x , y) : u(x , y , 2x + y 5) (x 1)
2
+ (y 1)
2
+ (2 x + y 7)
2
Then find the partial derivatives of first and second order:
v
x
(x y) : v x , y) 10x 30 + 4 y v
xx
(x y) : v
x
(x y) 10 , ( , ,
x x
v
y
(x y) : v x , y) 4 y 16 + 4 x v
yy
(x y) : v
y
(x y) 4 , ( , ,
y y
, , v
xy
(x y) :
y
v
x
(x y) 4
v
xx
(x y)v
yy
(x y) v
xy
(x y)
2
24 , , ,
Then you can find the stationary points:

v
x
(x y) = 0
_
,

solve , x , y


7 5
_


v
y
(x y) = 0
,

3 3
,
,
This must be a minimum because of the results above
v


7
,
5
_


8
for the second order derivatives. The minimum value is:
3 3
,
3
Method of Lagrange Multipliers
Example 2. Find the greatest and the smallest value of the function
2 2
x
f x , y) : xy
on the ellipse:
+
y
= 1 (
8 2
Solution:
Define
g x , y) :

8
+
2
,
1 F x y , ( ( (

x
2
y
2
_
(
,
)
: f x , y) g x , y)






101
1
F
x
(x y ,
(
,
)
y ,
)
: F x y , x
x
4
F
y
(x y , F x y , ,
)
:
y
(
,
)
x y
Then find the stationary points:
,
) = 0
_


2 1 2
_


F
x
(x y ,

2 1 2


F
y
(x y ,
y ,
,
) = 0

solve , x ,

2 1 2

(

g x , y) = 0
,


2 1 2

,
You find
f 2 , 1) 2 f 2 , 1) 2
corresponding to positive 2 ( (
f 2 , 1) 2 f 2 , 1) 2
corresponding to negative =-2
( (
(2,1) and (-2,-1) are maxima, while (-2,1) and (2,-1) are minima.
Mathcad's built-in optimization functions
You can also use the Maximize and Minimize functions:
x : 0 y : 0
Given g x , y) = 0 x 1 Maximize(f , x , y)
T
( 2 1 ) (
( Given g x , y) = 0 x 1 Minimize(f , x , y)
T
( 2 1 )
( Given g x , y) = 0 x 1 Maximize(f , x , y)
T
( 2 1 )
( Given g x , y) = 0 x 1 Minimize(f , x , y)
T
( 2 1 )
You can draw level curves of the two functions to illustrate the problem:
X
0
: CreateMesh(f , 4 , 4 , 4 , 4 , 40, 40)
0
X
1
: CreateMesh(g , 4 , 4 , 4 , 4 , 40, 40)
0




102
3.2.15 Linear optimization
The functions Maximize and Minimize can be used very effectively to solve
linear optimization problems
Example 1.
Find the maximum of the function
f x , y) : 2x + 3y
subject to the
(
constraints:
5x + 3y 15, 3x + 6y 18, x 0 , y 0
Solution: Define guess values:
x : 0 y : 0
and use a solve block:
Given 5x + 3y 15 3x + 6y 18 x 0 y 0
Then you get the solution by simply using the Maximize function:

x1
_

: Maximize(f , x , y) x1 1.714 y1 2.143

y1
,
f x1, y1) 9.857 (
Example 2.
Maximize the function
f x , y , z , u) : 29x + 45y
subject to the constraints
(
2x+8y+z=60, 4x+4y+u=60, x,y,z,u0
Solution: Define guess values:
x : 20 y : 20 z : 20 u : 20
and use a solve block:
Given 2x + 8y + z = 60 4x + 4y + u = 60 x 0 y 0 z 0 u 0

x2
_
x2
_
10
_


y2

: Maximize(f , x , y , z, u)

y2


5

f x2, y2, z2, u2) 515
z2 z2 0
(


u2
,
u2
,
0
,
Exercises.
1. Maximize
f x , y , z) : 4x + y + 2z
subject to
(
x 0 , y 0 , z 0 , x + y + z 1
,
x + y z 0.
2. Maximize
g x , y , z, u) : 4x + y + 3z + 2u
subject to
x y , z, u 0
,
( ,
10x + 15y + 30z + 6u 30, 8x + 10y + 20z + 5u 40
103
f x
f x
f x
f x
3.3 Integration
3.3.1 Indefinite integrals
Mathcad has a built-in operator that returns the indefinite integral (or
antiderivative) of a function, which can be accessed both from SmartMath and
from the menu system. Using the menu system, you start by writing just the
expression to integrate. Then you place the cursor on the x (or whatever
variable you have), and choose Symbolics - Variable- Integrate from the
menu. Then you get the indefinite integral below or to the right of it. You
choose between these two possibilities using the menu choice Symbolics -
Evaluation Style.
Example 1
4
2
x
1
by integration, yields
asin


1
x

_

2
,
There is also a button for indefinite integrals on the symbolic toolbar. Press the
button to get the calculus menu, and then press the button

Alternatively, type [Ctrl]I. In both cases, you get the symbol
( d

where you just fill in the placeholders. Then you either press [Ctrl][Period] to
get symbolic evaluation in SmartMath, or you choose Symbolics - Evaluate -
Symbolically from the menu system. Remember to have the whole integral
inside the editing frame. The two methods give the same result, but look a little
different:

( ) dx sin x ( ) dx
yields
sin x ( cos x ( ) ( cos x
( )

The first method method has the advantage that you can define a define a
function and then integrate:
( ) :
9
2
x
1


( ( ) dx
yields
( ( ) dx



which is not useful ,but
( ( ) dx asin


1
x

_
does work.

3
,
104
Si
Sometimes Mathcad gives the result in terms of a functions that is defined in
the symbolic Mathcad, but which is unknown to numerical Mathcad:

( )
( )
Si( )
(Function not defined above) but
(
sin x
dx Si x
1
( x

Si(1) float , 20 .94608307036718301494
Some non-elementary integrals are known both numerically and symbolically:

(

t
2
( ) erf(1) 0.842700792949715
(
2
exp
( )
dt erf t
(

erf(1) float , 20 .84270079294971486934
Exercises
Integrate the following functions using one of the methods mentioned above:
Basic primitive functions:
2
1 1 1
x exp x ( ) sin x ( ) cos x ( )
x
sin x ( )
2
a
2
+ x
2
1 1 1
( ) sinh x
x
2
a
2
+ 4
2
x
cosh x ( )
cos x ( )
2
Rational functions:
5x + 3 2x
3
4x
2
x 3 2x + 4
x
2
+ 2x 3 x
2
2x 3
(
x
2
+ 1
)
(x 1)
2
Notice that you don't have to worry about the conversion to partial fraction.
Mathcad knows that that's what has to be done.
Algebraic functions:
1 1 x
2
x
x
2
3 x + 5 x
2
3 x + 2 + 4
2
x
x
2
9
Exponential and logarithmic functions
exp(2x)
(
x
2
+ 5x
)
exp 2x
Try to use the code word
2 + exp(2x)
( )
collect,exp(2 x) on this one.
x
4
ln x
( )
3
Use collect,x on this one
1
cos(ln x
( )
3
x
4
ln x ( ))
x
105
Trigonometric and inverse trigonometric functions
(
2sin x ( ) + 1
)
cos x ( )
2
+ 3tan x ( ) ( )
2
sin x ( ) tan x ( ) + 2 x
2
asin x
Miscellaneous
( ) asin x cos x ( ) 1
2 x
1 x
x e
1 + x
x
4
+ 1
1 sin x ( ) +
1
2
x x
2
2x + 2 +
cos x ( )
1 sin x ( ) +
cos 2x
x
( ) 1
cos( 1 x
)
1
cos 2x

( )
2
( ) + 1
x 2x
3
+ 1
3.3.2 Definite Integrals
Mathcad's operators for definite integration
There are several ways to get a definite integral with symbolic Mathcad.
Press the calculus palette button and then
The keyboard shortcut is & (or [Shift][6] on the alphanumeric keyboard)
Press = if you want a numeric result, and [Ctrl]+[Period] if you want a
symbolic result.If you want a numeric result from the symbolic version, use
the keyword float n, where n is the number of decimal digits you want to have.
a :

Numerical value:
a
( ) dx 0.151746413916752
4
( xsin x

0
Symbolic value:
a
1
2
1
( xsin x ( ) dx

0
2 8
2
You can also write the integral and then choose Symbolics - Evaluate -
Symbolically or press Shift/F9:

yields 1
2
1

4
2 8
(
xsin x
2

( ) dx
0
a
a

but you cannot evaluate


( xsin x
( ) dx
( ) dx
yields
( xsin x

0
because the definition of a will be invisible from the Symbolics menu.
106
Symbolic evaluation with numerical approximation:
a
1
2
1
( xsin x ( ) dx 2 0.151746413916752
or

0
2 8
a

( xsin x ( ) dx float , 30 .151746413916751743523859238347


or

0
a

( 1.0xsin x
(The factor 1.0 will

( ) dx .15174641391675174351
force a numerical result.)
0
The precision of a numeric result can be improved by changing the value of
the variable TOL to something other than 10
-3
, which is the default value:
(
J(Tol) : TOL Tol
J 10
3
)
5.00000000006814
Compare with:
5
5

e
J 10
7
)
5.00000000000001

e
(
(
(
1
t
dt
(
(
1
t
dt 5
(

1
J 10
1
)
5.00000005437786

1
Exercises. Compute the following integrals, numerically and/or symbolically:
3
9
x ( )
5
3

ln

(3x 7) (
2
( e dx
(

( (x 1)(x 2)(x 3)
dx
(
(
16 + x
2
)
dx
0

4
0

64
1
2
( )
dx
(
1
dx
(
1 + x
dx
( cot x
(
( )
( 5
(
(
ln(esin x
(
(
(
x
2
1
)
2

2

1
2 2

1
(
x
3
cos 2x
(
( )
dx ( x 1 x dx

( ) dx
(
2xasin x
2

0 0 0
107
f x
3.3.3 Improper Integrals

b
There are two kinds of improper integrals
( ( ) dx
Either

a
1. a=- or b= or both or
2. f(x) has a discontinuity and is unlimited in one or more points of the
interval [a,b]
As a general principle: Try to use symbolic evaluation for improper
integrals. Examples:


sin x

1 cos x 1
Type 1):
(
( )
dx
1

(
( )
dx
( x 2
(
x
2
2

0
0
1 1

1

cos x
Type 2): (
1 x
2

dx 1
(
( )
dx
(
(
2

0
(x + 1)

0
x
It may happen, of course, that SmartMath cannot find any antiderivative:

( x
x
dx ( x
( x)
dx
and therefore no definite integral:

In version 8, you can compute such integrals numerically:


( x
x
dx 1.99545634417723

0
You have the possibility to choose between a certain number of integration
algorithms by clicking on the integral sign with the right mouse button. The
default is Autoselect, but then there is also Romberg, Adaptive, Infinite
Limit and Singular endpoint.
Exercises. Compute the following improper integrals:

(
1
dx
(
x
dx ( x ln x
2

1
1
1
( ) dx
(
2xe
x
dx
(


(
x
2
+ 1

0
0
108
f x
f x
f x
3.3.4 Plane areas
The area between the graph of a function u=f(x) and the x
axis
If the areas below the x-axis are counted as negative, then the area between the
curve and the x axis is simply the definite integral: Otherwise, you have to
integrate the absolute value of the function:
Example 1. Find the area bounded bounded by the x-axis and the graph of the
function f from x=0 to x=7:
x
f x ( )
Here is the graph for
x : 0 , 0.1.. 7 ( ) : 8cos x
5
10
0
10
f x ( )
f x ( )
0 2 4 6
x
I have used the trace type stem on the last trace to get the shading.
If the areas below the x-axis is counted as negative, the area from x=0 to x=7
is:

7
49
( ( ) dx 8sin 7 ( ) float , 20 .3558927897503127232

0
10
or numerically:

7
( ( ) dx 0.355892789750311

0
If the area below the x-axis is counted as positiv, the area from 0 to 7 is:

7
( ( ) dx 36.4321069196977

0
The symbolic processor will have difficulties with the absolute value, however
(try!).
109
g x
g x
f x g x
The area between the graphs of two functions
To find the area between two curves, you may have to combine a root finding
function with integration. Also, the shading is little more difficult in this case.
You may use the following function:
Shade(f , g , a, A, N) : (x a)

dx
A a
_


N
,
for n 0 .. N
(
X
0 n
x
)

(
X
1 n
x
)
, ,
(
Y
0 n
( )
)

(
Y
1 n
( )
)
, ,
x x + dx

X
_


Y
,
Example 2. Find the area bounded by the graphs of the functions f and g:
( ) : 5cos x f x ( ) ( ) : 3
1
x
2
x : 0 , 0.1.. 5 t : 0 , 0.1.. 5
5
First, find the points of intersection:
TOL : 10
13
( ) g x x : 1 r1 : root(f x ( ) , x) r1 0.973923271295714
( ) g x x : 4.5 r2 : root(f x ( ) , x) r2 4.50059493837989

r2
Then the area is:
( ( ) f x ( ) dx 13.5879540097218

r1

X
_

: Shade(f , g , r1 , r2, 40) x : 0 , 0.1.. 5

Y
,
0 2 3 4 5
5
5
Y
f x ( )
g x ( )
1
X x , x ,
110
f x g x g x
y t
a b
Exercises. Find the area between the graphs of the following pair of curves::
x
( ) : sin x
1.
( ) : x ( ) :
1
x
2
2.
f x ( ) ( ) : +
1
2 2 10
The area bounded by a parameter curve (x(t),y(t))
b

( ( ) dt A x , y , a , b) :
(
( )
d
x t
(
dt

a
Example
( ) y1(t) : bsin t ( x1(t) : acos t ( ) A x1, y1, 2, 0) ba
Exercises. Find the areas bounded by the following curves:
( ) ( ) ( ) y1( )
( ) y2(t) : 1 cos t
Cycloid
x2(t) : t sin t ( )
Asteroid
x3(t) : cos t ( )
3
( )
3
y3(t) : sin t
The area bounded by a polar curve
For curves given on polar form r=r(t), the area bounded by the curve and the
two radii t=a and t=b is:
AP(r, a , b) :
1
b
( )
2
dt ( r t
2
a
Example 4 Cardioid
r1(t) : 2(1 cos t ( ))
The area is:
AP(r1 , 0 , 2
)
6
Exercises. Find the area bounded by the following curves:
Four leafed rose:
r2(t) : sin 2t ( )
1
Limacon.
r3 t ( ) ( ) : + cos t
2
111
3.3.5 Curve length
Curves given as the graph of a function y=f(x)
b

(
CurveLengthF(f , a , b) :
(
1
x
f x ( )
d
d

,
2
+ dx

a
Example 1. The length of the graph of the cosine function
f x ( ) ( ) : cos x
from 0 to 1 can be computed as:
CurveLengthF(f , 0 , 1) 1.12388772294552
or:
CurveLengthF(cos, 0 , 1) float , 20 1.1238877229455250047
Exercise. Find the length of the parabola y=x
2
from 0 to b and from 0 to 1.
Curves given by parametric equations
For a curve given by a pair of parameter equation the arc length can be
evaluated by means of one of the following formulae:
b

(
CurveLengthP(x , y , a , b)
(
t
x t ( )
d
d

_

,
2
t
y t ( )
d
d

_

,
2
+ dt

a
In vector formulation, where X is a vector function:
b

(
CurveLengthV(X, a , b) :
(
t
X t ( )
0
d
d

_

,
2
t
X t ( )
1
d
d

,
2
+ dt

a
Example 2. The length of the cycloid
x t ( ) y t ( ) ( ) : t sin t ( ) : 1 cos t

t sin t ( )
_

or
X t ( ) :

whose graph looks like this:
t : 0 , .. 2

1 cos t ( )
,
32
2
1 cos t ( )
0 2 4 6 8
tsin t ( )
112
a a
a
a
can be computed in one of the following ways:
CurveLengthP(x , y , 0 , 2
)
8 CurveLengthP(x , y , 0 , 2
) simplify 8
CurveLengthV(X, 0 , 2
)
8
CurveLengthV(X, 0 , 2) 4 4 simplify 8
Exercises. Find the lengths of the following curves:
Asteroid: Circle: Ellipse:

cos t ( )
_
3 cos t
( ) :

( )
3
_

X t

acos t

X t
( )
_
X t ( ) :

( ) :


sin t
( )
,
2 sin t
( )
3
,


asin t ( )
,
Notice that you can have undefined parameters in the functions and still find
the curve length symbolically, not numerically.
Curves given on polar form
For a curve given on polar form r=r(t), the curve length is given by:
b

(
CurveLengthPol(r, a, b) :
(
r t ( )
2
t
r t ( )
d
d

_

,
2
+ dt

a
Example: The length of the leminscate:
r t ( )) ( ) : 2a(1 + cos t

t : 0 , .. 2
can be computed as
32
CurveLengthPol(r, 0 , 2
) simplify, assume, a 0 16a >
90
2(1+cos t ( ))
180
30
60 120
150
210
330
3
1
0
240 300
270
t
Exercises. Find the curve lengths of the following curves given in polar form:
( ) : a
Logarithmic spiral:
r t at
Circle:
r t ( ) : exp( )
113
g2 x ( )
x
2
1
10
+ : f2 x ( ) sin x ( ) :
2.
g1 x ( )
1
2
x
2
: f1 x ( ) x :
1.
Exercises. Find the centroid of the areas bounded by the graphs of the
following pairs of functions:
0 2 3 4 5
5
u x ( )
v x ( )
Y
c2
x x , X , c1 ,
X
Y



_

,
Shade u v , x1 , x2 , 40 , ( :
Shade from section 3.3.4
c1
c2



_

,
2.825
1.12



_

,

c1
c2



_

,
Centroid u v , x1 , x2 , ( :
Then compute the centroid:
x2 4.501 x2 root u t ( ) v t ( ) t , ( : t 4.5 :
x1 0.974 x1 root u t ( ) v t ( ) t , ( : t :
First, find the points of intersection:
x 0 0.1 , 5 .. : v x ( ) 5 cos x ( ) : u x ( ) 3
1
5
x
2
:
Example 1. Find the centroid of the plane area bounded by the graphs of the
following functions:
Centroid u v , a , b , (
1
a
b
x u x ( ) v x ( )

(

d
a
b
x x u x ( ) v x ( ) (

(

d
1
2
a
b
x u x ( )
2
v x ( )
2

(

d







1
1
1
1
1
1
]
:
Centroid of plane area bounded by u=f(x) and v=g(x)
3.3.6
1
)
)
)
) 1
)
)
)
Centroids and moments of inertia
114
Moments of inertia of graph of u=f(x) with density (x)
b

(
( ) 1
x
u x ( )
d
d

_

,
2
+ dx
About the x-axis:
I1S
x
(u , , a , b)
:
(
x
2
x

a
b

About the y-axis:
I1S
y
(u , , a , b)
:
(
u x ( ) 1
x
u x ( )
d
d

_

,
2
+ dx
(
( )
2
x

a
( ) : x f x ( )
Example 2:
x
2
( ) : 5cos x
I1S
x
(f , , 0 , 4)
526.227 I1S
y
(f , , 0 , 4)
806.203
Exercise. Find the moment of inertia of the curve
u x ( ) : 3
1
x
2
from 0 to
5
5.
Moments of inertia of a plane region bounded by the graphs
of u=f(x) and v=g(x) with constant density .
I2S
x
(u v ,

b
( ) v x , , a , b)
: ( x
2
(u x ( )) dx

a
I2S
y
(u v , (
(
u x ( )
3
)
dx , , a , b)
:

b
( )
3
v x
3
a
( ) : 3
1
x
2
v x ( )
cf. example. 1 Example 3 u x ( ) : 5cos x
5
I2S
x
(u v , 1 , x1, x2) 116.236 I2S
y
(u v , 1 , x1, x2) 62.006 , ,
Exercises. Find the moments of inertia of the plane regions bounded by the
following pairs of functions. Assume that the density is 1.
x
1.
f1 x x ( ) :
1
x
2
2.
f2(x) : sin x ( ) : +
1
( ) : g1 x ( ) g2 x
2 2 10
115
f x
3.3.7 The volume of a surface of revolution
Drawing a surface of revolution
First, we show how to draw a surface of revolution. Suppose the axis of
revolution is the x axis, and that you're given a function f. Then the surface of
revolution can be drawn by means of the following function:
XRevSurf (f , a , A, M , b , B , N) :

dx
A a
_

dt
B b
_


M
,
N
,
for m 0 .. M
x
m
a + mdx
for n 0 .. N
t
n
b + ndt
X
m n
x
m ,
Y
m n
f x
m
( )
,
( )
cos t
n
Z
m n
f x
m
( )
,
( )
sin t
n

X
_

Y



Z
,
Example 1.
( ) : x
2
M
0
: XRevSurf (f , 0 , 1 , 10, 0 , 2, 40)
you get the following graph, using Insert - Graph - Surface Plot or [Ctrl]2
116
f x y t
If the axis of revolution is the y axis, you define similarly:
YRevSurf (f , a , A, M , b , B , N) :

dx
A a
_

dt
B b
_


M
,
N
,
for m 0 .. M
x
m
a + mdx
for n 0 .. N
t
n
b + ndt
X
m n
x
m
cos t
n ,
( )
Y
m n
x
m
sin t
n ,
( )
Z
m n
f x
m ,
( )

X
_

Y



Z
,
Example 2. Revolve the parabola from example 1 about the y axis.
M2
0
: YRevSurf (f , 0 , 1 , 10, 0 , 2, 40)
The volume of a surface of revolution
Now, the volume of a solid of revolution about the x axis can be evaluated by
the following definition :
b

b

( ) dt VolXR(f , a , b) : ( ( )
2
dx VolXRP(x , y , a , b) :
(
( )
2

d
x t

a
(
dt

a
117
r
r
h
r
r
y t
U x
f x a
Here is a variation where f is a vector function:
b

VolXRevSolidPV(f , a, b)
(

(
f t ( )
0
dt ( )
1
)
2

d
f t
(
dt

a
Example 3
( ) : ax
2
VolXR(f , 0 , 1)
1
a
2
5
For a surface of revolution about the y axis, the volume can be evaluated by
means of the following functions:
b

VolYR(U, a , b) :
(
x
2

d
( ) dx
(
dx

a
b

( )
2

d
( ) dt VolYRP(x , y , a , b) :
(
x t
(
dt

a
b

In vector notation:
VolYRV(U, a, b) :
(

(
U t ( )
1
dt ( )
0
)
2

d
U t
(
dt

a
Example 4. Half sphere
simplify
2
3
f1 x r
2
x
2
r r ( ) : VolYR(f1 , r, 0)
assume, r > 0
3
Exercises. Find the volumes of the following surfaces of revolution about the
x axis:

rcos t ( )
_
1. A sphere generated by
f1 x r
2
x
2
r ( ) :

( ) :
or
U1 t
( )
,
rsin t
2. A cylinder generated by
f2 x ( ) : r
r
3. A cone generated by
f3 x ( ) : x
h
Also, find the volumes of the following surfaces of revolution about the y axis:
h
4. Paraboloid:
f4 x x ( ) : x ( ) :
5. Cone:
f5 x
r

rcos t ( )
_
6. Half sphere:
f6 t ( ) :

( )
,
rsin t
118
r
g t r f x
y t
U x
3.3.8 Surface area of a surface of revolution
Surfaces of revolution about the x axis
For a surface of revolution about the x axis, the formula for the surface area
can be written:
b

(
AreaXR(U, a , b) :
(
2 ( ) 1
x
U x ( )
d
d

,
2
+ dx

a
Parametric versions:
b

(
AreaXRP(x , y , a , b) :
(
2 ( )
t
x t ( )
d
d

_

,
2
t
y t ( )
d
d

_

,
2
+ dt

a
Vector formulation:
b

t
X
0
d
d

_

,
2
t
X
1
d
d

_

,
2
+
(X is an
(
AreaXRV(X, a , b) :
(
2X
1
dt
expression in t.)

a
( )
_
Examples: ( ) : x
2
( ) : r


cos t


sin t ( )
,
AreaXR(f , 0 , 1)
9
5 +
1
ln(2 + 5) 3.81
16 32
assume, r > 0
( ) 0 , AreaXRV(g t , ) 4r
2
simplify
Exercises. Find the surface area of the surface generated by the following
functions:
h
Cone:
f2 x ( ) :
r
x
Sphere:
f3 x ( ) : r
2
x
2
r
119
r
r r
f x
Surfaces of revolution about the y axis.
Analogous to the formulae above we can define the following functions for the
surface area for a surface of revolution about the y axis:
b

(
AreaYR(U, a , b) :
(
2x 1
x
U x ( )
d
d

,
2
+ dx

a
b

(
( )
t
x t ( )
d
d

_

,
2
t
y t ( )
d
d

_

,
2
+ dt AreaYRP(x , y , a , b) :
(
2x t

a

b
t
X
0
d
d

_

,
2
t
X
1
d
d

_

,
2
+
Notice that X is
(
an expression,
AreaYRV(X, a , b) :
(
2X
0
dt
not a function
here.
a
Examples: ( ) : x
2

3
_
3
_

AreaYR(f , a , b)
1

(
1 + 4b
2
)

2
,

1

(
1 + 4a
2
)

2
,

6 6
( ) : rcos t ( ) : rsin t x t ( ) y t ( )
AreaYRP

x , y ,

,

_
assume, r > 0
4r
2

2 2
,
simplify
( ) :

( )
_

AreaYRV

R t
assume, r > 0
R t

rcos t
( ) ,

_

4r
2
( )
,
2 2
,
simplify

rsin t
Exercises. Find the surface area generated by the following functions:

cos t ( )
_
f2 x r
2
x
2
r ( ) :

( )
3
_

f6 t

cos t

( ) : f5 t

( )
3
,

( ) :


2sin t

sin t
( )
,
120
3.3.9 Double integrals
Double integrals work both numerically and symbolically:.:
Example 1. The volume of a prism whose base is the rectangle [0,2] x [0,1]
and whose top lies in the plane z=4-x-y

1
( ( 4 x y dy dx 5 ( ( 4 x y dy dx 5

0 0 0 0
Example 2. The volume of a prism whose base in the xy-plane is bounded by
the lines y=0, y=x and x=1 can be computed as:

1
( ( (3 x y) dy dx 1
or
( ( (3 x y) dx dy 1

0 0 0 y
Change of coordinates
Suppose you have a coordinate transformation given as a two dimensional
vector expression U in the new coordinates u,v. Then the Jacobian matrix and
determinant can be defined as:
1
( (

(U u , v))
0
(U u , v))
0
1
Jac(U, u , v) :

u v
1
1
( (

(U u , v))
1
(U u , v))
1
1

u v
]
JacDet(U, u , v) : Jac(U, u , v)
For instance, for polar coordinates:
( )
_
factor

ucos v
( U u , v) :


usin v

JacDet(U, u , v)
simplify
u
( )
,
So, for instance, to find the area of the lemniscate r
2
= 4 cos 2v, you integrate

4

4 cos 2 v ( )
4
(
( u du dv 4

0 0
Exercises. Compute the following double integrals:
2 2x

x

( ) dy dx
(
(
(4x + 2) dy dx ( ( xsin y


2
0 x
121




a
3.4 Vector calculus
3.4.1 Vectors in R
n
Vectors can be of any finite dimension with Mathcad. Mathcad knows the
scalar product of two n dimensional vectors and the norm of an dimensional
vector. Hence you can define the angle between n dimensional vectors: It also
knows the vector (cross) product of two three dimensional vectors. All the
vector operations are on the Matrix toolbar, which access by pressing the
matrix icon on the Math toolbar. The matrix toolbar looks like this:
The angle between vectors is not built-in , but can be
defined as follows:

ang(x , y) : acos


x y
_


x y
,
Example

1
_
0
_


2

1


3
_
0
_
x :

1

y :

3

z :

2

u :

2



4

1

1
,
1
,


5
,
2
,

0
_
x 6.856 y 3.873 x y 5
z u



x y 7.211 ang(x , y) 79.146 deg

6
,

You can also use the symbolic processor:
x 47 y 15 x y 5

0
_

z u

3

x y 2 13 ang(x , y) acos


1
47 15

6
,


141
,
Notice however that if
V : ( a b c )
T
then while

1
_
1
_

V

( a )
2
+
( b )
2
+
( c )
2
1
]

2
,
V V
(
a
2
+ b
2
+ c
2
)

2
,
This means that
x x
should be used instead of |x| in symbolic calculations.
122
D1 D1 P t , ( t , (
f t
P t P t P t
t
) )
3.4.2 Vector valued functions R R
3
You might want define a vector valued function by describing the individual
component functions:
( )
i
: t
i
(Not defined.)
m : 3 i : 0 .. m 1 f t
As you see, Mathcad doesn't accept indexed functions in definitions. You have
to define a vector valued function in a vector:

sin t ( )
_

P t ( ) :

t
2


t
3

,
Once you have defined the function, however, Mathcad does understand the
nth component of it:
( ) ( )
1
t
2
( )
2
t
3
( )
0
sin t
To differentiate a vector function, you would probably like to make a
definition like this:
T
D1(f , t) :


d
f t
d d
f t
_
(As before, I use transposition to

dt
( )
0
dt
( )
1
dt
( )
2
,
save space.)
This will work fine numerically and symbolically:
( )
_

0.416
_
0.995
_

cos t

D1(P, 2)

4

D1(P, 0.1)

0.2

D1(P, t)

2 t




12
,
0.03
,

3 t
2
,

However, D1(P,t) is an expression, not a function, so it won't work to compute
D1(D1(P, t) , t)
(Error: No symbolic result was found.)
There is a way around this: Symbolic Mathcad - as Maple - understands
expressions as arguments as well as functions, as you have seen before. So if
you define:
( )
_
d d d
T

cos t
D1(f , t) :


dt
f
0
dt
f
1
dt
f
2
_
,

then
D1(P t


( ) , t)

2 t

and

sin t ( )
_

3 t
2
,
( ) , t) , t)

2

D1(D1(P t


6 t
,
You may even define:
123
t
t
D f
t
T
( ) :


d
f
0
d
f
1
d
f
2
_
where it is understood that f is a vector

dt dt dt
, whose components are expressions in t.

cos t
( )
_
( )
_

sin t

( ( ))

2 t

D D P t

D P t

( ( ( )))

2


3 t
2
,

6 t
,
But then you have to use t as independent variable in all your functions, which
seems to be a mild restriction.
To be able to use D(D(P(t))) as a function and find function values, you define,
say:

sin t ( )
_
( )
_
sin 1
DP t ( ( ( )))

2

DP 1 ( ) : D D P t

( )


6 t
,
6
,
For the second derivative you define likewise: For the example:
T

sin t ( )
_
( ) :


d
2
u
0
d
2
u
1
d
2
u
2

_
P2 t ( ))

2

D2 u

dt
2
dt
2
dt
2
,
( ) : D2(P t


6 t
,


More generally, you can define:
P2 2 ( )
T
( 0.909 2 12 )
T

cos t ( )
_
Dn(u , n) :


d
n
u
0
d
n
u
1
d
n
u
2

_
P5 t ( ) , 5)

0


dt
n
dt
n
dt
n
,
( ) : Dn(P t


0
,

P5 2 ( )
T
( 0.416 0 0 )
Exercise. Find the first three derivatives of the following vector functions:

sin t
( )
_


2 ln(t + 1)
_
( )
_


t + 1


1 + t


sec t


cos t

t
2
1
2
t
2

tan t

( )

( )

t
2

( )
,

2t

4

t
2

sin 2t

e
t
_


3t +
,
1
_


t
3


3
t
,


2
,


3 t
T
2 cos(3t


3
,


3 3
1

( )
,


t
2
,

4
(1 + t)
2
4
(1 t)
2
1
t
1

2 sin 3t

9 9 3
]
124
D3
V U
UN
N U
DV
V U
D1
t
V U
t
t
t
3.4.3 Differential geometry of space curves
You can define the elementary functions from the differential geometry of
space curves in the following way:
The first three derivatives:
T
D1 U
d d d _
( ) :

U
0
U
1
U
2

dt dt dt
,
T
( ) :


d
2
U
0
d
2
U
1
d
2
U
2

_
D2 U

dt
2
dt
2
dt
2
,
T
( ) :


d
3
U
0
d
3
U
1
d
3
U
2

_
D3 U

dt
3
dt
3
dt
3
,
Length of tangent vector, speed:
V U) : ( D1 U ( ) D1 U ( ) D1
The derivative of the speed V:
DV U
d
( ) : ( )
dt
1
The unit tangent vector:
UT U U ( ) : D1( )
( )
The principal normal vector:
N U) : D2 U ( )DV( ) ( ( ) UT U U
1
The unit principal normal vector:
UN U ( ) :
N U ( ) N U ( ) N
( )
The unit binormal vector:
UB U ( ) UN( ) ( ) : UT U U
Curvature:
U ( ) :
Torsion:
U ( ) :
125
W D1(U) D2 U ( )
W W
V( )
3
W D1(U) D2 U ( )
D1 U ( U ( ) D2(U) D3( ))
W W
N U
t


1


( ) :
Radius of curvature:
U
U ( )
1


U
Radius of torsion:
( ) :
U ( )
Example. A circular helix:

3 cos( )
_
t
U :

3 sin t

( )


4 t
,
Length of tangent vector, speed:
V U) simplify 5 (
The derivative of the speed V:
DV U ( ) 0
The unit tangent vector:
UT U ( ) ( )
4
_

( )
T
simplify


3
sin t
3
cos t

5 5 5
,
The principal normal vector:
( )
T
simplify ( 3cos t ( ) 0 ) ( ) 3sin t
The unit principal normal vector:
UN U ( ) sin t ( )
T
simplify ( cos t ( ) 0 )
The unit binormal vector:
UB U ( ) ( )
3
_

( )
T
simplify


4
sin t
4
cos t

5 5 5
,
3
Curvature:
(U) simplify
25
4
Torsion:
(U) simplify
25
25
Radius of curvature:


(U) simplify
3
25
Radius of torsion:

(U) simplify
4
Exercise. Repeat the example on the conic helix

tcos t ( )
_
R t ( ) :

tsin t

( )



t
,
126
z
z
x
y
z
3.4.4 Vector fields and scalar fields
A vector field is a function R
3
R
3
. A scalar field is a function R
3
R.
To define differential operators on vectors and scalar fields, you have the same
options as for space curves: You can use functions as arguments for numerical
definitions or expressions as arguments for symbolic definitions. You can
include or not include the names of the independent variables.
I choose the following convention: Functional arguments are expressions. The
independent variables are assumed to be x,y and z, and they are not included
in the list of arguments to the differential operators.
With this convention, you can define the standard differential operators for
vector and scalar fields as follows:
Divergence:
Laplacian:
div u ( ) :


d
2
u +
d
2
u +
d
2
u

_
( ) :

d
u
0
+
d
u
1
+
d
u
2
_
u

dx dy dz
,

dx
2
dy
2
dz
2
,
Gradient: T
d d d _
grad u ( ) :

u u u


dx dy dz
,
Curl: T
( ) :


d
u
2

d
u
1
d
u
0

d
u
2
d
u
1

d
u
0
_
curl u

dy dz dz dx dx dy
,
Examples:
U : xyz

y z
_

x
2
y

_


grad(xyz)


div
x z
2 xy + y x z


x y
,

y z
,,

(
x
2
sin(x + y)z
)
2sin(x + y)z + 4 xcos(x + y)z 2 x
2
sin(x + y)
Exercises.
1. Find the gradient and Laplacian of the following scalar fields:
x
2
+ y
2
2z
2
+ z ln x
(
( ) 2z
3
3 x
2
+ y
2
)
z + atan(xz)
2. Find the divergence and curl of the following vector fields:

y x
_


x
2
_


6x
2
+ 2xy
_


5x
3
+ 12xy
2

( )
x y


z y

2x y 2y + x
2
z y
3
+ e
y
sin z

z
,

( )
,

y x
,

3xz


4x
2
y
3
,


5z
3
+ e
y
cos z
127
D
t
t
D r
t
3.4.5 Line integrals
We repeat the definition of the derivative of a vector function:
T
d d d _
( ) :

r
0
r
1
r
2

dt dt dt
,
If F is a vector expression in the variable t, then you can integrate F from a to
b by the definition:
T

b
_
VecInt(F, a , b) :

( F
0
dt ( F
1
dt ( F
2
dt


a

a

a
,
Example:
)
T
T
VecInt

(
t t
2
t
3
, 0 , 1
,
_


1 1 1
_


2 3 4
,
If F is a scalar expression in the independent variables x,y and z and r is a
three dimensional vector expression in t, then the value of F at the point r can
be evaluated using the function Val below. This definition can be extended to
vector expressions.
Val(F, r) lim lim lim F
zr
2
yr
1
xr
0
ValV(F, r) :
(
Val
(
F
0
, r
)
Val
(
F
1
, r
)
Val
(
F
2
, r
) )
T
Example:

3 x
2
+ 6 y
_


t
_


cos( )
_


9 t
2
_

x t



( )


ValV(A, r1)

14t
5

A :

14yz

r1 :

t
2

r2 :

sin t

20xz
2
,


t
3
,


t
,


20t
7
,

Integrals of the kind F(r) dr, where F is a vector field.

b
Int1(F, r, a, b) : ( ValV(F, r)D( ) dt r

a
With the example above:
Int1(A, r1, a, b) 3b
3
4 b
7
+ 6 b
10
3 a
3
+ 4 a
7
6 a
10

128
t
D r ( )
D
Integrals of the kind (r)|dr|, where is a scalar field

b
Int2(
, r, a , b)
: ( Val(
, r)
D r ( ) D r ( ) D dt

a
Example Int2


x
2
yz , r2, 0 ,

_

2


2
,
9
2
Integrals of the kind F dr
r Int3(F, r, a, b) : VecInt(ValV(F, r) D( ) , a , b)
Example Int3(A, r1, 0 , 1)
T


349 29 41
_


36 10 6
,
Integrals of the kind dr with a scalar field
Int4(
, r, a , b)
: VecInt(Val(
, r)
D , a , b)
T
Example Int4
(
x
2
yz, r1 , 0 , 1
)


1 2 3
_


8 9 10
,
Example to illustrate Green's theorem in the plane:

3 x + 4 y
_
2cos( )
_
x t
F :

2 x 3 y

r :

2sin t



( )


u :

0
,
0
,

u
x
2
x 4
( (
d
F
1

d
F
0
dy dx 8
( (
dx dy
8 Int1(F, r, 0 , 2)

u
Exercises.
T
1. Find the integral of the vector field

(
y x
2
) (
z y
2
) (
x z
2
) 1
]
over
T
the curve r= (
t t
2
t
3
) , 0t1 using Int1.
2. Integrate f(x,y,z) = x - 3y
2
+ z over the line segment joining the origin and
the point (1,1,1) using Int2. Also integrate over the straight line from (0,0,0) to
(1,1,0) and then from (1,1,0) to (1,1,1).
3. Compute F dr where F is the vector field from exercise 1 over the to
curves described in exercise 2.
129
Dv
a
v u
3.4.6 Surface integrals
We repeat some definitions from the previous subsection:
D, Val, ValV, len, div
If S is a vector of expressions containing the variables u and v we define the
partial derivatives:
T T
_ _
Du S ( ) :

S
0
S
1
S
2
( ) :

S
0
S
1
S
2
Dv S

u u u
,
v v v
,
In the function below, U is a scalar expression in u,v. The double integrals are
performed either with u. first and then v (=0) or with v first and the u(=1). A,
a, B, b are scalar expressions possibly involving one of the variables v,u.

A
DInt(U, a , A, b , B , ) : return ( ( Udu dv if = 0

b a

B
return ( ( Udv du if = 1

a b
Example 1
1 1
DInt(u + v , 0 , 1 v , 0 , 1 , 0) DInt(u + v , 0 , 1 , 0 , 1 u , 1)
3 3
After this you can double integrate a vector function in x,y or u,v component
wise:

DInt(U
0
, a , A, b , B , )
_

VDInt(U, a, A, b , B , ) :

DInt(U
1
, a , A, b , B , )


DInt(U
2
, a , A, b , B , )
,

Example 2
2

a uv
_

U :
a uv
2

VDInt(U, 0 , 1 v , 0 , 1 , 0)
T


1
a
2
1
a
1
_



24 60 120
,

u
3
v
,
VDInt(U, 0 , 1 , 0 , 1 u , 1)
T


1
a
2
1
a
1
_


24 60 120
,
The normal to a surface.
A surface can be given either as the graph of a scalar function of two variables
x,y or as the graph of a three dimensional vector function of two variables u,v.
In the function below, U is either a scalar expression in the variables x,y or a
vector expression in the variables u,v:
N U) : Du(U) Dv( ) ( U
130


N
x
N
u
u
N S
v
v
Example 3.
v ( )
_
cos( )
_
cos v
U :

sin v (

( )


( )


N U) simplify

sin v

u
,
0
,
Integrals of the type
S
FdS
SInt1(F, S, a , A, b , B ,
)
: DInt(ValV(F, S) N S N( ) , a , A, b , B ,
)
Example 4. The integral of
F : ( x y z )
T
over the cylinder x
2
+y
2
1, 0z1.
x
On the curved part of the cylinder, you have:
v ( )
_
cos( )
_
cos v
S :

sin v

( )


( )


Here
( )

sin v

u
,
0
,
This points inwards, to you have take the negative of SInt1:
SInt1(F, S, 0 , 2, 0 , 1 , 0) 2
On the bottom base surface you have z=0:
SB : ( ucos v ( ) 0 )
T
( ) usin v
SInt1(F, SB, 0 , 1 , 0 , 2, 0)
0
On the top surface you have z=1:
ST : ( ucos v ( ) 1 )
T
( ) usin v
SInt1(F, ST, 0 , 1 , 0 , 2, 0)

Hence the surface integral is 3. This could also have been done using Gauss'
theorem. You find
div F ( ) 3
The integral of this constant over the
cylinder is the constant times the volume of the cylinder, i.e. 3 as before.
Integrals of the type
S
f dS, where f is a scalar field
S SInt2(f , S, a, A, b , B ,
)
: DInt(Val(f , S)len(N( )) , a , A, b , B ,
)
Example 4, continued Suppose:
: x
2
yz
Then the integral of f over the curved
SInt2(
, S, 0 , 1 , 0 , 2, 0)
0
surface of the cylinder is
On the bottom base surface you have
SInt2(
, SB, 0 , 1 , 0 , 2, 0)
0
On the top surface you have:
SInt2(
, SR, 0 , 1 , 0 , 2, 0)
0
In total, the integral is 0.
Integrals of the type
S
FdS, where F is a vector field
S SInt3(U, S, a , A, b , B , ) : VDInt(ValV(U, S) N( ) , a, A, b , B , )
Example 4 continued. For the curved part of the cylinder you find:
131
v
N
N
N S
SInt3(U, S, 0 , 1 , 0 , 2, 0)
T
( 0 0 0 )
At the bottom:
SInt3(U, SB, 0 , 1 , 0 , 2, 0)
T
( 0 0 0 )
At the top:
SInt3(U, ST, 0 , 1 , 0 , 2, 0)
T
( 0 0 0 )
So, the total integral is 0.
Integrals of the type
S
dS, where is a scalar field
SInt4( , S, a, A, b , B , ) : VDInt(Val( , S)N( ) , a , A, b , B , )
Example 4 continued. On the curved part of the surface:
T
SInt4
(
x
2
yz, S, 0 , 1 , 0 , 2, 0
)


0
1
0

_

8
,
Since the normal points inwards, you have to take the negative of this.
T
On the bottom surface
SInt4
(
x
2
yz , SB, 0 , 1 , 0 , 2, 0
)
( 0 0 0 )
T
On the top surface:
SInt4
(
x
2
yz , ST, 0 , 1 , 0 , 2, 0
)
( 0 0 0 )
3.4.7 Surface areas
For a surface gives by a parameter function S in the independent variables u and
v, the surface element is:
D S S ( ) : len(N( ))
integrating D(S).
S SArea(S, a , A, b , B ,
)
: DInt(len(N( )) ,
Example 1. The surface area of the sphere

Rcos( )cos u v ( )
_
S :

Rcos v ( )


( )sin u


Rsin v ( )
,
So the area is found by
a , A, b , B ,
)
SArea

S, 0 , 2,

,

, 1

_
assume, R > 0
4R
2

2 2
,
simplify
3.4.8 Triple Integrals
Triple integrals are treated much the same way as double integrals.
Example 1

1
1
1

z

z
2
y
2

1
( ( ( z dx dy dz
( (
( z dx dy dz

0
2


z
2
y
2

4
0 z
132
u
J J U
w
y
Substitutions
Suppose you have a vector expression U representing a coordinate change from
(u,v,w) to (x,y,z). Then you can define the Jacobian matrix:
_

U
0
U
0
U
0

u v w

and the Jacobian determinant:

( ) : J( ) ( ) :

U
1
U
1
U
1
JD U U

u v w



U
2
U
2
U
2

u v w
,
Then a triple integral will be transformed into the integral:

( ) du dv dw ( ( ( f dx dy dz ( ( ( Val(f , U)JD U

Example 2. Spherical coordinates
( )cos w

usin v ( )
_
U u , v , w) :


usin v ( )

( )u
2
( ( )sin w

JD(U(u , v , w)) simplify sin v

ucos v ( )
,
Therefore, the volume of the sphere, which is the triple integral of 1 over the
sphere, can be written

2
( )u
2
dwdv du
4
R
3
( ( ( sin v

0
3
The mass of a ball with radius R and density proportional to the distance from
the center is:

2
( )u
2
dwdv du R
4
( ( ( usin v

0 0 0
Def. of div, grad, curl
Example 8. Verify Stokes' theorem for the field
F : ( y z x )
T
over the
paraboloid z=1-(x
2
+y
2
), z0.
)
T
The paraboloid has the parameter function
S :
(
ucos v ( ) 1 u
2
( ) usin v
133






t
The surface integral of curl F over the curved part of the paraboloid is therefore:
SInt1(curl F ( ) , S, 0 , 1 , 0 , 2, 0)

The limiting circle of the boundary has the parameter function
r : ( cos(t) sin t ( ) 0 )
T
Int1(F, r, 0 , 2
)

Exercises.

y
_
1. Find the integral of

2

over the parabolic cylinder y=x2, 0x2, 0z3


x z
,

x
2
_

2. Find the integral of

0

over the portion of the plane x+y+z=1 in the first


3y
2
,
octant.
3. Find the integral of x+y+z over the surface z=x+y, 0yx, 0x1
( ))cos u

(a + bcos v ( )
1
4. Find the area of the torus

(a + bcos v ( )
1

( ))sin u
1

bsin v ( )
]
x

e
_

5. Verify the divergence theorem for the vector field

ye
x

over the surface


3z
,
x
2
+y
2
c
2
, 0zh.

z
2
_

6. Verify Stokes' theorem for the field
0
for the square 0x,y1, z=1


4x
,
134
4 Differential equations
4.1 Differential equations of order one
Mathcad 6.0 Plus doesn't have a general built-in tool for solving differential
equations symbolically. However, since it has built-in tools for symbolic
integration and differentiation, you can still use Mathcad as a computing aid
when solving ODEs. And Mathcad is well equipped to solve ODEs
numerically. Let's look at some of the most important types of ODEs.
4.1.1 Indefinite integrals y'=f(x)
This is equivalent to finding an antiderivative of f, which can be done by
means of the symbolic integration operator, which you can find on the third
vertical tool bar. You can define a SmartMath function, where U is the
expression to integrate:

AntiDerive(U, C) : ( Udx + C

Example: f x , C) : AntiDerive(cos x ( ) + C ( ( ) , C) sin x
Exercise: Find the antiderivative of x
2
, tan(x), ln(x)
4.1.2 Separable equations f(y) dy = g(x) dx
Here you can integrate both sides of the equation, and then try to solve the
result with respect to y.
Example: y = 2xy
can be written
dy
= 2 xdx
y


Now
(
1
dy ln y ( )
and
( 2 x dx x
2
( y


So the equation has the solution:
ln y
2
( ) = x + C
This can be solved with respect to y using Symbolic - Solve for Variable to
get the general solution:
ln y ( ) = x
2
+ C solve , y exp
(
x
2
+ C
)
Exercise. Solve the following separable differential equations:
2 2 2
d
x
y =
(
1 + y
2
)
e
x
y =
x
y
y =
y 1
x
+ x
3
)
dx
y =
1 + y
2

(
135
x
x
g x 4.1.3 Linear equations y + f x ( )y = ( )
This has the general solution

_

Lin1(f , g , C) exp

( f dx

(
exp

( f dx

g dx + C

,
(


,
3
Example: y + y = x (x 0)
Here you find the general
>
x
solution:
( F x , C) : Lin1


3
, x , C
,

_
expand
1
x
2
+
1
3
C

x 5
x
Exercise. Solve the following linear equations:
( ) x y + 2y = sin x y 2xy = x y +
y
= 3 cos 2x ( ) y + 2xy = 2xe
x
2
x
4.1.4 Linear equations y' - a y = g(x), where a is a
constant.
In this case the general solution can be written as


_
Lin1c(g , a , C) : exp(ax)

( exp(ax)g dx + C


,
In particular, if g(x) is a polynomial, you can always get a result. :
Example: y
Define
P : 1 +
The solution is:
2y = 1 +
2x + 5 x
2

2x + 5 x
2

+ 6 x
3

( h x , C) : Lin1c(P, 2 , C) expand
+ 6 x
3

9
8 x 7 x
2
3 x
3
+ exp x ( )
2
C
2
Exercises. Find the solutions of the following equations:
y ay = A e
kx
for k=a and for ka

y ay = Acos(
x)
+ Bsin(
x)
+ 3y = x + e
2x
y y = 2e
x
y y = 2xe
2x
y 2y = x
2
e
2x
136
x
g x
x
4.1.5 Bernoulli's equation y + yf x
n
( ) = y ( )
The substitution z=y
1-n
will lead to the equation z'+(1-n)z f(x) = (1-n) g(x),
which is a linear equation. Its solution can be expressed as:
1
1 n


1 1

( ( ( 1 1

(1 n)
(
f dx

(
(
(1 n)f dx
1 1
Ber(f , g , n , C)

e

(
e (1 n)g dx + C
1 1


] ]

3
Solution: Example: y + y = x y
1
( F x , C) : Ber(1 , x , 3 , C) expand

1
_


1
( )
2
C
_


2
,

x + + exp x

2
,
Exercises. Solve the following equations:
y y = x y
5
:

y + 2xy + x y
4
= 0
4.1.6 Total differentials
If the equation can be written in the form P dx + Q dy = 0, where P
y
= Q
x
, i.e.
the left hand side is a total differential, then S(x,y)=C will be a solution, where
S(x,y) is given in the following formula:


(

_
TotDiff (P, Q) ( Pdx +
(

Q
d
( Pdx

dy

(


dy

,

Example: P : 4x
3
+ 2 xy + y
2
Q : x
2
+ 2 xy 4 y
3

You find:
d
P 2 x + 2 y
d
Q 2 x + 2 y
dy dx
and the solution is S(x,y)=C, where:
( S x , y) : TotDiff (P, Q) x
4
+ x
2
y + y
2
x y
4
You can use Insert - Graph - Contour Plot from the menu to draw a family
of integral curves.
Exercises. Solve the following equations:
(
4x
3
y
3
2 xy
)
dx +
(
3 x
4
y
2
x
2
)
dy = 0 3e
3x
y 2x
)
dx + e
3x
dy = 0
137
D y
x
4.2 Differential equations of order two
or higher
4.2.1 Homogeneous equations with constant
coefficients
Mathcad can be used effectively to solve equations with constant coefficients
of the form y''+a y' + b y = R(x). Let's first look at the homogeneous equation
y''+ay'+by=0. The solution depends on the root of the characteristic equation
r
2
+ar+b=0, which you can solve numerically or symbolically.
Example 1. y''+5y'+6y=0.
The differential operator corresponding to the left hand side is:
d
2
d
( ) : y + 5 y + 6 y
dx
2
dx
The characteristic equation is
R
2
+ 5 R + 6 = 0
You find the solutions:

r : R
2
+ 5R + 6 solve , R

3
_

2
,
Actually you just get the vector, but then you can insert a definition in front of
it. The solution is then:
( F x , A, B) :
(
Aexp
(
r
0
x
)
+ Bexp
(
r
1
x
))
Aexp(3x) + Bexp(2x)
This can be verified using the differential operator above:
D F(x , A, B)) 0 (
Mathcad's contribution in this case was to find the roots of the characteristic
equation, and to verify the solution. This is not very significant for 2. order
equations, but it will be more important for higher order equations. Cases
where the characteristic equation has two equal roots or complex roots will
have to be done in a similar way. If you have an ODE whose characteristic
equation has multiple roots, it's better to use factor than solve:
Example 2. y'''-3y''+3y'-y=0 has characteristic polynomial:
R
3
3 R
2
+ 3 R 1 factor (R 1)
3

Exercises. Solve and verify the solutions of the following differential
equations:
y'' + y' -6y = 0 y'''-y''-12 y' = 0 y''''+6y'''+5y''-24y'-36y=0
y''-2y'+10y=0 y'''+4y'=0 y''''+y'''+2y''-y'+3y=0
138
x
x
4.2.2 Inhomogeneous equations with constant
coefficients
The method of undetermined coefficients
The contribution from Mathcad will be more significant when the calculations
become heavier, as they do with inhomogeneous equations. You still have to
know the theory about ODEs, so you know what kind of solutions you must
look. But Mathcad can help you find the unknown coefficients.
Example 1. y''-2y'+y=(x+1)e
x
d
2
d
The differential operator is here
D1 y ( ) : y 2 y + y
dx
2
dx
The characteristic equation r
2
-2r+1=0 has the double root 1, and so the
homogeneous equation has the general solution
H1(x , C1, C2) : (C1 + C2x)exp x ( )
You can check that this is indeed a solution of the homogeneous equation:
D1(H1(x , C1, C2)) 0
Then according to the theory you must look for a particular solution of the
form:
P x , A, B) :
(
Ax
2
+ B x
3
)
exp x ( ( )
You find
D1(P(x , A, B)) factor 2(A + 3Bx)exp x ( )
:
1 1
Therefore,
A =
and
B =
2 6
The general solution is therefore
GS(x , C1, C2) :

C1 + C2x +
1
x
2
+
1
x
3

,
_
exp x ( )

2 6
Check the result:
D1(GS(x , C1, C2)) factor (1 + x)exp x ( )
Example 2. y''+4y = xe
x
+x sin 2x
d
2
Differential operator:
D2 y ( ) :
2
y + 4 y
dx
The homogeneous equation has the general solution C1 cos 2x + C2 sin 2x .
You have to try a particular solution of the following form:
139
P2(x , a , b , c , d , f , g) : (ax + b)exp x ( ) +
(
c x
2
+ d x
)
cos(2x) ...
+
(
f x
2
+ g x
)
sin(2x)
To find the undetermined coefficients, evaluate D2(P2(x,a,b,c,d,f,g)) using
collect:
collect , sin 2x ( )
D2(P2(x , a , b , c , d , f , g))
collect , cos 2x ( )
collect , exp x ( )
The result is too long for the page width. Written on three lines, it looks like
this:

(2 a + 5 ax + 5 b)exp x ( ) ...
1
...

+ (2 c + 8 fx + 4 g)cos(2x)
]

+ (8cx 4 d + 2 f)sin(2x)
Then you can find the undetermined coefficients by means of one of Mathcad's
equation solvers:
Given 5a = 1 2a + 5b = 0 8f = 0 2c + 4g = 0
8c = 1 4d + 2f = 0
A : Find(a , b , c , d , f , g)
T


1 2 1
0 0
1
_


5 25 8 16
,
So, the general solution of the equation is:
GS(x , C1, C2) :


1
x
2
_

e
x
+


1
x
2
+ C1

_
cos(2x) ...

5 25
,
8
,
+


1
x + C2

_
sin(2x)

16
,
Check the solution:
D2(GS(x , C1, C2)) simplify exp x ( )x + xsin(2x)
Exercises. Find the general solution of the following diff. equations:
(
D
2
3D + 2
)
y = e
x
(
D
2
3D + 2
)
y = e
5x
(
D
2
+ 5D + 4
)
y = 3 2x
( )
(
D
2
+ 4
)
y = 2 cos(x)cos 3x
(
D
2
+ 9
)
y = xcos x ( )
3x
(
D
2
9D + 18
)
y = e
e
(
D
2
4D + 3
)
y = 1
(
D
2
4D
)
y = 5
(
D
2
6D + 9
)
y = e
2x
(
D
2
+ D 2
)
y = 2
(
1 + x x
2
)
(
D
2
1
)
y = 4xe
x
(
D
2
1
)
y =
(
1 + e
x
)
2
140
P x
Equations of order 3 or higher
The help you can get from Mathcad is similar for higher order equations as for
second order equations: You have to know the theory, but once you know
what form of solution to look for, Mathcad can help you determine it. We
show the method by an example.
Example 1. y''' - 4 y' = x + 3 cos x + e
- 2x
Differential operator:
D1(u , x) :
d
3
u 4
d
u
dx
3
dx
The solutions of the homogeneous equation are obviously r=0,-2,2. So the
general solution of the homogeneous equation is c
1
x + c
2
e
-2x
+ c
3
e
2x
.
According to the theory you must look for a particular solution of the form:
PS(x , A1, B , C , D, E) : A1x + B x
2
+ Ccos x ( ) + E xexp(2x ( ) + Dsin x
By symbolic evaluation of D1(PS(x,A,B,C,D,E),x) using [Ctrl][Period] you
find:
5 Csin x ( ) + 8 Eexp(2x) 4 A1 8 Bx ( ) 5 Dcos x
Comparing coefficients:
Given 5 C = 0 5D1 = 3 8 E = 1 4A1 = 0 8B = 1
Find(A1, B , C , D1, E)
T


0
1
0
3 1
_


8 5 8
,
(The use of D and A as a variable name here gives an error.)
So, the particular solution is
( ) :
1
x
2

3
sin x
1
( ) + xexp(2
8 5 8
Hence the general solution is:
( ( ) + xexp(2x) ... G x , C1, C2, C3) :
1
x
2

3
sin x
1
8 5 8
+ C1x + C2exp(2x) + C3exp(2x)
Exercises. Find the general solution of the following diff. equations:
(
D
3
+ 3D
2
4
)
y = xe
2x
(
D
3
5D
2
+ 8D 4
)
y = e
2x
(
D
3
4D
2
)
y = 5
(
D
5
4D
3
)
y = 0
(
D
3
4D
)
y = x
141
D y
A
4.2.3 Solution by power series expansion
Mathcad can be used to help finding solutions of ODEs by power series
expansion, but you must limit yourself to a finite number of terms.
Example. Airy's Equation y''- xy=0
Say you want to find the first six terms of the Taylor expansion of the solution
of Airy's equation y''-xy=0 with the initial conditions y(0)=1 and y'(0)=0.
d
2
Differential operator:
( ) : y x y x
dx
2
Let's try a polynomial of degree six:
U : A00 + A1x + A2x
2
+ A3x
3
+ A4x
4
+ A5x
5
+ A6x
6

2 A2
_


6 A3 A0

lim U A0



x0

12A4 A1

(
Then
D U) coeffs , x


20A5 A2


lim
d
U A1

30A6 A3

x0
dx

A4

So, the initial conditions give:

A5


A0 = 1 A1 = 0

A6
,
To find the coefficients so that all the terms up to degree 6 are zero, you can
use (say) the solve keyword:


A0 = 1
_

A1 = 0


A0
_


2A2 = 0


A1

A2

6A3 A0 = 0


solve ,

A3


1 0 0
1
0 0
1
_


12A4 A1 = 0


A4



6 180
,

20A5 A2 = 0


30A6 A3 = 0


A5



A6
,

A4 = 0
,
142
f x
So, the first terms of the power series of the solution is
( ( )) expand
1
x
7
( ) : 1 +
1
x
3
+
1
x
6
As a check,
D f x
6 180 180
So, f(x) is indeed a correct sixth degree approximation to the solution.
Mathcad has the two linearly independent solutions of Airy's equation as
built-in functions with the names Ai(x) and Bi(x). Let's use them to solve the
above initial value problem:
G x , C1, C2) : C1Ai x ( ) ( ( ) + C2Bi x
We find the values of the derivatives at 0:
Ai x ( ) z2 0.448 x : 0 z1 :
d
( ) z1 0.259 z2 :
d
Bi x
dx dx
Then you can find the coefficients C1 and C2 by means of the initial
conditions:
C1 : 0 C2 : 0 TOL : 10
10
Given C1Ai 0 ( ) = 1 C1z1 + C2z2 = 0 ( ) + C2Bi 0

c1
_
c1
_
1.4083394102
_

: Find(C1, C2)



c2
,
c2
,
0.8131051376
,
Then you define
F x ( ) + c2Bi x ( ) : c1Ai x ( )
and draw the graphs near 0:
x : 3 , 2.9.. 3
5
10
f x ( )
F x ( )
2 0 2
x
Exercises. Find sixth degree approximations to the solutions of the following
equations:
y'' - y = 0 y'' - x y' - y = 0 y'' - x y' - y = 0 (1 - x) y'' + y = 0
y'' + x y' + 2 y = 0 Choose your own initial conditions.
143
y 0
f x
4.3 Laplace transforms
4.3.1 The built-in Laplace transform
Mathcad has the Laplace transform and its inverse Use can use Symbolics -
Transform - Laplace from the menu, or you can use the [laplace] button on
the Symbolic Toolbar. With the menu and the cursor on t:
( )
has Laplace transform a
sin at
With the Symbolic Toolbar: (
s
2
+ a
2
)
a a
( ) sin(at) laplace, t
(
s
2
+ a
2
) (
s
2
+ a
2
)
invlaplace , s sin at
The Laplace transforms have also an undocumented (Maple) syntax:
( ) , t , s)
(
s
2
+
a
a
2
)
invlaplace


s
2
+
a
a
2
, s, t

_
sin at laplace(sin at ( )
,
4.3.2 Application to initial value problems
The main application of Laplace transforms is solving initial value problems.
So, suppose we have an initial value problem:
n
p
n
y
( )
+ p
n 1
y
(n 1)
+ .. + p
1
y + p
0
y = ( )

( ) = y
1
...
y
(n 1)
0

( ) = y
0
y 0

( ) = y
n 1
It can be shown easily (cf. any standard textbook) that the Laplace transform
of the ith derivative of a function can be expressed in terms of the Laplace
transform of the function itself in the following way:
n
laplace

y
( )
1
]
= s
i
laplace y


i
( )

s
i k
y
k 1
k 1
Hence the Laplace transform of the left hand side of the differential equation
above can be written as:
( )1

rows p rows p ( )1
1

L p , y , u , Ly) :

p
i


u
i
Ly

u
i k
y
k 1
(k i)
1
(

1
i 0

k 1
]
Then we can write a function that solves the differential equation:
144
y t
D U
t
DiffSolve
t
DiffSolve(p , y , f) : A L(p , y , s, Ly)
B solve(A laplace(f , t , s) , Ly)
invlaplace(B , s, t)
Example. In the initial value problem y - 3 y + 2 y' = e
-t
sin t + t
2
,
y
0
=5, y
1
=6, y
2
=7
( ) + t
2
)
p : ( 0 2 3 1 )
T
y : ( 5 6 7 )
T
Y : DiffSolve
(
p , y , e
t
sin t
Symbolic evaluation by [Ctrl]Period gives
1
t
3
+
3
t
2
+
7
t +
13
+
14
exp t
27 1
t ( ) ( ) +
40
exp(2t)
10
exp( )cos t
6 4 4 8 5
You can check the solution in the following way:
( ) :
d
3
3
U 3
d
2
2
U + 2
d
U
( ( ) + t
2
dt dt
dt
D Y) exp(t)sin t
The initial conditions:
d d
2
lim Y 5 lim Y 6 lim Y 7
t0 t0
dt
t0 dt
2
You can also use Laplace transforms on a set of simultaneous equations.
Example x = 6x + y y = 4x + 3y
First, apply Laplace transform and use the result above aboutb the laplace
transform of a derivative. Then use a symbolic solve block to find the Laplace
transforms:
Given
(2 s + 1)
1

s LX 2 = 6 LX + LY

s LY 7 = 4LX + 3LY Find(LX, LY)


(
s
2
9 s + 14
)
1
1

(7 s 34) 1

(
s
2
9 s + 14
)
]
1

Then you find the inverse Laplace transform of each component:



x t ( ) :
(
s
2
(

2 s
9 s
+
+
1)
14
)
invlaplace , s exp(2t) + 3exp(7t)

( ) :
(7 s 34)
)
invlaplace , s 4exp(2t) + 3exp(7t)
(
s
2
9 s + 14
Exercise. Find the "rest solution" (i.e. the particular solution where the
function and its derivatives are 0 at 0) of the diff. equation y'''' + 3y''' + 2y'' +
6y' = t
2.
145
n
D
A
4.4 Difference equations
4.4.1 Method of undetermined coefficients
For difference equations, the situation is much the same as for differential
equations. You have to know from the theory what solutions to look for, but
then Mathcad can help you do the calculations. The following operator will
replace n by n+i in an expression y:
( D y , i) : lim lim y
n+ tttn i nttt
Below, we are going to assume that all indices are named n
Example. Find the solution of the difference equation y
n+2
+ 3 y
n+1
+ 2 y
n
= n
The characteristic equation and its solutions:
2
2
_
r + 3r + 2 solve , r

1
,
Therefore, (-2)
n
and (-1)
n
are the two linearly independent solutions to the
equations. Let's check this. The difference operator is
D1 y ( ) : D(y , 2) + 3 D(y , 1) + 2 D(y , 0)
You find
D1

( )
n
1
]
0 D1

( )
n
1
]
0

1
According to the theory, the inhomogeneous equation must have a solution of
the form
( ) 6A + 6 Bn + 5 B Y : A + Bn
You find:
D1 Y
Comparing coefficients and solving, you find
Given 6A + 5B = 0 6B = 1 Find(A, B)
T


5 1
_


36 6
,
So, the general solution of the inhomogeneous equation is:
1 2 ( ) n Y :
1
n
5
+ C1( )
n
+ C2( )
n
Control:
D1 Y
6 36
Exercises. Solve the following difference equations:
y
n 2
y
n 1
y
n
= 0
with initial conditions
y
0
= 1 y
1
= 1
(Fibonacci)
+ +
y
n 2
4 y
n 1
+ 4 y
n
= n 2
n
y
n 2
+
2
y
n
= 2
n
+ +

+
+
The system
x
n 1
x
n
y
n
= n
y
n 1
x
n
+ y
n
= 3
with initial conditions
x
0
= 0 y
0
= 10
+
146
y n
4.4.2 The z transform
If x(n) is a function that defines a number sequence, then the z-transform of x
is given in the formula:

For instance, if
x n ( ) : 2
n
then
( ( )z
n
Z x , z) :

x n
z
(
n 0
Z x , z)
(2 + z)
Mathcad has the z-transform and its inverse as built-in functions. You can use
the menu choice Symbolics - Transform - Z (or Symbolics - Transform -
InverseZ) or you can use the analogous buttons on the Symbolic Toolbar.
There is also an undocumented Maple syntax
ztrans(expression,variable,name) and similarly
invztrans(expression,variable,name)
z z
2
n
ztrans, n 2
n
has z transform
(2 + z) (2 + z)
z z
invztrans , z 2
n
has inverse z transform
2
n
2 + z 2 + z
ztrans
(
2
n
, n , z
)

z
invztrans


z
, z , n

_
2
n
(2 + z)

2 + z
,
Applications to difference equations
The main application of the z-transform is to solve difference equations with
initial conditions:
(

(

( a
N
y n + N) + a
N 1
y n + N 1) + a
N 2
y n + N 2) + .. + a
0
( ) = f(
with y(0),...,y(N-1) given in a vector y.
The most important property of the z transform is the following: If Y(z) is the
z-transform of y(n), then z Y(z) - z y(0) is the z-transform of y(n+1) and in
general: If Y(z) is the z transform of y(n), then z
k
Y(z) - z
k
Y(0) -z
k-1
Y(1) - ...-
z Y(k-1) is the z-transform of Y(n+k)
( ) 1 ZZ(a , y , z, Z) : N rows a
N

N 1
1



a
N i


z
N i
Z

( j N i)z
N i j
y
j
1

<
1
i 0

j 0
]
147
n
D
n
D
Then you can write a symbolic program to solve the difference equations by
means of the z transform:
DS(a , y , f) : A ZZ(a , y , z , ZT)
B solve(A ztrans(f , n , z) , ZT)
invztrans(B , z, n)
Example Solve the initial value problem y
n+2
+ y
n+1
-6y
n
= 2
n+2
-1, y
0
=1, y
1
=1
With the notations above:

6
_
n+
a :

1

y :


1
_

f : 2
n 2
1


1
,

1
,
Y : DS
+
3 S
(
a , y , 2
n 2
1
)
Y
31
( )
n
+
1
+
2
2
n
n +
11
2
n
100 4 5 25
Let's check the solution:
D y , i) : lim lim y
D1 y
(
tttn i nttt
( ) : D(y , 2) + D(y , 1) 6 D(y , 0)
n+
3 Y :
31
( )
n
+
1
+
11
2
n
+
2
2
n
n
100 4 25 5
D1 Y ( ) 42
n
1 Y substitute, n = 0 1 Y substitute, n = 1 1
Exercise. Solve the following difference equations by means of the z
transform:
y
n 1
y
n
= 2 y
0
= 1 y
n 2
y
n 1
y
n
= 0 y
0
= 1 y
1
= 1
+ + +
148
f x
f x
4.5 Fourier series
4.5.1 Fourier coefficients and Fourier series
You can define the Fourier coefficients of a function f by the following
symbolic functions:
L

L
(
( )cos


nx
_

dx FourierA(f , L, n) :
1

(
f x


L
,
L
L

L
(
( )sin


nx
_

dx FourierB(f , L, n) :
1

(
f x


L
,
L
The the Fourier series with N terms can be defined as:
1
L
FourierSum(f , x , L, N) : ( ( ) dx ...
2 L
L
N
+

FourierA(f , L, n)cos


nx
_

...

_
n 1

L
,
+ FourierB(f , L, n)sin


nx



L
, ,
Given a function f defined on some interval [-L,L], you can define the
periodic extension of f defined for all x by the following:
Periodic(f , L, x) : f

x 2Lfloor


x + L


2 L
,,
Example 1.
( ) : x h x ( ) : Periodic(f , , x) x : 5 , 4.9.. 5
g x x , ( ) sin(2x) + sin(3x) ( ) : FourierSum(f , , 3) 2sin x
2
3
6 4 2 2 4 6
5
5
h x ( )
g x ( )
0
x
Exercise. Repeat example 1 with the function f(x) = x
2
.
149
g x
g x
f x
4.5.2 Step functions
Fourier coefficients also work with discontinuous functions, as long as they
are piecewise continuous. The question is how discontinuous functions can be
defined in a way that symbolic Mathcad can understand. The solution lies in
Heaviside's step function , which both symbolic and numerical Mathcad
understand. It is equivalent to if(x<0,0,1).

1
( x ( ) dx 1 ( ) dx 1 ( x

1
You can use Heaviside's step function to define a function by different
formulae on different intervals. (x-a)-(x-b) is a function that is 1 on [a,b
and 0 otherwise. Here are two examples:
Example 1 ( ) :
(

(x +
)
x 1 ( )
(x
)) ( ))
( ) +
(
x

( f x ( ) dx expand 0 ( )cos x


So the Fourier series of f has to be evaluated by expanding:
x , ( ) +
(3
)
sin(3x) Fof(x) : FourierSum(f , , 3)

4
sin x
4

here are the graphs:
f2(x) : Periodic(f , , x) x : 10, 9.95 .. 10
10 5 5 10
f2 x ( )
Fof x ( )
0
x
Exercises. Repeat the example with the following functions:
( ))

(x +
)
+
(
x ( ) :
(

(x +
)
x ( )
(x
))

(
x)
( ))
+
(
x ( ) :
(

(x +
)
x ( )
(x
))

(
1 + x
2
)
150
4.5.3 Fourier transforms
Mathcad has the Fourier transform and its inverse built-in. They are defined as
follows:


( )exp(
t) dt Fourier(f ,
)
: ( f t i


1

( )exp(it) d InvFourier(f , t) : ( f
2


You can get them in three ways:
Write the expression, say
exp
(
x
2
) Then put the cursor on an x and choose
Symbolics - Transform - Fourier from the menu. The result is

1
_


2
,
exp

_
.You can compare this with

4
,

1
_


t
2

( exp
( )
exp(
t) dt exp


2
,
i



4
,
Alternatively write the expression and click on the [fourier] button the
symbolic toolbar, and write x or whatever name you have used for the
independent variable in the placeholder:

1
_

.
exp
(
x
2
)
fourier, x exp


2
,

4
,
Finally, you can use a Maple syntax:

1
_

fourier
(
exp
(
x
2
)
, x , t
)


2
,
exp


1
t
2
_


4
,
Here it is possible to choose the names of the independent variable both of the
input and the output.
You have similar choices for the inverse Fourier transform:
t
2
exp

_
has inverse Fourier transform
1
4exp
( )

4
,
2

2
_
invfourier,
exp
( )
exp t
2

4
,
simplify
151
f x
invfourier

exp

w
2
_
, w, x
,

_
simplify exp
(
x
2
)

4
,
The Fourier transform is linear, and has the property that the Fourier transform
of f'(x) is i times the Fourier transform of f(x).
Also, for a function of two variables u(x,t), the Fourier transform of
u x , t) (
t
is the partial derivative of the Fourier transform of u.
4.5.4 Fourier transforms and the heat equation
The main application for Fourier transforms is partial differential equations.
Suppose for example that you have a heat conduction problem in an infinite
slab:
2
( ( )
u(x,t) bounded
u u = 0 u x , 0) = f x
t
x
2
Taking Fourier transforms of the differential equation you get
( )) fourier(u(x , t)) +
2
fourier(u(x , t)) 0 fourier(u(x , t) , 0) fourier(f x
t
This problem has the solution
fourier(u(x , t)) fourier(f x ( ))exp
(

2
t
)
2
For instance, if
( ) : e
x
then

1
_

fourier(f x x , ( ) , )exp

( )
2
t
]
1
simplify

2
,
exp

2
(1 + 4 t)
1
1

4
]
So the solution is:

x
2
1
( exp


1 1
exp


(4 t + 1)
1
]

u x , t) : invfourier (1 + 4 t)1 , , x1

4
] ]

1
_

(4 t + 1)

2
,

You can check the solution:
2 simplify
( ( ( u x , t)
2
u x , t)
assume, t > 0
0 u x , 0) simplify exp
(
x
2
)
t
x










152
f x
f x
4.5.5 Discrete Fourier Transforms
Mathcad has built-in functions for the Fast Fourier Transform.
To motivate this, notice that the Fourier series of a function f can be written in
complex formulation as
L

2 L
(
( )exp

i
nx
_

dx CFourier(f , L, n) :
1

(
f x


L
,
L
1
L
CFS(f , x , L, N) : ( ( ) dx ...
L
L
N
x
_
+

CFourier(f , x , L, n)exp


i n

...

_
n 1

L
,
n
+ CFourier(f , x , L, n)exp


i x



L
, ,
L

i
jx

(
i


jx
_

or as

c
j
e
L
with
c
j
=
1
( ( )e

L
,
dx
L

L
j
To get back the real Fourier coefficients, you compute:
a
0
= 2 c
0
a
j
= 2 Re c
j
( )

( )
b
j
= 2Im c
j
Now to compute the integral c
j
, you can approximate it by a Riemann sum.
Suppose you subdivide the interval [-L,L into n=2q subintervals of equal
lengths h=2L/n=L/q. The subdivision points then become
t
k
= L + k h k = 0 , 1 , .. , n
The upper Riemann approximation to the integral then becomes:
n
1
( )
exp


jt
k _

1
1
h
But
C
j
=
L


f t
k

L
,]
k 1
f t
k
( )
exp


j
L + k h
_

1
1
( )
exp


jt
k

_
1
1
f t
k


L
,]
L
,]
=
f t
k
( )
exp( ji)exp

i
2k j
_


n
,
Therefore
n
1
C
j
=
L
exp(i j
( )
exp

i
2
n
k j
_

,
or

)
h

f t
k
k 1
153
b j
f x
b j
n
C
j
=
2
exp(i j

( )
exp


2k j

_
1
1
1
1
n

)
h


f t
k

n
,]
1

k 1
]
Now this formula is closely related to the definition of Mathcad's function
FFT: Given a sequence of n=2
m
pairs (t
k
,v
k
), k=0,...,n-1 where the t's are evenly
spaced. You may interpret the v's as the displacement of a wave at time t. Then
the d=FFT(v) is a vector with n/2 + 1 = 2
m-1
+1 components such that:
n
d
j
=
1


v
k
exp

i
2 jk
_

n

n
,
k 1
Let's illustrate with an example where the Fourier coefficients are found by
means of the definitions and by means of the FFT to compare:
With the definition: ( ) : x L :
L

( ) :
1

(
f x
( )
+ jcos( ))
L
(
( )sin


j
L
x
_

,
dx

(
sin j
j
2
j

L
With FFT:
Number of points:
m : 13 n : 2
m
k : 0 .. n 1
Subdivision points:
x
k
: L + k
2
Observations:
v
k
: f x
k
( )
n
Using the FFT:
cc : FFT v ( )
n
Fourier coefficients:
k : 0 .. c
k
: 2exp(
i)
cc
k
k
2
Mathcad also has the inverse of FFT, with the name IFFT:
( )
then you can check that
ww = v
See below. If
ww : IFFT cc
Results for
j : 1 .. 25
Most of the coefficients agree up to 5 digits.
Define
C
j , 0
: j C
j , 1
: v
j
C
j , 2
: ( ) C
j , 3
: c
j
C
j , 4
: Im c
j
( )
C
j , 5
: ww
j
and write C= to see that.
Applications of FFT are of course not limited to finding the Fourier
coefficients of a known function. A more meaningful application is when the
function is not given explicitly, but only in terms of a certain number of values
of the displacements for the wave in a period. Then FFT gives information
about the frequency spectrum of the wave.
154
F x
4.6 Numerical solution of differential
equations
Mathcad has a variety of numerical differential equation solvers built-in. We
shall look at one of them namely the classical fourth order Runge-Kutta
method. Before we look at that, however, we shall look at some graphic tools
that can used to visualize differential equations.
4.6.1 Drawing a two dimensional vector field
Mathcad has a built-in function for drawing a two dimensional vector field.
Suppose F is a two dimensional vector field F: R
2
R
2
that you want to
illustrate by drawing arrows of the right length and direction at the points of a
rectangular grid in the rectangle [a,A] [b,] with +1 subdivision points in
the x direction and N+1 subdivision points in the y direction. The following
function gives a pair of matrices which you can use in Mathcad's vector field
plot tool, which you get access to by choosing Insert - Graph - Vector Field
Plot from the menu.
A a
VectorGrid(F, a , A, M , b , B , N) : h
M
B b
k
N
for m 0 .. M
x
m
a + mh
for n 0 .. N
y
n
b + nk

x
m _
M F


y
n
,
MX
m n
M
0 ,
MY
m n
M
1 ,

MX
_


MY
,
Example 1.

x
0 _
( ) :

M
0
: VectorGrid(F, 2 , 2 , 10, 2 , 2 , 10)

x
0
x
1
,
_

,
155
However, later on I want to draw a combined diagram with directions and
integral curves. For this I need to draw a vector field using the two
dimensional XY plot. Here is a program that does that. P is a complex polygon
- an "arrow" - to be drawn to indicate the directions:
DirField(F, a , A, M , b , B , N, P) :

dx
A a
_

dy
B b
_


M
,
N
,
P P
0.48if(dx < dy, dx, dy)
max(P) min P ( )
k 0
for m 0 .. M
x
m
a + mdx
for n 0 .. N
y
n
b + ndy

x
m __
ff F


y
n
,,
f ff
0
+ i ff
1

S

P f +
(
x
m
+ i y
n
)
k

k k + 1
S
156
Example 2.
F x ( )
x
0
x
0
x
1



_

,
: P
1
1



_

,
: P
1
1
0.5 0.5i +




_


,
:
M DirField F 2 , 2 , 11 , 2 , 2 , 10 , P , ( :
Im M ( )
Re M ( )
If you are only interested in the direction, you can define:
G x ( )
F x ( )
F x ( )
: A DirField G 2 , 2 , 11 , 2 , 2 , 10 , P , ( :
Im A ( )
Re A ( )
157
)
)
F x H x
F x
F x
4.6.2 Drawing a family of integral curves
A differential equation y'=f(x,y) may have a solution that can be written on
the form G(x,X,Y), where (X,Y) is a point in the plane which the integral
curve is required to pass through. We choose a grid dividing [a,A] [b,B] in
(M+1) (+1) points and using P+1 points on each integral curve.
Curves(G, a , A, M , b , B , N, P) :

dx
A a
_

dy
B b

_
(k 0)

M
,
N
,
A a
ddx
P
for m 0 .. M
X
m
a + mdx
for n 0 .. N
Y
n
b + ndx
for p 0 .. P
T
p
a + pddx
,
(
Z
p k
G T
p
, X
m
, Y
n
)
k k + 1

T
_


Z
,
Example 3. The differential equation y' = x
2
- y has the exact solution through
(a,b) given by
( G x , a, b) : x
2
2x + 2 +
(
a
2
+ b + 2a 2
)
exp(a x)
We plot the integral curves:
M : Curves(G, 2 , 2 , 5 , 2 , 2 , 5 , 50)
together with a plot of the directions:
1
( ) :


1
1
( ) :
( )
x
0

( )
2
x
1
]
( )
A : DirField(H, 2 , 2 , 10, 2 , 2 , 10, P)
158
g t
2
1
M
1
0
Im A ( )
1
2
2 1 0 1 2
M
0
, Re A ( )
4.6.3 Runge-Kutta's fourth order method rkfixed
Let's demonstrate the use of Mathcad's Runge-Kutta function rkfixed for
differential equations x' = f(t,x) on the initial value problem x'=F(t,x), x(0)=0,
where
F t , x) : t + x
. It can be shown that the exact solution of this problem
(
( )
is
( ) : t 1 + exp t
The rkfixed function needs five arguments:
x0 is a vector giving the initial conditions. In the one dimensional case
you have to give a vector with one component.
a and b are the endpoints of the interval for the independent variable t
N is the number of subdivision points in the interval [a,b]
F is the vector function giving the right-hand side of the differential
equation.
Let's choose
a : 0 b : 1 x0
0
: 0 N : 5
X1
X1
: rkfixed(x0, a, b , N, F)
For comparison:
0 0
_
0
_
0.2 0.0214






0.0214027582


0.4
0.6
0.09181796
0.2221064563




g X1
0
( )



0.0918246976
0.2221188004


0.8 0.4255208258






0.4255409285


1 0.7182511366
,
0.7182818285
,
159
The graphs look like this:
t : 0 , 0.05 .. 1
0 0.5 1
0.5 g t ( )
X1
1

t X1
0

,
Exact solution
Runge-Kutta
rkfixed is intended to work for differential equations equations in any
dimensions, so here is a two dimensional example:
Example 4. x'(t) = F(t,x), where:

x
0
4 x
1 _

1
_

F t , x) :

Initial condition:
x0 :

(

x
0
+ x
1
,

0
,
This is equivalent to the system
x = x 4y y = x + y
( ))
1
It can be shown that the exact

0.5(exp(t) + exp 3t
( ) :

solution of the initial value problem


X t

0.25(exp(t) exp 3t
1
( ))
]
is
With rkfixed:
R : rkfixed(x0, 0 , 2 , 10, F) t : 0 , 0.2.. 2

0 1 0
_
( 1 0 )
1

0.2 1.32 0.251

( 1.32 0.251)
1
1

0.4 1.994 0.662

( 1.995 0.662)
1

0.6 3.296 1.373

( 3.299 1.375)
1
1

0.8 5.728 2.639

( 5.736 2.643)
1
( )
T


( 10.227 4.929)
1
R

1 10.207 4.92

X t

1.2 18.406 9.053

( 18.45 9.074)
1
1

1.4 33.375 16.564

( 33.466 16.61)
1
1.6 60.665 30.231 ( 60.856 30.327 ) 1

1.8 110.393 55.114

( 110.786 55.31)
1
1

2 200.988 100.426
,
( 201.782 100.823)
]
160
The graphs look like this:
t : 0 , 0.05 .. 2

2
R
50
X t
0 2 100 200
100
50
R
2

X t ( )
1
( )
1
100

0 1
R , t R , X t ( )
0
4.6.4 Drawing a family of numerically computed
integral curves.
If S is rkfixed or any other numerical differential equation solver, here is a
function that draws a family of integral curves for a one dimensional
differential equation x'=D(t,x) through a M grid of points in the
rectangular area [a,A] [b,B].
IC(a , A, M , b , B , N, c , P, D, S) :

dt
A a
_

dx
B b

_
(k 0)

M
,
N
,
for m 0 .. M
t
m
a + mdt
for n 0 .. N
x
n
b + ndx
z
0
x
n
Z S
(
z, t
m
, t
m
+ c , P, D
)
Y

Z
k 1
for p 0 .. P
c
U
p k
t
m
+ p
,
P
k k + 1

U
_


Y
,
161
Example 5, cf. example 3
( F t , x) : t
2
x
0
M : IC(2 , 2 , 5 , 2 , 2 , 5 , 5 , 50, F, rkfixed)
2
M
1
0
2
2 0 2
M
0
The function IC can easily be extended to the two dimensional case:
IC2(a , A, M , b , B , N, c , P, D, S) :

dt

for

A a
_

dx
B b

_
(k 0
M
,
N
,
m 0 .. M
t
m
a + mdt
for n 0 .. N
x
n
b + ndx

t
m _
z0


x
n
,
Z S
(
z0, t
m
, t
m
+ c , P, D
)
X

Z
k 1
Y

Z
k 2
for p 0 .. P
c
T
p k
p
,
P
k k + 1

T
_

X



Y
,
162
4.6.5 ODEs of order two or higher
Second order ODEs can be transformed into a system of two first order
equations. Let's demonstrate the method on an example, say the ODE
y''-3y'+2y=t with the initial conditions y(0)=0.75, y'(0)=1.
Substitute x
0
=y, x
1
=y'. Then the ODE is equivalent to the system:
x
0
'(t) = x1
x
1
(t) = 3 x
1
+ 2 x
0
+ t
This system can be written on the form x'(t) = D(t,x), where:

x
1 _ The initial conditions

0.75
_
( D t , x) :


3 x
1
2 x
0
+ t
,

give the initial vector
x0 :

,
It can be shown that the exact solution is:

2
t +
4

2
exp t
1
( )
_


1 3 1
( ) +
2
exp 2t
F t ( ) :


1 1
( ) + exp 2t
2
exp t ( )


2
,
By rkfixed you get:
t : 0 , 0.05 .. 0.5
X : rkfixed(x0, 0 , 0.5, 10, D)

0 0.75 1
_
( 0.75 1 )
1

0.05 0.80195 1.07954

( 0.80195 1.07954)
1
1

0.1 0.85812 1.16882

( 0.85812 1.16882)
1

0.15 0.91901 1.26894

( 0.91901 1.26894)
1
1

0.2 0.98521 1.38112

( 0.98521 1.38112)
1
X

0.25 1.05735 1.50671

F t ( )
T

( 1.05735 1.50671)
1

0.3 1.13613 1.64719

( 1.13613 1.64719)
1
1

0.35 1.22234 1.80422

( 1.22234 1.80422)
1
0.4 1.31686 1.97963 ( 1.31686 1.97963) 1

0.45 1.42064 2.17545

( 1.42065 2.17545)
1
1

0.5 1.53478 2.39392
,
( 1.53478 2.39392)
]
So they agree up to five decimals.
163
h x
g x
y 0 y x
ODESolve
From version 2000, Mathcad has an differential equation solver ODEsolve that
can take care of intial value and boundary value problems involving one
unknown function, whose highest order derivative term must be linear.
ODEsolve does the steps described above and then uses rkfixed. Using the
right hand mouse button, you can choose an adaptive method instead. To get a
function defined for all values of the parameter, it uses spline interpolation .
You start with the code word Given. Then write the differential equation and
the initial condition. The prime in y' is written by means of the accent (accent
grave). For the example above it looks like this:
Given
y'' x x ( ) = x
(Use Ctrl + to get the = symbol.)
( ) 3y'( ) + 2 y x
y 0 ( ) = 1 ( ) = 0.75 y' 0
f : ODESolve(x , 0.5, 10)
(ODESolve returns a function.)
x : 0 , 0.05.. 0.5
Write f(x)= and you get exactly the same values as above.
Example of a boundary value problem:
Given 4y'' x ( ) = 0 ( ) + ( ) = 1 ( ) = 0 y
g : Odesolve(x , , 10)
It can be shown that the exact solution of the boundary value problem is
( ) : 1 cos

_
sin

_
h x

2
,
2
,
The values at /2 are
g

_
0.414212827001793 h

_
0.414213562373095

2
,
2
,

Here are the graphs:


x : 0 , ..
which apparently coincide:
64
0
( )
0.2
( )
0.4
0 1 2 3
x
164
4.6.6 Phase diagram for a damped pendulum.
As an example of this we shall draw the phase diagram for a damped
pendulum.
The differential equation of a damped pendulum can be written in the form
y''+Ay'+Bsin(y)=0. If you substitute x0=t, x1=y', then for a suitable choice of
the constants A and B the equation can be written in the form x'(t) = D(t,x),
where:

x
1 _
( D t , x) :

( )
,

0.4x
1
sin x
0
M1 : IC2(20, 20, 10, 10, 10, 10, 20, 50, D, rkfixed)
M2 : IC2(20, 20, 10, 10, 10, 10, 20, 50, D, rkfixed)
10
M1
2
0
M2
2
10
20 10 0 10 20
M1
1
, M2
1
4.6.7 Other differential equation solvers.
Mathcad has a number of other differential equation solvers built-in. They are
useful in some situations where rkfixed fails to give good result. One of them
is Rkadapt, which works similar to rkfixed, the difference being that the step
lengths are chosen adaptively instead of being constant. However, the steps in
the returned value are of constant length, even if the steps underlying the
computation are not.
Example 1.
( )
( )
_


4
_
9 x
0
+ 24 x
1
+ 5 cos t
sin
3
t

3

( D t , x) :

y0 :

( ) +
( )

2

24 x
0
51 x
1
9 cos t
sin t

3
,
3
,
165
It can be shown that the exact solution of this system is:

2 exp(3t) exp(39t) +
1
cos t

3
( )
_

F t ( ) :

cos t

exp(3t) + 2 exp(39t)
( )


3
,
Here is a comparison between the values returned by rkfixed, rkadapt and the
exact solution:
M1 : rkfixed(y0, 0 , 1 , 5 , D) M2 : Rkadapt(y0, 0 , 1 , 5 , D)
0 0
: M1
2 3
M

: M1
1 1
: M1
2
M

: M2

4 2
M

: M2

0 .. 5 M
i 5
: F(0.2i)
0
M
i 6
: F(0.2i)
1 , ,
t
rkfixed ------------------ Rkadapt ----- Exact ---------

0 1.333 0.667 1.333 0.667 1.333 0.667
_


0.2 97.354 196.683 1.424 0.875 1.424 0.875


0.4 9.754 10
3
1.951 10
4
0.909 0.608 0.909 0.608

M

0.6 9.634 10
5
1.927 10
6
0.606 0.44 0.606 0.44


0.8 9.514 10
7
1.903 10
8
0.414 0.323 0.414 0.323



1 9.396 10
9
1.879 10
10
0.28 0.23 0.28 0.23
,
As you can see, Rkadapt agrees very well with the exact solution, while
rkfixed does not. Mathcad also has other ODE solvers Stiffb and Stiffr, but I
shall not go into details about them.
First and second order methods
You may want to use first or second order methods, e.g. if you are teaching
numerical mathematics. Here are the classical first and second order methods.
The meaning of the parameters are the same as for rkfixed. Here is Euler's first
order method:
Euler(x0, a, b , N, F) :

h
b a
_

(
t
0
a
)

N
,

x0
0
x
for n 1 .. N

x

+ h F(t
n 1
, x

)
n n 1
x

n 1
t
n
t
n 1
+ h

augment
(
t , x
T
)
166
1
deHeuns second order Method:
deHeun(x0, a , b , N, F) :

h
b a
_

(
t
0
a
)

N
,

x0
0
x
for n 1 .. N
n 1
F1 F(t
n 1
, x

)

n 1

F2 F(t
n 1
+ h , x

+ h F1)

n n 1
x

x

+
h
(F1 + F2)
2

t
n
t
n 1
+ h
augment
(
t , x
T
)
The second order midpoint method:
Midpoint(x0, a , b , N, F) :

h
b a
_

(
t
0
a
)

N
,

x0
0
x
for n 1 .. N
n 1
F1 F(t
n 1
, x

)

n 1
F2 F

t
n 1
+
h
, x

+
h
F1


2 2
,

x

+ h F2 x
n n 1

t
n
t
n 1
+ h

augment
(
t , x
T
)
167
g x
Example F t , x) : identity 1 ( ( )
(
t + x
0
)
xx0
0
: 0
(This is how you can express a scalar problem as a vector problem.)
X1 : Euler(xx0 , 0 , 1 , 5 , F)
Exact solution:
( ) X2 : deHeun(xx0 , 0 , 1 , 5 , F) ( ) : x 1 + exp x
X3 : Midpoint(xx0 , 0 , 1 , 5 , F) i : 0 .. 5 t
i
: 0.2i x : 0 , 0.05 .. 1
Values:
M : 0
(annihilates any previous value of M)
M

: X1

M

: X1
0 0 1 1
M

: X2

M

: X3
2 1 3 1
M
i 4
: g(i0.2)
,
t Euler deHeun Midpoint exact

0 0 0 0 0
_

0.2 0 0.02 0.02 0.0214027582



0.4 0.04 0.0884 0.0884 0.0918246976

M
0.6 0.128 0.215848 0.215848 0.2221188004


0.8 0.2736 0.41533456 0.41533456 0.4255409285


1 0.48832 0.7027081632 0.7027081632 0.7182818285
,
0.2
0.4
0.6
M
1

M
2

M
3

g x ( )
0 0.2 0.4 0.6 0.8 1
t t , t , x ,
168
4.6.8 A boundary value problem: Ballistics
Instead of giving initial conditions you can give boundary conditions. For
instance, you can specify that an integral curve should go through two given
points. We illustrate the shooting method on an example - the motion of a
body under the influence of the gravitation and air resistance. First, let's
assume that the motion takes place in the x-y-plane with the gravitation force
acting in the direction of the negative y axis. Then, if there is no air resistance,
the equations of motion of the body are: x''(t)=0, y''(t)=-g. Substituting x
0
=x,
x
1
=x', x
2
=y, x
3
=y'(t), the equations can be written x'(t) = D(t,x), where
g : 9.81
x
1 _
x
1 _

0
_

D t , x) :

0

D t , x) :

0

+

0

(
x
3

(
x
3
0

g
,
0
,

g
,
The second form is the sum of two vectors, the first of which comes from the
substitutions, while the second comes from the the gravitational force. This
system can be solved by integrating the equations x''(t)=0, y''(t)=-g twice. If the
initial condition is that x(0)=0, x'(0)=v0cos(), y(0)=0, y'(0)=v0sin(), the
solution can be written:
( ( )
t y v0, , t)
: v0sin
1
x v0, , t)
: v0cos
( ( )
t
2
gt
2
You can get y as a function of x by eliminating t between these two equations.
The result is:
( ( )
2
)
x
2
+ tan y v0, , x)
:
1

g

(
1 + tan
( )
x
2
v0
2
For a typical example, it looks like this:
: 30deg v0 : 200 x : 0 , 10.. 4000
500
y v0 , , x) (
0 1000 2000 3000 4000
x
169
You can compare this to the result obtained with the Runge-Kutta method:

0
_ 1
1
( )

M : rkfixed


v0cos

, 0 , 22, 20, D
1
1
0

( )
,
1
]
v0sin
The graphs seem to coincide:
i : 0 .. 20
500
,
M
i 3
y(v0 , , x)
0 1000 2000 3000 4000
M
i 1
, x
,
Now let's proceed to the air resistance. This force is very difficult to describe,
since it depends on the weather conditions among others. Its dependence on
the speed is also complicated. You need to make a simplification, which is
acceptable under certain conditions: you assume that the air resistance is
proportional to the square of the speed of the body. In the model above, if
x=(x
0
,x
1
,x
2
,x
3
)
T
is the vector that describes the motion, the velocity is
(0,x
1
,0,x
3
), and the speed is the length of this vector. A vector in the opposite
direction of the velocity with magnitude proportional to the square of the
speed must then be of the form:

0
_
0
_


x
1
x
3
k
x
1
( )
2
x
3
( )
2
+

( )
2
+
( )
2
]
1


x
1

k x
1
( )
2
x
3
( )
2
+

x
1

0 0


x
3
,
x
3
,
Hence the equation of motion can be written x'(t)=D(t,x), where
k : 0.00183
(This value is nearly correct for a standard army rifle projectile.)
170
D t , x) ( :






x
1
0
x
3
0
_




,
+






0
0
0
g
_




,


0
_


x
1

0


x
3
,
x
1
x
3
k
( )
2
+
( )
2
The initial condition can be expressed as a vector
v0 : 1000
x( )
:






0
( ) v0cos
0
( ) v0sin
_




,
From an artillerist's point of view, the initial speed v0 can be assumed to be a
constant, while the elevation angle is that parameter that can be controlled.
You can find the solution by means of Runge-Kutta's method for several
values of :
( )
: rkfixed(x( )
, 0 , tH, 20, D) tH : 4 R
20
0 200 400 600 800 1000

3
R(2deg)

1
R(2deg)
i : 0 .. 10
i
: (1.5 + i0.1)deg M : 0
( )
Y

:
( )

X

:
( )

M
i
: R
i
i
M
i
3 i
M
i
1
20
Y
0 200 400 600 800 1000
X
171
Now, the question is: Given a target with coordinates (Dh,Dv), what value of
do I have to use in order to hit the target? This value of can be found in
the following way:
First you choose a value of which gives almost a hit based on a table or a
diagram. For instance, if
Dh : 900 Dv : 10
then it follows from the diagram above that is not far from 2 degrees. So you
use 1=2 degrees and compute the trajectory:
( )
1 : 2deg Z1 : R 1
Then you can find an approximate value of the projectile's altitude at the
distance Dh by means of linear interpolation:
1
h1 : linterp
(
Z1

, Z1
3
, Dh
)
h1 14.739
This means that 1 = 2 deg is too big. So, you try with a smaller value:
( ) This time, you find:
2 : 1.6deg Z2 : R 2
1
h2 : linterp
(
Z2

, Z2
3
, Dh
)
h2 8.462
To find an approximation to the elevation
hit
that gives a hit, you use linear
interpolation:

h1 1
_ 1
H : csort

, 0
1

h2 2
, ]
(This is to make sure that the first column of H is in ascending order, which is
required by the function linterp.)
0

hit
: linterp
(
H

, H
1
, Dv
)

hit
1.698deg
Alternatively, you can define
hit
as a function:
: 2deg
(This may have to be changed.)

hit
(Dh, Dv) : root
(
linterp
(
R
1
( )

, Dh
)
Dv,
) ( )

, R
3
You find:

hit
(900 , 10) 1.698deg
hit
(800 , 20) 2.209deg

hit
(900 , 20) 2.335deg
hit
(1200, 0) 2.598deg

hit
(1200, 500) 25.646 deg
hit
(2000, 0) 5.579deg
172
5 Linear Algebra
In section 1.6 we exposed most of the elementary operations on arrays. In this
section we shall have a closer look at some standard topics from linear algebra.
5.1 Elementary row operations and Gauss
elimination
5.1.1 Elementary row operations
The elementary row operations can be programmed as follows:
Multiplying row m in M by t:
To exchange rows no. m and n in M:
( ) RX(M , m, n) : C cols M
( ) RM(M , m, t) : C cols M
c 0
R rows M ( )
while c C <
r 0
while r R <
A
r c
M
r c , ,
r r + 1
A
m c
t A
m c , ,
c c + 1
A
R rows M ( )
c 0
while c C <
r 0
while r R <
A
r c
M
r c , ,
r r + 1
v A
m c ,
A
m c
A
n c , ,
A
n c
v
,
c c + 1
A
Notice that I've used while loops instead of the more natural for loops to make
the function work symbolically.
Example:

1 2 3
_
1 2 3
_
1 2 3
_
M :

2 4 3

RM(M , 1 , 2)

4 8 6

RM(M , 2 , 2)

2 4 3



6 4 5
,
6 4 5
,
12 8 10
,
173
To add t times row m to row n:
RA(M , m, n , t) : C cols M ( )
Example:
R rows M ( )
c 0

1 2 3
_
while c C
M

2 4 3

<

r 0
6 4 5
,
while r R <
M1 : RA(M , 0 , 2 , 3)
A
r c
M
r c , ,
r r + 1

1 2 3
_
M1

2 4 3

A
n c
A
n c
+ t A
m c

, , ,

3 2 4
,
c c + 1
A
To add suitable multiples taken from column n of row m to all the other
rows:
( ) RsA(M , m, n) : R rows M
C cols M ( )
c 0
while c C <
r 0
while r R <
A
r c
M
r c
if r = m
, ,
M
r n ,
A
r c
M
r c
M
m c
otherwise
, , ,
M
m n ,
r r + 1
c c + 1
A
Example

1 2 3
_
1 2 3
_
M

2 4 3

RsA(M , 0 , 1)

0 0 3



6 4 5
,
4 0 1
,
174
5.1.2 Naive Gauss elimination
Let's demonstrate how to use the elementary row operations to solve a system of
linear equations having the following augmented coefficient matrix:

1 4 2 4
_
A :

2 7 1 2

The function RsA will work effectively to


2 9 7 1

,
achieve the diagonalization:
A1 : RsA(A, 0 , 0) A2 : RsA(A1, 1 , 1) A3 : RM(A2, 1 , 1)

1 4 2 4
_
1 0 10 36
_
1 0 10 36
_
A1

0 1 3 10

A2

0 1 3 10

A3

0 1 3 10



0 1 3 7
,
0 0 0 17
,
0 0 0 17
,
The conclusion is that the system is inconsistent.
5.1.3 Gauss elimination with pivoting
Suppose you have a matrix A which is the augmented coefficient matrix for a
system of linear equations. The process of Gauss elimination with pivoting goes
like this:
First, define a function which normalizes the ith row of A. that means to divide
by the coefficient of greatest absolute value.
Normalize(A, i) : (B A)(C cols B ( ))
(
Max B
i 0
)

(
MM B
i 0
)
, ,
for j 1 .. C 1
M B
i , j
if M > Max
Max M
MM B
i , j
for k 0 .. C 1 if Max > 0
B
i k ,
B
i k

,
MM
B
175
Example.

1 4 2 4
_
1 4 2 4
_
A

2 7 1 2

Normalize(A, 1)

0.286 1 0.143 0.286



2 9 7 1
,
2 9 7 1
,
In the next function COrder, the rows of A are if necessary rearranged so that
row m on, the uppermost row is the one with the greatest element in absolute
value in column k:
COrder(A, k , m) : B A
( ) 1 for i m + 1 .. rows B
B RX(B , i , m) if B
i k
> B
m k , ,
B
Example

1 4 2 4
_
2 9 7 1
_
A

2 7 1 2

COrder(A, 2 , 0)

2 7 1 2



2 9 7 1
,
1 4 2 4
,
Here is the function Rref that does Gauss elimination with pivoting:
Rref M ( ) : B M
R rows B ( )
for m 0 .. R 2
for i m.. R 1
B Normalize(B , i)
B COrder(B , m, m)
B RM


B , m,
(
B
m m
)
1
1
]
if B
m m
0
, ,
for i 0 .. R 1
B RA
(
B , m, i , B
i m
)
if i m
,
if B
R 1 , R 1
0

B RM


B , R 1 ,
(
B
R 1 , R 1
)
1
1
]

for i 0 .. R 2
B RA
(
B , R 1 , i , B
i R1
)
,
B
176
B1 B
t
Example.

3 13 9 3 19
_
1 0 0 0 3
_

6 4 1 18 34

( )

0 1 0 0 1

A : Rref A
6 2 2 4 16 0 0 1 0 2


12 8 6 10 26
,
0 0 0 1 1
,
The rref function
Mathcad has a built-in function rref that performs Gauss elimination with
pivoting. The output is a matrix on row reduced form, It works only numerically
(at the moment):

1 0 0 0 3
_


0 1 0 0 1

rref A ( )
0 0 1 0 2


0 0 0 1 1
,
5.2 Rank and subspaces
5.2.1 The rank of a matrix
The function that gives the rank of a matrix is of course rank:
rank A ( ) 4
The rank function also only works numerically. So, if you are asked to find the
rank of a matrix with an undetermined parameter like:

1 2 0 0 3

_
then the functions rref and rank won't work, but


2 5 3 2 6

you can use naive Gauss elimination with
B :
0 5 15 10 0
symbolic evaluation:


2 6 30 20 t
,
B1 : RsA(B , 0 , 0) B2 : RsA(B1, 1 , 1)

1 2 0 0 3
_
1 0 6 4 3
_


0 1 3 2 0

B2

0 1 3 2 0

B1
0 5 15 10 0 0 0 0 0 0


0 10 30 20 t 6
,
0 0 0 0 t 6
,
From this it is easily seen that the rank of B is 3, except for t=6, when it is 2.
177
5.2.2 The space spanned by the column/row vectors of
a matrix
In this subsection all the functions will only work numerically. Here is a
function that, given a matrix M, returns a submatrix B of M such that the
columns of B are linearly independent and span the same subspace as the
columns of M:
( ) ColumnBasis(M) : C cols M
R rows M ( )
B

M
0 0
for n 1 .. C 1
n
D augment
(
B , M

)
B D if rank(D) > rank B ( )
B

1 2 3
_
1 2 3
_

( )


2 4 3

M

2 4 3

ColumnBasis M

6 4 5
,
6 4 5
,
You get a similar function for the row vectors by transposition:
)
T
RowBasis(M) : ColumnBasis
(
M
T

1 2 3
_
1 2 3
_

( )


2 4 3

M

2 4 3

RowBasis M

6 4 5
,
6 4 5
,
5.2.3 Basis for the null space of a matrix
First, here are some auxiliary functions:
m
NullV(n) : identity n

A
T

T
( )
0
0
RowV(A, m) :
( )
Examples

0
_
1 2 3
_
NullV 3 ( )

0

M

2 4 3

RowV(M , 1) ( 2 4 3 )


0
,
6 4 5
,
178
The next function NullSpace gives a basis for the null space of a matrix A.
NullSpace(A) : (B RowBasis A ( ))(C cols B ( ))(R rows B ( ))
(I 0)(i 0)( j 0)(Null NullV R ( ))
return 0 if R = C
0
if B

= Null
1
i
while B

= Null
for c 0 .. C 1
M
i c
0
,
(
M
i i
1
)

(
IE
j
i
)
,
i i + 1
j j + 1
(I i)(k 0)
R0 RowV(B , k)
M if(I = 0 , R0, stack(M , R0))
for c I.. C 2
r1 rank(submatrix(B , 0 , R 1 , I, c))
r2 rank(submatrix(B , 0 , R 1 , I, c + 1))
if r1 < r2
k k + 1
M stack(M , RowV(B , k))
otherwise
( )

T
)
+
M stack
(
M , identity C
c 1
IE
j
c + 1
j j + 1
T M
1
( ) for j 0 .. last IE
j
( )

(
IE
j
)

X

Tidentity C
X
179
Example To solve a system of homogeneous equations, you can use a symbolic
solve block:
Given x 2y = 0 2x 5y 3z 2u = 0
5y + 15z + 10u = 0 2x + 6y + 30z + 20u = 0

6z 4 u
_

3z 2 u


Find(x , y , z, u)
z

or the solve keyword on a vector of

u
,
equations:

x 2y = 0
_



2x 5y 3z 2u = 0

solve , x , y , z , u ( 6z 4 u 3z 2 u z
5y + 15z + 10u = 0


2x + 6y + 30z + 20u = 0
,
In any case, the solution vector can be written in the form:

6
_
4
_
6
_
4
_

z

+ u

2

Thus, a basis for the

3

and

2

1 0
null space consists of
1 0


0
,
1
,
0
,
1
,
Using the function NullSpace on the system's coefficient matrix, you get this
result directly:

1 2 0 0
_
6 4
_

A :

2 5 3 2

NullSpace A

3 2

0 5 15 10
( )
1 0


2 6 30 20
,
0 1
,
Exercises. Find the null space for the following matrices:

1 2 1 1
_

1 2 0 1 2
_


3 1 1
_
A1 :

0 1 1 1 0

A2 :

2 3 4 3

A3 :

6 2 2

3 5 5 4

2 3 1 3 4
,

9 3 3
,

1 1 3 2
,
180
5.2.4 Gram-Schmidt's orthonormalization process
Suppose you have a basis for a subspace of Rn given as the column vectors of
some matrix M. The Gram-Schmidt orthogonalization process returns an
orthogonal base given in a matrix E such that the first m column vectors of E
span the same subspace as the first m vectors of M.
The length of a vector symbolically:
len V ( ) :
( )
V V
GramSchmidt(M) : C cols M
M
0
E
0
len
(
M

)
n 1
while n C <
n
a M

i 0
while i n <
n i i
a a
(
M

E

)
E

i i + 1
a
E augment

E,

_

len a ( )
,
n n + 1
E
This will return a matrix similar to the argument M.
Example 1.

1 1 1
_
M :

1 2 2

E : GramSchmidt M

( )

1 1 3
,

1
3
1
6
1
2

_

3 6 2


0.577 0.408 0.707
_
E

1
3
1
6 0


0.577 0.816 0

3 3

1
3
1
6
1
2


0.577 0.408 0.707
,


3 6 2
,
181
Control:
i j
Y
i , j
: E

E

i : 0 .. 2 j : 0 .. 2 X
i , j
: E

E
i j

1 0 0
_
1 0 0
_
X

0 1 0

Y

0 1 0



0 0 1
,
0 0 1
,
5.2.5 Completion to a full base
Suppose you are given a linearly independent set of n-vectors as the column
vectors of some matrix M, and you are asked to find an nn matrix whose
column vectors span all of Rn and whose first column vectors are the given
vectors.
Then you can find suitable vectors that are orthogonal to the given vectors.
This is equivalent to finding the nullspace of M, and you can use the function
NullSpace from section 5.2.2 (p. 169) to find this:
Definitions from 5.1
Complete(M) : N NullSpace
(
M
T
)
augment(M , N)
Example

1 1
_
1 1 1 0.333
_


1 2

( )

1 2 0 0.333

A :
1 1
Complete A
1 1 1 0


0 1
,
0 1 0 1
,
5.3 Eigenvalues and quadratic forms
5.3.1 Eigenvalues and eigenvectors.
Mathcad has the functions eigenvals and eiegenvecs to find eigenvectors and
eigenvalues. They work both numerically and symbolically, but these two
don't gove exactly the same result:

5 4 2
_
A :

4 5 2

E : eigenvals A ( )

( ) ES : eigenvals A
( ) EVS : eigenvecs A
2 2 8
, EV : eigenvecs A ( )
182
Q x

9
_
0
_
0.278 0.691 0.667
_
E

9

ES

9

EV

0.192 0.72 0.667



0
,
9
,
0.941 0.058 0.333
,

1
5
2
_

0
5

3



0 0.447 0.667
_
EVS

1
5 0
2


0.447 0 0.667

5 3

2
5
2
5
1


0.894 0.894 0.333
,




5 5 3
,
The symbolic version is dangerous to use for diagonalizations, since the
column vectors are not orthogonal. But the you can use the Gram-Shmidt
orthogonalization process to get an orthogonal matrix:

1
5
2
_

0
3

3


E2 : GramSchmidt(EVS)

1
5
4
5
2

5 15 3

2
5
2
5
1




5 15 3
,
You can check it out:

i
i : 0 .. 2 D
i
: A EV
i
E
i
EV

D
T
( 0 0 0 )

i
DS
i
: A E2
i
ES
i
E2

DS
T
( 9 0 9 )
Furthermore:

9 0 0
_
9 0 0
_
E2
1
AE2

0 9 0

EV
1
AEV

0 9 0



0 0 0
,
0 0 0
,
This means that the quadratic form:
Q x , y , z) : 5x
2
+ 5 y
2
+ 8 z
2
+ 8xy + 4yz 4xzor (
x
0

( )
2
+ 8 x
2
( ) : 5
( )
2
+ 5 x
1
( )
2
+ 8 x
0
x
1
+ 4 x
1
x
2
4 x
0
x
2
can be transformed into the quadratic form
( ) : 9
( )
2
+ 9 X
2
QQ(X, Y, Z) : 9Y
2
+ 9Z
2
or
QQ X X
1
( )
2
183
Q x
by the transformation
x = E2X

x
_1

Q E2

y
1
simplify 9y
2
+ 9 x
2
Note that you don't get the correct
1
result if you use EVS directly:

z
,]

x
_1
You have to use
Q

EVS

y
1
simplify
72
xy + 9 y
2
+ 9 x
2
Gram-Schmidt

1 5
orthogonalization first.

z
,]
A two dimensional example
Classify the curve given as
6x
2
+ 4xy + 9y
2
= 1

6 2
_
Solution: The quadratic form has the matrix
A :


2 9
,
Compute

2
5
1
5
_

5
_

5 5

( )

EV : eigenvecs A E : eigenvals A ( )


10
,

1
5
2
5


5 5
,
Note that Mathcad apparently has a bug here: The first eigenvalue
corresponds to the second eigenvector and vice versa:
A EV

2
5
5
_

10EV


2 5
4 5

_

0 0
,

,
A EV

2 5
4 5

_
5 EV


5
2 5

_

1

1

,
In the cases where no eigenvalues are multiple, the matrix of eigenvectors is
orthogonal, so you can use it directly:
That means that the quadratic form:
( ) : 6
( )
2
+ 4 x
0
x
1
+ 9 x
1
x
0
( )
2
is transformed into
QQ X X
0

( )
2
( ) : 10
( )
2
+ 5 X
1
by the coordinate transformation
x = EVX

x
_1
Q EV
1
]
simplify 5x
2
+ 10y
2


y
,
184
In the two dimensional case you can illustrate this by drawing a contour plot of
the quadratic. We use the function CreateMesh:
( f x , y) : 6x
2
+ 4xy + 9y
2
MM : CreateMesh(f , 1 , 1 , 1 , 1 , 40, 40)
For comparison, you could find the points of minimal distance from the origin:
2 2
( x : 0 y : 0 g x , y) : x + y
Given 6x
2
+ 4xy + 9y
2
= 1


x1

_
: Maximize(g , x , y)


x1


0.4
_


y1
,
y1
,
0.2
,
Given 6x
2
+ 4xy + 9y
2
= 1


x2
_

: Minimize(g , x , y)


x2
_


0.141
_


y2
,
y2
,
0.283
,
These are eigenvectors of A:

x1
_
0.4
_
x2
_
0.141
_
A


5 A


10

y1
,
0.2
,
y2
,
0.283
,
This indicates that the axes of the ellipse are eigenvectors of A.
185
Index
A
accessing the elements of an array 26
Add Line 41
addition of an array and a scalar 29
Airys equation 143
algebra 67
angle between vectors 122
animation 65
area between graphs 110
area bounded by parameter curve 111
area bounded by polar curve 111
arrays 25ff
ASCII files 30
assignment in a program 41
asteroid 93
augment 31
axis format 34
B
ballistics 169
Bernoullis equation 137
binary 49
binomial coefficient 46
binormal vector 125
boundary value problem 164, 169
break 42
built-in functions 19
calculator toolbar 12
calculus 83 ff.
cardioid 37, 92
ceil 46
centroid 114
change of coordinates in double
integral 121
characteristic polynomial 138
closing a file 16
collect 72
column vector of a matrix 26
combin 46
combinatorics 46
completion to a full base 182
concat 62
continue 43
contour plots 53, 98
creating an array or vector 25
curl 127
curvature 89, 90, 125
curve length 112 ff.
cycloid 90
D
damped pendulum 165
decimal 49
defining a function 32
defining a variable 20
defining array by a formula 27
defining big arrays 30
definite integrals 106
deHeuns method 167
derivative as a limit 83
derivative of vector function
123
determinant 29
difference equations 146
differential equations 135 ff.
differential equations of order
one 135
differential equations of order
two or higher 138, 141
differential geometry 126
differentiation 83 ff.
differentiation of implicit
functions 86
dimension 23
discrete Fourier transform 153
divergence 127
double integral 121
E
eigenvalues 182 ff.
eigenvectors 182 ff.
187
C
elementary operations 11
elementary row operations 173 ff.
elements of an array 26
ellipsoid 59
envelope 93
equation format 21
equations 77
Eratosthenes sieve 48
error function 44
Eulers method 166
evaluation style 68
Evaluation toolbar 18
evolute 89
expand 67, 70
expand nested arrays 30
extra math symbols 61
extrema 94, 97, 99
extrema with side conditions 101
F
factor 71
families of integral curves 158, 162
FFT 153
Fibonacci numbers 48
first index of an array 28
float 76
floor 46
for 41
Fourier coefficient 149
Fourier series 149 ff.
Fourier transform 151
functional arguments 38
G
Gauss elimination 175
global assignment 20
gradient 127
Gram-Schmidt 181 ff.
graph of a function of two variables 52
graphs 33
greatest common divisor 46
Greens theorem 129
H
helix 57
Hessian 99
hexadecimal 49
hitting a target 172 ff.
I
if 43
improper integrals 108
indefinite integral 104, 135
index operator 26
inflection point 95
inhomogeneous ODEs with
constant coefficients 139
integral curves 158
integration 104
J
Jacobian 133
L
Lagrange multipliers 101
Laplace transforms 144
Laplacian 127
least common multiple 46
limits 83
line integrals 126 ff.
linear algebra 173 ff.
linear equations 80, 136
linear optimisation 103
local maximum 94
local minimum 94
loops 41
M
Math toolbar 12
matrix addition 28
matrix inversion 29
matrix multiplication 28
matrix transpose 29
Maximize 95
Mersenne numbers 47
188
method of undetermined coefficients
139
midpoint method 167
Minimize 95
moments of inertia 114 ff.
multiplication of array by scalar 29
N
naiv Gauss elimination 175
nested array 30, 55
newton 24
normal 87, 88
normal to a surface 130
null space 178
num2str 62
number bases 49
number of rows and columns of a
matrix 28
numerical solution of differential
equations 155
O
octal 49
opening an existing file 16
ORIGIN 28
otherwise 43
P
parameter curve 36
parameter surfaces 54
parfrac 73
partial derivative 84, 96
partial fractions 73
pendulum 165
periodic extension 148
permut 46
phase diagram for damped pendulum
165
Pi 33
pivoting 175
placeholder 14
plane areas 109 ff.
polar curve 36
polynomial coefficients 76
polynomial equations 79
power series solution of ODEs
142
prime number factorisation 47
prime number function 48
prime numbers 47
principal normal vector 125
printing a file 16
printing to a file 16
product symbol 51
programming 40
Pythagorean triples 49
Q
quadratic forms 182
quick sheet 61
R
radius of curvature 126
radius of torsion 126
range product 51
range sum 50
range variable 22
rank 177
READPRN 31
resource center 61
result format 18
return 44
Rkadapt 166
rkfixed 159
root 77
round 47
row reduced form 177
rref 177
Runge-Kutta 159
S
saving a file 15
scalar field 127
scalar product of vectors 28
search 62
189
second order ODEs solved numerically
163
separable equations 135
series 96
several 3D objects 58
several equations solved numerically
79, symbolically 81
shooting method 169
simplify 69
solving an equation numerically 77,
symbolically 78
space curves 57
special characters in text 60-61
speed 125
sphere 54
stack 31
starting a new file 15
starting Mathcad 11
step functions 150
str2num 62
str2vec 62
strlen 62
submatrix 29
subscript 60
substitute 74
substr 62
summation symbol 50
superscript 60
surface area of a surface of revolution
119 ff.
surface integrals 130 ff.
surface of revolution 116
surface plot 52
symbolic computation 17
symbolic differentiation 84
symbolic evaluation 68
symbolic float keyword 18
symbolic mathematics 67
symbolic processor 17
T
tangent 87, 88, 125
Taylor series 96
text 60
text blocks 60
text on a 2D graph 63
text variables 62
three dimensional plots 52
torsion 125
torus 54
total differentials 137
transpose 29
trapezoid rule 40
trunc 47
U
units 23
user-defined functions 32
V
value of an expression 39
variable 20ff
variable names 21
vec2str 62
vectors 25, 122
vector calculus 122 ff.
vector field, 127, 155
vector field plot 155 ff.
vector length 29
vector sum 50
vector valued functions 123
vectorize 32
volume of a surface of
revolution 117
W
while 42
X
XY-plots 34
Z
z transform 147
190

Anda mungkin juga menyukai