Mathcad Tutorial Introduction & Examples - CADDIT Australia

40
- 1 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/ CADDIT.net CADDIT Guide: Overview of Mathcad 14.0 basics & Industry Specific Features. ©2009 CADDIT Pty Ltd, CAD and Design software partners Liverpool, NSW 1871. Visit us at www.caddit.net

description

Mathcad tutorial for Mathcad 14 scientific and math calculation and graphics software. Exmaples in statistical approximation, medical grpahics optimization and academic study from www.caddit.net Australia.

Transcript of Mathcad Tutorial Introduction & Examples - CADDIT Australia

Page 1: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 1 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

CADDIT.net

CADDIT Guide:

Overview of Mathcad 14.0 basics & Industry Specific Features.

©2009 CADDIT Pty Ltd, CAD and Design software partners Liverpool, NSW 1871. Visit us at www.caddit.net

Page 2: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 2 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Contents Mathcad - Exploring the possibilities................................................................3 Mathcad – “Jack of all trades”...........................................................................4 Using Mathcad – Beginner’s Overview .............................................................6

Inserting Text, functions, values and changing the unit system ........................... 6

Errors and solution checking for calculations .......................................................... 7 Entering Characters and other functions using shortcuts...................................... 8 Graphing ........................................................................................................................ 8 Integrating Mathcad with PTC Pro/Engineer ......................................................... 11

Mathcad Libraries and Extension Packs ........................................................13

Mathcad Engineering Libraries ................................................................................ 13 Mathcad Extension Packs ........................................................................................ 13

Industry Specific Examples .............................................................................14

Chemical Analysis ...................................................................................................... 14 Medical Imaging and Nuclear Medicine.................................................................. 18 Preconditioning Data ................................................................................................. 29 Descriptive Statistics.................................................................................................. 34

Index ..................................................................................................................39

Page 3: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 3 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Mathcad - Exploring the possibilities Let’s journey back to a time before all our fancy electronic gizmos and time saving devices, to a time where maths was much simpler and counting was done simply with the use of our fingers or a tally stick. As record keeping methods and arithmetic developed so did our use of tools such as the abacus particularly in parts of Asia and Africa. The abacus was in use centuries before we adopted the written modern numeral system.

We have since then had many technological advances beginning with the invention of the calculator. Now imagine life without calculators, not only would calculations be much more difficult to compute but more advanced calculations would also occur at a snails pace. Think of the implications in fields such as mathematics, science, engineering, business, and aerospace just to name a few. There would have been obvious limitations placed on the growth and development within these fields. Further advances have since occurred in the field of software to help cope with the very real and present demand for a mathematical program that allows users to perform, document, share calculations and

design work. Mathcad was first introduced in 1986 and is the first and only engineering calculation software that automatically computes and documents engineering calculations while dramatically reducing the risk of costly errors. Mathcad version 14.0 is now the global standard in engineering calculation. Mathcad is used by engineers, scientists and other technical professionals to capture knowledge reuse calculations and encourage collaboration. Its unique visual format and easy to use scratchpad user interface (WYSIWYG) integrates standard mathematical notation, text and graphs in a single worksheet makes life simpler. Mathcad is superior to any proprietary calculating tool and spreadsheets in that it allows you to document, format and present your work while simultaneously applying comprehensive mathematical functionality and dynamic, unit aware calculations. PTC have coined the term “Engineering excellence” however this ebook is aimed at looking not only at the field of engineering but the other possibilities that exist for Mathcad in other industries including the medical and scientific fields. Mathcad is not only easy to learn but easy to use and does not require additional programming skills or training required for its use. It is able to increase productivity and improve verification and validation of calculations within a variety of industries. Not only is it able to reuse calculation content saving time and effort, Mathcad is able to securely manage calculations and ensure a significant reduction in errors.

Page 4: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 4 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Mathcad – “Jack of all trades”

Mathcad is a mathematical "Jack of all trades" application for visual calculations in engineering, medicine, imaging, quality control, statistics, data analysis and transformation. Here are just a few examples of the fields for Mathcad application.

Concept Field MathCAD module Comments

Quality Control Data analysis - Utilities and

descriptive statistics

Quality control and quality engineering are used in developing systems to ensure products or services are designed and produced to meet or exceed customer requirements. It deals with assurance and failure testing in design and production of products or services, to meet or exceed customer requirements. Therefore it is an extremely important aspect in the manufacturing process and errors can result in loss of productivity, time and money. Mathcad can help to accelerating products to market, reducing costs and eliminating the risk of design failures.

Chemical analysis Data analysis - Preconditioning

data and interpolation

Chemical analysis deals with the central tasks of finding out the identity of an unknown substance, determining its properties and structure, isolating it from other components, and detecting it and quantifying its amount in a given system. e.g. Water analysis, metal detection, assay & purity testing, spectroscopy, titration, nuclear magnetic resonance. http://science.widener.edu/~svanbram/mathcad.html

Civil and environmental Engineering

Data analysis e.g. When comparing two different materials the Wilcoxon Signed-Rank Test can be used to find to some degree the statistical significance, whether the means of two different data sets are equal, i.e. if they came form the same distribution.

Signal/ waveform preconditioning

Data analysis - Mean

smoothing - Cosine

smoothing

