1 / 31

Mathcad Variable Names

Mathcad Variable Names. A string of characters (including numbers and some “special” characters (e.g. #, %, _, and a few more) Cannot start with a number Capitalization & spelling count!!! A1 is different from a1 Be careful not to conflict with predefined name

barth
Télécharger la présentation

Mathcad Variable Names

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Mathcad Variable Names A string of characters (including numbers and some “special” characters (e.g. #, %, _, and a few more) Cannot start with a number Capitalization & spelling count!!! A1 is different from a1 Be careful not to conflict with predefined name (e.g. g = acceleration due to gravity, m = meter, etc. -- which we will discuss later) Be careful that variables and functions have different names

  2. Subscripts The “.” (period) starts a text subscript, which really is part of the variable name A1 is different from A1 The “[“ indicates an array subscript. Thus A1 indicates an element in the array A (it is the second element, as array subscripts start with 0 by default in Mathcad)

  3. Functions Similar to Excel function Have a name with argument list in ( ) Return a value ( or set of values)

  4. Common math functions implemented as functions or predefined symbols (from the calculator tool pad: Or \ Square Root:  Absolute Value: | | (put expression in edit box, hit | key) Powers of “ e “ : e

  5. Most available as function with a standard math name: log ln sin cos exp abs

  6. Other somewhat useful functions: If ( test expression, true result, false result) Health (Temp) = if ( Temp>98, “Fever”, “No Fever”) Health(100) = “Fever” String functions --- to find length, take substrings, search, concatenate + others.

  7. And, as you might expect, we can write our own. We will look at writing simple functions that can be expressed as a single mathematical expression Example: Function to compute volume of an ideal gas as a function of the gas constant (R) , temperature (T), pressure ( P), and moles (n)

  8. First, define the function as you would assign a value to a variable ( use the := sign ) Vol(P,n,R,T) := n*R*T/P Use it like any other function: Volume := Vol(100,1,0.08206,273.15)

  9. Functions can take and use units: Vol ( 1 atm, 2 mol, 0.80206 L*atm/(mol*K), 500K) = 41.03 L But as with all use of units in Mathcad, must be consistent. If evaluation results in incorrect unit operations, will get an error message ( the variable or whatever in red )

  10. Functions Functions “know about” variable values defined to the left and above its definition and those values will be used when the function is used. A:= 3 Y(x) = A*3 Y(2)=6 A:=10 Y(2) = 6

  11. Functions Functions can have other functions in them, providing they have been previously defined. Y(x) := x2 A(y, x):= y2+Y(x) A(2, 3) = 13Y13

  12. Arrays, Vectors, & Matrices Range Variables Brief Introduction to Plots

  13. Arrays Ordered set of numbers Vector Single Row Or Column Matrix Two or More Rows and / or Columns

  14. Arrays Access elements with array subscript “ [ “ Maximum of two dimensions Define with ctrl-m or matrix tool button First element has index of [0] or [0,0] (can change with the ORIGIN keyword)

  15. Basic Operations Scalar add & multiply -- affects Each element in the array Determinant & Inverse -- square matrix only -- short cut key strokes ( | | & ^ -1 ) Add, subtract, multiply with usual matrix rules on size & shape -- standard math operators (+, - , *)

  16. Resize Operations Add / Delete Rows Add / Delete Columns Add / Delete Rows & Columns Put array (or element) in edit box, type ctrl-m

  17. Vectorize Operation This is a non-standard matrix operation in which the indicated operation is performed element by element

  18. Standard Multiply Vectorized Useful, but be careful!

  19. Range Variable A special type of Mathcad variable Takes on the indicated range of values when found in the worksheet

  20. Range Variable Var := First, Second; Upper Limit ( the ; shows as … ) J := 1,3;10 J takes on values 1, 3, 5, 7 & 9 each time it is in found in the worksheet (following usual worksheet evaluation – To right or anywhere below)

  21. Define and fill a matrix in 4 steps:

  22. Arrays can have units, but each element must have the same dimensions

  23. Range variable not limited to integers:

  24. Range variable can have units:

  25. Plots As in Excel, many type of plots. We will look at the x-y plot

  26. From the menu: Insert / Graph / X-Y plot Add X vector in the box on the x axis Add Y vector in the box on the y axis Can add multiple x – y vector pairs. Works in internal units – no units on plot

  27. Insert / Graph / X-Y Plot Click on plot, then right click to get format menu

  28. Plots If would like specific units for a plot, need to convert the data before or during plotting. Say wanted previous plot in ft & ft^2

  29. As with Excel, plot not complete until has title and axis labels

  30. To add axis labels & titles, select plot then right click. • Choose “Labels” and add as desired • To get rid of Mathcad’s variables, • choose “Trace” and check “Hide Arguments”

More Related