MATHCAD Tutorial
- Page ID
- 279150
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)
( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\id}{\mathrm{id}}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\kernel}{\mathrm{null}\,}\)
\( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\)
\( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\)
\( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)
\( \newcommand{\vectorA}[1]{\vec{#1}} % arrow\)
\( \newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow\)
\( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vectorC}[1]{\textbf{#1}} \)
\( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)
\( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)
\( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)PTC MATHCAD Prime 3.1
CHEM 231 SPRING 2017
Overview:
MATHCAD is a very powerful program that, when used properly, can aid in solving complex and/or cumbersome mathematical expressions. In this lab, we will demonstrate the utility of MATHCAD for familiar calculations using pH and solubility.
Getting Started:
MATHCAD is available on the campus network machines.
To open MATHCAD from a networked PC, click on the start button (lower left) and click on “All Programs” and select “PTC Mathcad Prime 3.1” under “PTC Mathcad”
Once you have opened the program, a series of pull-down menus and perhaps a few icon toolbars have appeared, and a blank (white) document will be opened. Look around the software -- check out the options on the pull-down menus; for example “Math” and “Plots” options can bring up several useful functions which will be used in this laboratory exercise. The blank white space is your working space. Mathcad will assume that you are typing mathematical expressions unless you tell it otherwise. For example, you can type text by selecting text box in “Math” option. Then you can format the text using “Text Formatting” option.
You can use variables in any calculation as long as you have “defined” them using a colon (appears as :=, NOT just =) prior to using them in a calculation. The first time you type a variable, Mathcad will assume you are giving it a definition.
Quirky things about Mathcad:
- Never type spaces in your mathematical expressions. Reason: The space bar (as well as the arrow keys) are used as select/scroll mechanism in Mathcad.
- For definitions, use a colon (press shift-colon on keyboard or go to “Operators” under “Math” option to select the definition sign from “Definitions and Evaluations”), NOT an equal sign. Equals sign mean “hey program, calculate this for me” while colon means “hey program, I’m telling you the value(s) of this variable.” Mathcad does this automatically the first time.
- Variables must be defined prior to their use in a calculation. As long as the definition is above or to the left of the calculation, you will be OK.
- If a variable has to be defined with a range of numbers use two dots in between the two numbers (for example if the range is 1 to 7 type 1..7). You can also use 1..n function in “Vector and Matrix” under “Operators” in “Math” option to carry out the same operation. Then you can ask Mathcad what the values of the variable are by typing the variable followed by equal sign (press = on keyboard).
- You must type the * (or shift-8 on key board) for multiplication and the ^ (or shift-6) for exponents. (note "*" does not appear when you type shift-8, rather a dot appears).
- To select an entire object (text or equation) that you have already typed, click and hold as you drag across the object.
- To edit a specific part of an object (text or equation) click on the spot you would like to edit.
- To delete a specific part on Mathcad first select (by highlighting) the region you want to delete and press delete on keyboard or right click on mouse and select “delete”.
- Use the left/right arrows to “scroll through” an equation when editing it.
- When you use a series of numbers with the 1...n function, Mathcad will count by ones. If your step size is not 1 then you should use 1,3..n function (consider this function as x,y..z where x is the starting number, y is the second number which is equal to a step size of y-x and z is the ending number)
- When performing multi-term calculations (such as a calculations) that include fractions, make use of parentheses to move from one term to the other.
- Watch out for unwanted parentheses – if Mathcad puts them in, especially with exponents, it probably means Mathcad thinks you mean something else –Delete them!
Practice:
- Have Mathcad add 20 and 22, then divide the total by 7, all in one step. The answer should be 6.
- Now, define a=20, b=22, and add a+b and divide the total by 7.
- Now, define the answer of the calculation in 2 as f(a), then type a = and right next to this, type f(a)= and you should see 20 (the value of a) and 6 (the value of f(a)) displayed below your typing.
- Now, go back up to the definition of a, and define a to be a range of numbers between 1 and 40 (use two dots in between 1 and 40) or by using the Vector and Matrix pallet (look under “Operators” in “Math” option) and using the 1...n. When you have successfully done this, you will see that a long list of numbers has appeared below you a= and your f(a)= columns. Pretty slick, eh?
- Under “Plots” option go to “Insert Plot” and select “X-Y plot” to plot a graph of f(a) as a function of a. Then, click on the small boxes that appear on the x and y axes and type in a on the x-axis, f(a) on the y-axis. A plot of your data should appear. You may now change the values of a or b and immediately see how the plot changes. Play around with this a bit. (note: if you have more than one function for x and/or y axes then, after typing the function in x or y axis box click “Add Trace” in “Plots” pull down menu to bring a second box to type the other function.)
You now understand the basics of using MathCad.
Note:
MathCad is a good way to do your sample calculations for this course......
Open the file HAlab.MCD in the CHEM 231-Harris-MathCad folder on the chemistry public space. Give you any ideas?
Exercise: Calculate the pH of a weak acid solution:
- Define Ka, Kw, and F (the formality of your acid in solution)
- Calculate the pH using the “fast,” “quad,” and “no assumptions” equations.
\[\begin{align}
&\textrm{WA Fast equation:} &&[H^+]=\sqrt{K_AF_{HA}} \nonumber\\
&\textrm{WA Quadratic:} &&[H^+]^2+K_A[H^+]-K_AF_{HA}=0 \nonumber\\
&\textrm{No assumptions (Cubic):} &&[H^+]^3+K_A[H^+]^2-(K_AF_{HA}+K_W)[H^+]-K_WK_A=0 \nonumber
\end{align} \nonumber\]
We will use the “root” function to solve both the quadratic and the cubic equations, as follows:
- Define the “tolerance” by typing
TOL:= 10-22
(this lets MathCad know that anything smaller than 10-22 can be interpreted as zero).
- Define the function, by typing something like:
f(x,i):= x2 +Ka(i).x - Ka(i).F
(where x is [H+] and Ka(i) is several values for Ka).
- Define and solve the function, by typing something like
Hq(i):=root(f(x,i), x, 0,1)
(where f(x,i) is the function, x is the “answer” and 0 and 1 are the minimum and maximum values for the answer).
A note about minimum and maximum values: A quadratic has two solutions (or “roots”) that will solve the math, and a cubic equation has 3 roots. In most cases only one of the roots gives a rational number that has a positive value. The possible answers for [H+] are between 0 and 1.
We will superimpose the answers from all three calculations to find out where the assumptions are valid and where they are not valid. [Note: you may get irrational numbers or “does not converge” for some answers…try lowering the Ka and/or Formality of the acid, or changing the TOL if this happens to you.]
Question: What are the assumptions that result in going from the cubic to the quadratic form and from the quadratic to the “fast” form?
In all, for weak acid portion of this lab, you will make two different Mathcad files as follows:
- Vary Ka from 10-14 to 0.1 (hint: use i:=1 ... 14, then have Ka(i):=10-i).
Plot the three answers (fast, quad and noassump) as a function of pKa.
- Vary Formality from 0.1 F to 10-14 F, holding Ka constant at some value.
Plot the three answers (fast, quad and noassump) as a function of log(F).
Question: Where do the assumptions break down? You may need to change the constant parameter in each case, and see the result to answer this question.
Take a look:
On the Chemistry Public space, there are several MCD files in the CHEM 231-Harris-MathCad folder -- take a look at these!
Individual Assignment:
Pick a sparingly soluble salt that has pH-dependent solubility, and construct a plot showing the solubility of the salt as a function of pH.
Hint: you will need to define the Ksp and the Ka(s)
Hand in:
Printouts of your monoprotic acid calculations and plots.
Printouts of your solubility calculations and plots.
Be sure to put your name on all printouts!!
Contributors and Attributions
- Timothy Strein, Bucknell University (strein@bucknell.edu)