Many of today’s applications require measuring, or creating a precise signal in a very noisy environment. This may require the use of smoothing filters however some built-in filters tend to over-smooth data, removing important features. MathCAD allows for greater control in order to obtain the desired level of filtering required for a specific task. http://www.caddit.net/forum/viewtopic.php?p=771 http://www.imakenews.com/ptcexpress/e_article001119634.cfm?x=bcR12Vy,b3jsqcsB,w

Astronomy Data analysis

Mathcad can also have applications in the field of astronomy. For example it can be used to generate a set of orbital elements for the planet a planet that can be used to calculate its position at any instant of the year. Orbital elements are a dynamical astronomer's way of describing an orbit in a manner that is useful for calculating positions in the orbit E.g. Two-Point, Two-Body Elements for the Planet Jupiter

Equipment calibration

Data analysis Effective calibration and maintenance of equipment and measuring devices is an often overlooked, but critical component of an effective, long-term quality management program. Mathcad helps improve the life and accuracy of equipment by implementing reliable, effective calibration and maintenance processes. e.g. Calibration of thermocouples

Page 5: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 5 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Medical imaging (Radiodiagnostics, electron microscopy, nuclear medicine)

Imaging Processing & Wavelets

Image processing and analysis can be used to clean images, remove distortions,

highlight important features, add colour, image manipulation, manipulating colour,

combining images, zoom, enlarge, making images crisper, create inverse images and

much more. It is also a means of extracting quantitative information from images as well

as a means of detecting and measuring objects in images.

http://www.caddit.net/forum/viewtopic.php?t=243

Speech pathology Imaging Processing & Signal Processing

The Speech spectrogram module along with the Fourier transformations module can be

used in the area of Speech Pathology to analyse abnormal speech patterns.

Forensics & Security

Wavelets Fingerprint recognition or fingerprint authentication refers to the automated method of verifying a match between two human fingerprints. Wavelets are particularly useful in compressing digitised fingerprints. Wavelet methods were selected as part of an FBI standard for compression of fingerprint images. http://www.afp.gov.au/national/e-crime/forensics.html

Page 6: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 6 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Using Mathcad – Beginner’s Overview

Here’s a basic introduction to some of the tools and applications available in Mathcad.

Note: For help on installing Mathcad for the first time, click HERE.

Now, as we start Mathcad software, a window as the one shown here should appear. On this Image, each area of the window is labelled for your consideration as we walk through the workspace or window in which you will be working in.

The drop menus are the list of menus in which you can find various commands to math, graphics symbolic options to use in Mathcad as well as the various functions of editing and controlling your worksheets that you will working with. The Insert, Format and Symbolics menus are the most commonly used drop menus to gain access to the different mathematical function at your disposal with Mathcad.

As we go down further in the image from the drop menus, there are list of icons where are all shortcuts various and commonly used functions in Mathcad. This is known as the main toolbar. Here you can save, cut, paste, change fonts and sizes and other various functions as well. Under the main toolbar is the math palette. Here is a set of shortcut icons of just a few of the many functions that are with Mathcad. Note to take is that by clicking on any of the icons in the math palette will open an additional dialogue box which will allow you to use the various options are made available to you. In addition to that, there is also a control palette that allows Object Linking and Embedding (OLE). This means that you can integrate various items from other programs to be added to your worksheet in the calculation process. However it is required that you need to understand a degree of scripting before you undertake using this function.

Next is the workspace in which will be doing the layout out of the calculations as well as various descriptions and information to be placed in. At very bottom of it all there is a small section known as the message box. This box will tell you what description of the function you have selected.

Inserting Text, functions, values and changing the unit system

In Mathcad, you have noticed that the position on workspace red crosshair. By selecting a position on the worksheet you will be able to enter in values, text or an equation at that location. Simple arithmetic can be entered via the number pad located on the right hand side of the

Page 7: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 7 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

keyboard or using the calculator icon located in the math palette. By entering an equal sign after the calculation, Mathcad will give a solution. By adding different units in the previous equation by simply re-clicking the area in which the equation is entered, will allow for Mathcad to recalculate the answer in units for you. To change the units in the final answer, just simply double click the unit and a dialogue will open up to allow you to select the various units which are available in Mathcad. Depending on the version you have, the European version will have the units based on the SI system, however you can change to imperial system or US system by going to the drop menu> select tools > Worksheet options >select the Unit system tab and selecting the desired unit system.

Mathcad also has a list of various functions which you can simply access by going to the drop menu > insert > function. This will open a dialogue as shown here, allowing you to access a large variety of functions which are used in mathematics, engineering and other fields requiring calculations.

You can also move singular or multiple calculations on the workspace, by holding the left mouse button and dragging a box highlighting the calculations. You will notice that a hand will appear over the box highlighted allowing you to move calculations freely in the workspace. By using the Shift key, you can deselect various parts of the calculations that you do not want to move.

Errors and solution checking for calculations

Algebraic expressions can also be entered into Mathcad and then able to generate a solution with given values. Firstly, this is done by entering the expression, and then above it entering the values of the various terms show in the equation. Note that if the equation is showing some highlighted parts of the equation, this tells the user that he or she has not entered the necessary values to work out the solution to the equation. Mathcad provides an answer to the highlighted error in the calculation by click on the error itself. A small description will be given. Note to remember is when entering expressions use the colon key Shift+ [:] and when giving a value use For example, In the image below you can see what Mathcad has Identified a problem with my calculation of y here. I haven't given the value for b within the calculations and shown in the next image the problem is identified as soon as I clicked here:

