Preface


This tutorial was made solely for the purpose of education and it was designed for students taking Applied Math 0330. It is primarily for students who have very little experience or have never used Mathematica and programming before and would like to learn more of the basics for this computer algebra system. As a friendly reminder, don't forget to clear variables in use and/or the kernel. The Mathematica commands in this tutorial are all written in bold black font, while Mathematica output is in normal font.

Finally, you can copy and paste all commands into your Mathematica notebook, change the parameters, and run them because the tutorial is under the terms of the GNU General Public License (GPL). You, as the user, are free to use the scripts for your needs to learn the Mathematica program, and have the right to distribute this tutorial and refer to this tutorial as long as this tutorial is accredited appropriately. The tutorial accompanies the textbook Applied Differential Equations. The Primary Course by Vladimir Dobrushkin, CRC Press, 2015; http://www.crcpress.com/product/isbn/9781439851043

Return to computing page for the first course APMA0330
Return to computing page for the second course APMA0340
Return to Mathematica tutorial for the first course APMA0330
Return to Mathematica tutorial for the second course APMA0340
Return to the main page for the course APMA0330
Return to the main page for the course APMA0340

Solving Equations


Mathematica is not only powerful program for symbolic mathematics, it is also capable of handling sophisticated numerical calculations. In fact, almost all the symbolic operations have a numerical counterpart. Mathematica uses a special letter N for numerical evaluations. One of the most common problems encountered in numerical mathematics is solving equations. They are defined in Mathematica by a double equal sign. The basic command in Mathematica for solving equations is Solve. However, for numerical evaluations, we need other procedures.

Suppose that we need to solve the algebraic equation

\[ f(x) =0 \qquad \mbox{or} \qquad x= g(x) \]

for some smooth functions f(x) and g(x). Mathematica has two basic commands, FixedPoint and NSolve, to solve these equations numerically. More details can be found in the first three sections of Part III. Recall that FixedPoint[f,expr] starts with expr, then applies f repeatedly until the result no longer changes. NSolve works when restricted to reals:

NSolve[x==Cos[x],x,Reals]
Out[2]= {{x -> 0.739085}}
A few other methods to find the root of the equation x = cos x are presented for illustration:
N @ FindInstance[x == Cos[x], x]
N @ Reduce[{x == Cos[x], -1 < x < 1}, x]
FindRoot[x == Cos[x], {x, 0}]
FixedPoint[Cos[#] &, 0.5]        (* 0.5 is the initial guess *)

Example: Suppose we want to find a square root of 4.5. First, we apply FixedPoint command:

FixedPoint[(# + 4.5/#)/2 &, 2.]
Out[3]= 2.12132

or 2.121320343559643 . Another option is

NSolve[x^2 == 4.5, x]
Out[3]= {{x -> -2.12132}, {x -> 2.12132}}

which is actually the same value as Newton's method provides: 2.121320343559643

 

Return to Mathematica page
Return to the main page (APMA0330)
Return to the Part 1 (Plotting)
Return to the Part 2 (First Order ODEs)
Return to the Part 3 (Numerical Methods)
Return to the Part 4 (Second and Higher Order ODEs)
Return to the Part 5 (Series and Recurrences)
Return to the Part 6 (Laplace Transform)
Return to the Part 7 (Boundary Value Problems)