Skip to main content
Chemistry LibreTexts

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}}\)

    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:

    1. 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.
    2. 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.
    3. 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.
    4. 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).
    5. 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).
    6. To select an entire object (text or equation) that you have already typed, click and hold as you drag across the object.
    7. To edit a specific part of an object (text or equation) click on the spot you would like to edit.
    8. 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”.
    9. Use the left/right arrows to “scroll through” an equation when editing it.
    10. 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)
    11. When performing multi-term calculations (such as a calculations) that include fractions, make use of parentheses to move from one term to the other. 
    12. 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:

    1. Have Mathcad add 20 and 22, then divide the total by 7, all in one step. The answer should be 6.
    2. Now, define a=20, b=22, and add a+b and divide the total by 7.
    3. 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.
    4. 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?
    5. 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:

    1. Define Ka, Kw, and F (the formality of your acid in solution)
    2. 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: 

    1. Define the “tolerance” by typing

      TOL:= 10-22

      (this lets MathCad know that anything smaller than 10-22 can be interpreted as zero).

    1. 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).

    1. 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:

    1. 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.

    1. 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


    This page titled MATHCAD Tutorial is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by Contributor via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.