Page 8: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 8 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Entering Characters and other functions using shortcuts

A lot of the functions have been arranged into shortcut keys. Example of this is the Greek characters which are most commonly used in engineering equations and calculations. With Other programs such as excel will require for you to go to the character maps and select the individual and then insert them into the field, cut and paste the expression into the desired equation. Mathcad has provided the shortcut within in the Math palette where you can add the characters individually or by pressing Ctrl and keystroke g to change the previous character entered into a Greek character. Example of this is the pi symbol. To create the character pi, you just have type the letter p and then ctrl+g to change it π or alternatively use ctrl+shift+p to get the symbol of pi.

This is only one example of the various keyboard shortcuts which can be found in drop menu help > quick sheets > keyboard shortcuts.

Graphing

Graphing of various points can be done differently depending on the values which are used as well as the function which is used to generate the graph. Now by creating a table of values (done by right clicking within the workspace >insert table), you can use this to define your graph. Firstly you will need to enter in the values in the appropriate fields as shown in this example. Once you have completed this, the next step will require for you to define the table. In this case, we will define the table as T. Next we will have to define the X and Y axis in which values we will be using. By typing x, : m [ctrl+6], 0, this will give the following function of x:= m

0. This will tell

Mathcad to use the values found in column 0 as the x -values. The process is repeated to the y -axis by replacing the x with y and 0 with 1 giving the function of y:= m

1.

You can also sketch graphs based on data collected by using the matrix function as well to define the values given. This is done by entering the name of the data and then by pressing [Ctrl+M] to open the matrix option. Next define the amount of values which will be entered and enter the data required. For example: the values for X axis can be called xdata and pressing [shift+colon] and then [ctrl+M] to generate the matrix. Next is just adjusting the amount of columns as well as rows for your data. In this example, we will be using only 1 column and 5 rows. Now we enter the vales for the x axis and then repeat the same steps for the y axis.

Page 9: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 9 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Once the values of the X and Y axis has been complete, either go to the drop menu insert and then graph and then X,Y plot or go to the Math palette, graph icon and then x, y plot icon. This will give you a graph which looks like the following image:

You will need now to define the X and Y axis by clicking on the Axis Label under the x axis and type x to set the X axis and repeat for the y axis in a similar fashion. Once you have done this, click outside the graph box to generate the graph. You can adjust the upper and lower limits of the x and y axis values by clicking within the box and changing the values near to the limits of the axis as indicated here. The Graph can also be formatted based on preference of colour, style as well showing the gridlines on graph. This is accessed by right clicking on the graph area and selecting the format option. Here you will gain additional dialogue were you can change the format of the graph to better present the values to your liking.

Going back to the insert text option, various points of the graph can also be labelled and information can be given specific area of the graph. This can be performed by using the insert text function outside of the graph and then selecting the text or label and placing it on the graph as desired. This is another function which allows for the Mathcad user to perform simple and easy task of labelling the graphs properly to share views and ideas other people who are looking through the calculation.

Page 10: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 10 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Multiple algebraic expressions of various graphs can be placed all on a singular graph to compare the differences between functions drawn up. This can be done by entering multiple algebraic by the y axis and ensuring that the expressions are still using the same x values. For example as shown here, we can see that the all the expressions which are used here are labelled different yet still use the same variable (x). Note: When entering in the functions, ensure that the functions used are separated by commas. For example: f(x),c(x),d(x)

3D graphs can be generated in Mathcad by going to the graph palette and clicking on either the surface, 3D bar, 3D vector graph icons. Entering an expression which has more than one variable will generate the 3D graph. Integrating multiple expressions into the one 3D graph can be done by using the matrix function by entering the name of the expression with the two variables, creating a matrix with rows and entering the values into the matrix brackets. Change the appearance of the 3D model is very much the same as the linear 2D graphs as well by right clicking and selecting the properties menu. A Note to remember is that the whole expression is not required to be entered into the graph since you can refer the expression via assigned letter as shown within this example.

Page 11: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 11 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Integrating Mathcad with PTC Pro/Engineer

Mathcad can be integrated into various programs within PTC products. In this tutorial, we will be looking on how to integrate into Pro Engineer via using the parameters as well as relationships within the model in Pro/Engineer. Firstly, start of by creating a part that you want to use in pro engineer. Here we have generated a Cylinder for this example. Once completed, we go to the top of the menu and go to tools/ parameters. Next we enter a new parameter, rename the parameter to an appropriate name and then add a Value. Next, move to the right hand side of the menu and insert the units for the height.

Click okay to confirm. Next, go to top menu to analysis / external analysis and then to Mathcad analysis, this will open a new dialogue as shown below. At the top of the dialogue, you can load previously made Mathcad worksheets or generate a new worksheet to be used in the analysis. Click new and a new worksheet for Mathcad will open. To create a link from Mathcad to Pro/Engineer, it is necessary to use the subscript here in the expressions that are written out. We linked the subscripted height value back to the word height to make sure that Mathcad is processing it to the correct value. We also added an extra line here with height [=] to see if the value is generated correctly. Next we need to link the expressions to Pro/Engineer by going to the properties to the first expression and then going to the Tag Field and type proe2mc. This tells the

program Pro engineer to get the input field from this Mathcad file. The Last Height Expression we will use and go to properties, Tag and type mc2proe. This defines the output field from Mathcad to Pro/Engineer model. Once completed Click save and name file accordingly.

Now go back to Pro/Engineer to the Mathcad Analysis dialogue, click load and select the Mathcad worksheet that you have created. Next, go down the dialogue to add parameter, select the name of the parameter that was created before and next click the input field from Mathcad which was "Height_proe" and click okay. Exit the extra dialogue box and proceed to the output field box in the Mathcad analysis dialogue box. Select the "height_proe" output field defined in

Mathcad and to test, we will use the compute button. Once that the value shows that it has worked by giving the value we defined in parameters in this example, we click add feature, name the analysis accordingly and then save.

Page 12: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 12 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Next, go to relationship where we will need to define the relationship of the Height value on the model with the Mathcad worksheet. To do this we go to the top menu tools / relations and type in the edge to work with, the expression to use found in Mathcad and then where the analysis is located in the feature tree. An example is shown here for the cylinder height.

Once completed, test the relationship to see if it is verified by Pro-Engineer and then click regenerate. Note to remember is that if you change any values in the parameters after the model has been regenerated you will have to click the regenerate button twice to complete the new changes. This is due to Pro-Engineer doing the first initial calculations but not displaying the changes in the model. The second regeneration will regenerate the model that is shown graphically.

These are just the few of the features available with Mathcad that were shown in this Basic Tutorial. For additional information of the functions please refer to the tutorial in Mathcad as well as the quick sheets to help you navigate through the multiple functions of Mathcad version 14.

Page 13: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 13 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Mathcad Libraries and Extension Packs Mathcad offers extensive, content-rich math libraries that contain several well-known reference books delivered as interactive e-books. These engineering discipline-specific libraries include:

Mathcad Engineering Libraries

Mathcad Civil Engineering Library Combines the encyclopedic “Roark’s Formulas for Stress and Strain” with easy-to-adapt structural design templates and examples of thermal design problems.

Mathcad Electrical Engineering Library Provides hundreds of standard calculation procedures, formulae and reference tables used by electrical engineers.

Mathcad Mechanical Engineering Library Combines the encyclopedic “Roark’s Formulas for Stress and Strain” with easy-to-adapt calculations from a classic McGraw-Hill reference book, along with an interactive introduction to the finite element method.

Mathcad Extension Packs contain specialized libraries of functions designed to complement and extend Mathcad Professional's built-in function set. These extension packs expand Mathcad's capabilities while using standard Mathcad functions and operators. To extend the capabilities of Mathcad into specific disciplines, four Mathcad Extension Packs are available:

Mathcad Extension Packs

Mathcad Data Analysis Extension Pack Enables engineers to easily import, manipulate and analyze data patterns and relationships in Mathcad.

Mathcad Signal Processing Extension Pack Offers more than 70 built-in signal processing functions, adding extensive capabilities for performing analog and digital signal processing, analysis and visualization.

Mathcad Image Processing Extension Pack Performs smoothing, crisping, edge detection, erosion and dilation algorithms on color and grayscale images–useful in medicine, astronomy, weather, geophysics, geology, forensics and radar, among other fields.

Mathcad Wavelets Extension Pack Facilitates a new approach to signal and image analysis, time series analysis, statistical signal estimation, data compression analysis and special numerical methods. Engineers can create an almost limitless number of functions that duplicate any natural or abstract environment - useful for compressing vast amounts of data, as in fingerprint identification or coding an MRI.

Page 14: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 14 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Industry Specific Examples As mentioned previously, Mathcad has the capability to be tailored to the needs of specific industries or disciplines. Here are just a few examples of the types of applications that Mathcad can be used for.

Chemical Analysis

(1) Why it is important it consider Mathcad? (2) Working out on how to generate standard curves with higher accuracy and using Mathcad to do the calculations (3) Example Case of an Analysis of Dietary Metabolites in urine. Mathcad is a versatile and powerful mathematical program in which one can be able to do complex calculations and still be able to complete them in a logical fashion. This is extremely useful in providing information that correlated among peers. This example will show how this can be achieved. Here we start with the data which is given and is processed into Mathcad by using the Table function which is assess accordingly by right clicking in the workspace and selecting insert----> and the table.

You may note that this example here is done in duplicates to generate a more accurate result with the standard curve which is required for this assay method. Also it is good to notice that the workspace can accommodate word or text anywhere within the calculations. Now we come down to the second table which we have here with the values which are taken out of the UV-Vis spectrometer. Take note to be able to use the figures later on in Mathcad, you will need to specify the columns that are used in the calculations later on. This is done by using the following keys: [x][:][space][m][desired number according to the column needed]

Page 15: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 15 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Now we will specify the data points in which we will be using, so in the next step when doing standard deviation calculations, the information is available. Now for the equation of standard deviation can be shorthanded later by using a SD(x) can be used later on within the worksheet.

Now we can go to the insert function options to give us all the necessary equations or functions that we require to do simple to complex statistics. This is done by going to the insert ---> function and within the new dialogue on the left as shown here. We go to statistics and select the required functions. Note also that every time you select another function within the right hand window there is box underneath which gives u a description on what that function does as well as the shorthand version of the function in Mathcad. This is valuable since you do not have to come back to the the insert function over and over again.

Page 16: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 16 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

To save time you can see that I am simply cutting and pasting the functions here and editing the values in which the function is to calculate. Simply click within the function where you want to edit and enter in the new values. Now in case the answer do not automatically change with the new values given go to the top of the menus and look for the calculate button as shown here or alternatively by using the F9 key and this will perform the calculate function in Mathcad or Crtl F9 to calculate the complete worksheet itself.

Now after we have completed all the necessary calculations for the standard curve to be used her, we can start using the values here to make our standard curved to do our calculations. Go to the Graph bar and select the x,y plot graph. Now to get the values into the graph we just have to click on the bottom middle box here and enter in x and to the left middle box we add in our functions that we need which is the y function as well as the r(x) which will give us the line of best fit. Now completed, to generate the graph simply click outside into the workspace.

You may notice that the axis of the graph are defined at a undesirable scale. To edit the scale, click the graph once again and you will notice two of additional numbers which are part of the graph on the bottom as well as on the left where the axis are. These numbers are your minimum as well as maximum range values on the corresponding axis. Change these numbers to the desired scale you would like and click outside into the workspace to regenerate the graph with the new changes. To change the Units in which the graph is also spaced out on the axis, right click the graph and select format.

Page 17: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 17 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

A new dialogue similar to the one show here will open and click on the options in the dialogue under the x and y primary axis and un-tick auto grid and set to a desired amount of scale units you would like. Once completed click apply and okay.

Now that we have the standard curve we can start by working out the amount of urea in urine sample, I am going to demonstrate how to integrate excel into Mathcad and vice versa.

Page 18: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 18 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Medical Imaging and Nuclear Medicine Mathcad has a broad range of applications within the medical imaging field. Here’s another example of how Mathcad can be tailored to specific industry requirements. With all radiologist and radiographers, one thing they all know that is important is that the quality of the images taken for the diagnostics must be of the highest quality possible. However, there are many factors that contribute to poor quality image acquisition such as parameters settings for the scan, image contrast, contrast sensitivity, distortion, noise as well as artifacts and blurring. Getting that balance between sensitivity and selectivity creates the need for image processing a necessity. This example will allow for image processing possible to be done in MathCAD, which can be used in the medical field where every little detail makes the difference in giving an accurate diagnosis. We will focus on 5 processes in MathCAD to give quality images without comprising the integrity of the scans taken. 1. Equalisation 2. Function and level mapping 3. Noise and Error measurement 4. Crisping 5. Filtering Noise But why bother using Mathcad to do image processing when other Photoshop programs are available? The answer is simple. Mathcad allows for far greater control on how defined you would like the image to be without comprising the image as well as being able to customize using different algorithms. Also another factor to consider is that the images can be swapped in and out quickly to use the same function or that particular setting just by changing the address line where the image is located. First of all, we will be using an image which has been provided through PTC for this tutorial. In the Handbook for image processing, the image which will be used to demonstrate the various features of the image processing pack in Mathcad is brain.gif as shown here. Through out this tutorial the original image is shown next to the edited image which has been enhanced by MathCAD with appropriate names.

Equalisation

Equalisation allows for the scanned image to be more defined by controlling on how the light and dark values are distributed in defined cumulative histogram of the image. This will in turn create a linear looking cumulative histogram of the scanned image and giving sharper details on the image. Now to activate this function, command line typed out as equalize(M) , as M is defined as your image from the previous line of calculation to this command. However it is best if you use a similar layout to what I will be doing for the example of equalisation here: Firstly, define the image in which is being read. The example show here is that I will be using M to define my image from the MathCAD image processing booklet. M :=READ_IMAGE(“C:\Program Files\Mathcad\Mathcad 14\Handbook\improc\brain.gif”)

Page 19: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 19 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Next I will output the image to a histogram to see the degree of spread of the intensities in the 255 greyscale bands. Note that the number 256 is used since that the intensities start at and include 0 to 255, therefore giving 256 intensities). So the command of H:=imhist(M ,256)

And for the histogram to work, we need to define the data in which the histogram will be using which is the pixel matrix of the image as we defined as so: k:= 0..rows(H) – 1

Next create a Histogram and define the axis accordingly to the Hk as the function and k as the axis values for x and you should get a histogram like this:

Seeing the image is slightly dark, we will be spread out the intensities to define the features on the scan to help get a better detailed image of the scan. For this image, the cumulative histogram is given by the difference equation for C. So we will define as the following and repeat the same steps to create a cumulative histogram as shown with these steps.

Cumulative histogram:

Now that we can see the slope is not linear from the histogram, we will apply the equalise function here to see what happens. We do this by typing the following commands to generate the histogram and the new changes shown Requal :=equalize(M) J :=imhist(requal,256)

Page 20: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 20 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

The new cumulative histogram of equalized image generated by typing the following commands:

Now just generate the cumulative Histogram:

Now as we can see the cumulative histogram is showing a relatively linear curve here give us the following images as a result.

Now as we can see the newly edited image has more defined features since that the equalisation has brought out the lines within the Cerebellum is more defined as well as the sulci and the gyri in the cerebral cortex.

Page 21: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 21 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Function and Level Mapping Function and level mapping shows the different levels of intensities across an existing image which will allow for different areas of the image to be more defined. This can be done to eliminate the amount of background noise as we saw in the equalisation step for the first webinar. To activate this function, type in funmap(M,f) where M is the image matrix which needs to be generated first. The character f in the command is for the function to be performed at each vector or cells in the image matrix (256 levels to map the different intensities) which is going to be used to help define the details on the image. This means that every time that the image matrix is processed by the new function, the mapping image matrix will be also calculated with the new changes to the image at each intensity each time separate as it is applied. To use this function, we type in R := READ_IMAGE("C:\Program Files\Mathcad\Mathcad 14\Handbook\improc\brain.gif"). This allows us to setup first variable for the function mapping. Next we will use a function to help us generate the desired effect. Now there are a number of other functions which can be used for this or custom made for their desired effect. However this will require doing some experimenting and testing of the function applied to the image. For now we will be using the following function to create the desired effect.

Here is a small list of possible functions which can be used for the function mapping.

Once we have completed that we enter in fmap := Re(funmap(R,F)) Since that we have generated the function as well the image matrix to use, using an output image you can see the results.

Page 22: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 22 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Level Mapping Level Mapping allows for the replacement of the intensities with in a specified image by a specified area or vector of intensity. In other to simply put it, to increase the intensity levels within a specific area by use a defined vector. An example of this can be said to be the same of having a 29th element in a vector will give a new level for the pixels with an intensity of 29. It is important to note that images have entries within 0 and the length of the vector used of minus 1. An example of this is that we would like to create an image with a squared intensity scale. We would create a Vector within: r := 0 …255 This will result in the creation of the following curve constructed given us the what the vector will look like.

Now given by imaging pack we can use a number of examples as shown here, to refine the image for better screening and printing resolution.

Page 23: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 23 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

This therefore, helps in enhancing the image for better diagnosis of the patient. Note to remember is that a particular function map or look-up table can be created with monitor or sensor, which maps irregularities cause by the display to their corrected values.

Once we are satisfied with the vector created we apply the vector to the Level mapping function with the following command and specify the image to be used in the level mapping as well. R := READ_IMAGE("C:\Program Files\Mathcad\Mathcad 14\Handbook\improc\brain.gif"). level :=levelmap(R, vec)

Error and Noise Measurement With Error and Noise Measurement, we use functions which are based on the relative error( squared error ration, the mean squared error and the signal-to-noise ration between the two images which are used to be compared. These functions are used to determine the level of noise that affects an image after that it is processed or transmitted. To demonstrate this function we will be looking at a few examples here. Firstly we need to define out variables here: which are R that represents out first or control image matrix that we are using. And Q which is the second image matrix , the same size as the first. Note that the functions return a number which represents the relative error, the mean squared error, or the signal-to-noise ratio (SNR) between M and Q. Remember that all returned values are in decibels (dB). Now the first of the three commands that we are going to be looking at with error and noise measurement is the relative error. This function returns the squared error ratio over all the elements of the two matrices that are defined by M and Q. This is activated by the command of relerror(M, Q).

Page 24: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 24 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Now to workout the squared error ratio is as follows:

Over two matrices, this function rearranged and defined as:

After getting the required values for N by working out the ratios, simply type in the following command to work out the relative error for R: err :=relerror(M ,N) err :=0.0666667 To demonstrate the effect of this function, we will be applying this function to our example image here and define it: R := READ_IMAGE("C:\Program Files\Mathcad\Mathcad 14\Handbook\improc\brain.gif"). Next we will add some random noise to this image by the following command and then calculate the relative error from the image matrix. Q := addnoise(R,.05,128) err :=relerror(R ,Q) err :=0.059 Another way in which you can measure the amount of error in a image is the mean square error function. This gives the average squared error between the selected images of R and Q. For example we can read and define an image first. Once we have done that we can apply the re-quantize to 13 levels on it: R := READ_IMAGE("C:\Program Files\Mathcad\Mathcad 14\Handbook\improc\brain.gif" Q := imquant(R,13)

Page 25: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 25 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

The mean squared error (MSE) is defined as follows: I := 143 J := 234 Next we define the Dimensions of images: I :=0..(I-1) J :=0..(J-1)

MSE= 41.189 Calculating the MSE with the built-in function we obtain the same result: MSE2 :=immse(R,Q) MSE2 :=41.189 The third of the error and noise measurement functions in this section, is the SNR or the Signal to Noise Ratio. This command calculated the singal to noise ration of an image in decibels (dB). For example, let’s say when transmitting a scanned image between diagnosticians via a communication channel. The receive we observe the same image, but is corrupted by some noise interference. We will mimic or recreate this situation by applying the first scan as follows: Q :=addnoise(R,0.3, 150)

The SNR is defined as the ration of the averages of power between the original and of the noise itself. The noise is obtained by subtracting the original image matrix with the recreated noisy image. To activate this function by typing in the function: SNR :=imsnr(R,Q) This gives us a value of 3.57 (dB) Now another commonly used function in image integrity is peak signal to noise ratio (PSNR). This function can be activated by using the following command:

Where A is defined by the image quality used (8 – 24bit, A = 255 for 8bit and A=4095 for 12 bit)

Page 26: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 26 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Crisping Sharpening the details of image is important to give definition to the image when diagnosing a patient. Mathcad provides crisping functions which help in this matter. They are as follows: orthogonal crisping (R) dia – crisping(R) uni –crisping (R) orthogonal5 crisping(R) All of these functions work by the convolution of the specific crisping kernel within an selected matrix defined as R. The Number in the orthongal5 shows that the 5 x 5 kernel is used instead of a 3 x 3 kernel. Crisping can be used to restore lost sharpness to an image which as degraded due to transmission or image processing. The command will result in giving out a more defined or crisper image matrix. The edges remain unchanged since the kernel doesn’t overlap completely in these areas. These are the matrix kernels that are used for the following functions

Now to use any of these functions, firstly define the image to be used and then define the command to be used. For Example, we will use the same scan through this webinar R := READ_IMAGE("C:\Program Files\Mathcad\Mathcad 14\Handbook\improc\brain.gif" Next we blur the image and crisp the image again. R :=orthosmooth(R) Orthogonal := orthocrisp(R) Due to the nature of Crisping functions allowing full floating point calculations and compression of image values, we would need to rescale and equalize to spread the values out again. So in order to save time and space in the worksheet, we will combine these functions all into single line commands as shown here: Orthogonal :=equalize(scale(orthogonal(R),0,255)) dia :=equalize(scale(diacrisp(R),0,255)) uni :=equalize(scale(unicrisp(R),0,255)) Ortho5 :=equalize(scale(orth5(R),0,255)) Here are some examples of combining commands and the results of crisping the original Image.

Page 27: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 27 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Noise Filtering Noise filtering requires experience in the types of noise that the person is dealing with in each image. Depending on what generated the noise, what sort of edge distortions are acceptable in the output and what sort of noise it is will great depend on what sort of filtering which will be used. We will start of with a simple scattering of noise (otherwise known as salt and paper noise). We will simulate this and see if this can be reversed. Orig :=READ_IMAGE(“C:\Program Files\Mathcad\Mathcad 14\Handbook\improc\brain.gif”) Noisy: = addnoise(orig,.2,128) Now to remove this type of noise there are two ways in which can be done to this. Firstly, the use of an averaging function such as smoothing or secondly a more complex method of median filtering. So we will look at the first method of doing this the smoothing filtering. Smoothing of the image can be done by the following command: Smooth := unismooth(noisy) To use the median filtering, type in the following command: Med :=medfilt(noisy) Now the following images will show the difference of the filtering methods as we show the orginal image, the noise generated one, smoothing and the median filtering images.

Page 28: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 28 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

As the images prove, the median filtering is a better filtering method for the scatter noise because it doesn’t change the intensity levels of the images, but uses what is available in the image. To observe these levels, 4 histograms are provide from each image to see the differences between them. To enable this simply type in Intensity := imhist(<name of the image>,256) k:= 0.. length(intensity1) – 1 As shown through the histogram, the original and the median filtering histogram exhibit very similar intensities proving that median filtering is a much more appropriate method in filtering the noise. Median filtering is a better way to filter this type of noise because it does not change the intensity levels in the image, but only uses available levels. To see this, look at the histograms of the four images.

Page 29: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 29 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Preconditioning Data

This example will show how smoothing functions can be used In Mathcad to precondition data before further analysis can be conducted. Data analysis is used in a variety of industries including business, science and social sciences. It involves gathering information, modelling and transforming data into information can that be used to suggest conclusions and support decision making. It is therefore essential to be able to analyse this data quickly and efficiently. Many of today’s applications require measuring, or creating a precise signal in a very noisy environment. This may require the use of smoothing filters however some built-in filters tend to over-smooth data, removing important features. MathCAD allows for greater control in order to obtain the desired level of filtering required for a specific task. The smoothing functions act to remove noise from data in a number of ways. In this webinar I will be discussing 3 different types of smoothing filters available in MathCAD. 1. medsmooth 2. supsmooth 3. vsmooth (new in Mathcad 14)

Lets consider some data:

Sampled at specified intervals:

Inject noise in every fifth sample

Page 30: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 30 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Median Smoothing

The medsmooth function takes a vector of real data, x, and smooths it using a window of length n. The median (midpoint) of the n points surrounding each data point is used to replace the data point, as is suggested in this diagram for a window of length 5: As you can see in this particular data set of 5 values indicated by the blue line, the median (midpoint) falls into the number 3.

It is clear that this graph is significantly cleaner than the original. Median smoothing is particularly useful in cases where there are sudden bursts of noise or incidents of corruption in the data. It is generally preferred over mean smoothing, which has a tendency to blur sharp features in data.

Super smoothing

Consider a cloud-like data set created by corrupting a cosine curve:

Page 31: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 31 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

The supsmooth function takes x data in strictly increasing order (no two x values can be the same). It uses a fast algorithm which sorts through the cloud of data to produce a reasonable periodic pattern. Similar results are obtained from kernel smoothing, but the calculation takes longer.

Repeated smoothing

The smoothing process can be repeated until no additional changes occur on successive applications. The programmed function Smooth below demonstrates this technique. The program will also terminate after 100 applications of medsmooth even if this steady state is not reached.

Consider the data

Page 32: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 32 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

..you can see the effect of different window lengths, and also the plateaus that arise from "sanding" this data too much. VSmooth is the new built-in function which is a variation on the preceding method. It takes a data set x and a vector of window values W1. The function Smooth is applied successively to the data for each value in the window vector.

The data is first smoothed repeatedly until there's no change using a window of

then applies the process to

and finally smooths as much as possible with

as the window width. You can also provide a scalar value for W, in which case only a single window width is used repeatedly.

Page 33: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 33 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Other "smoothers" You may wish to consider various regression techniques as smoothing methods, since fitting a curve to a set of data amounts to finding a smooth function that approximates the data. If you evaluate the function at every original data point in x, you will get a smoothed version of the y data. These smoothers form a core of basic techniques. Other special-purpose built-in functions for smoothing one and two-dimensional data sets are available in the Signal Processing Extension Pack and the Image Processing Extension Pack, available from CADDIT.

Page 34: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 34 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Descriptive Statistics This next example will explain some of the basic concepts involved within the field of descriptive statistics and how these can be done easily in Mathcad. Descriptive statistics is commonly used in the field of medical research studies. It is used to quantitatively describe the main features of a set of data. Inferential statistics differs in that it is used to reach conclusions that generalise beyond the immediate data. Descriptive statistics are used to present quantitative descriptions of large amounts of data in a clear and understandable way. Mathcad offers a variety of descriptive statistical functions to reduce large amounts of data into a much simpler summary. Descriptive statistics are generally presented along with more formal analyses, to give the audience an overall sense of the data being analysed. I plan to go through the following basic functions: 1. mean(A,B,C,...) 2. median(A,B,C,...) 3. mode(A,B,C,...) 4. percentile(v,p) These functions take single or multiple scalars or arrays, and return the mean, median, and mode, respectively, giving measures of the location of a data point relative to the rest of the distribution. The best choice of location estimator depends on the general dispersion or distribution of your data.

Mean In statistics we refer to this also as the "arithemetic mean" and is the most commonly used type of average. To calculate the mean of a set of numbers this involves simply adding the total sum of the numbers in a set divided by the number of items in the set. The other types of averages such as the median and th mode will be discussed later on. Example: Consider the following numeric data:

The arithmetic mean or average of N values is given by the following formula:

The mean is sensitive to changes in values of one or more data points:

Page 35: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 35 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

The mean is greatly affected by significant outliers. So you may find that the mean is a poor description of the central location if this is the case. You may choose to trim the outliers and find the "trimmed mean" for a better estimate. Consider the "trimmed" numeric data:

As you can see I have chosen to leave out the value 46 which was a significant outlier in this set.

MathCAD automatically readjusts all the values of the formulas and recalculate the new mean for this data set.

Median The median, or "middle value," of a set of data is another description of central location. The median depends on the relative positions of the data, not on the actual values of every data point, and so is relatively insensitive to small changes in individual data values. Mathcad's median function does not accept complex numbers. A median is the value falling in the middle when data are sorted in ascending order (smallest to largest). Example:

If there are an odd number of data, there is one data value which is the median. e.g. if a<b<c then the median for the list {a,b,c} is b Example:

Page 36: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 36 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

If there is an even number of data, the median is taken to the be mean of the two middle numbers. e.g. if a<b<c<d then the median for the list {a,b,c,d} is the mean of b and c i.e. (b+c)/2. Example:

Mode The mode refers to the value that occurs the most frequently in a data set. Example: In a data set where there are no repeated values, you see an error message like the one shown below.

Example: In the case where more than one data value is repeated with the same frequency, the mode function also gives an error, with the message "multimodal."

Page 37: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 37 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Percentiles and quartiles Percentiles measure which values of a data set fall below which a certain percentage of the total number of points/observations. E.g. the 20th percentile of a range of data is the value below which 20% of the observations may be found. The 25th percentile is also known as the first quartile (Q1); the 50th percentile as the median or second quartile(Q2); the 75th percentile as the third quartile (Q3). Example: If your data set has 11 points/entries, the 50th percentile is the value of the median (or 6th point) and so on. The percentile function takes a vector of data and a percentage between 0 and 1 and returns the value of the percentile.

Note that if the indexed value occurs between two data points, then we have to calculate the amount to add or subtract from an actual point in the data set to give the percentile. A quartile is one of the three percentiles that mark 1/4 of the data: Example:

Page 38: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 38 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Quartiles are best used for graphical analysis of data in Quantile-Quantile plots.

Page 39: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 39 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

About the Authors

Nhung Huynh coordinates Mathcad support at CADDIT Australia. She has both mathematics training and

application experience, primarily in the medical field . CADDIT is a full service CAD CAM and design

consulting service in Sydney Australia offering an extended portfolio of design and manufacturing software

and services. They can be contacted via their website at http://www.caddit.net.

Page 40: Mathcad Tutorial Introduction & Examples - CADDIT Australia

- 40 - “Using Mathcad”, Published by CADDIT Australia, Mathcad Sales & Support - http://www.caddit.net/

Index

Chemical Analysis, 12 Crisping, 24 Descriptive Statistics, 31 Equalisation, 16 Error and Noise Measurement, 21 Function Mapping, 19 image processing, 16 Level Mapping, 19 Mathcad

Data Analysis Extension Pack, 11 Entering characters, 4 Entering functions, 4 Errors, 4 Extension Packs, 6 Format, 4 Graphing, 6 Image Processing Extension Pack, 11

Inserting functions, 4 Inserting text, 4 Intalling, 4 Libraries, 6, 11 Signal Processing Extension Pack, 11

Solution checking, 4 Symbolics, 4

Toolbar, 4 Units, 4 Values, 4 Wavelets Extension Pack, 11

Mean, 31 Median, 32 Median Smoothing, 28 Medical Imaging and Nuclear

Medicine, 16 Mode, 33 Noise Filtering, 25 Object Linking and Embedding

(OLE), 4 Other "smoothers", 30 Percentiles and quartiles, 34 Preconditioning Data, 27 PTC, 3

Pro Engineer, 6, 9, 10 Repeated smoothing, 29 Smoothing filters, 27 Standard curves, 12 Statistics, 13 Super smoothing, 28 Workspace, 4