





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A part of lecture 2 from computer methods (cgn 3421) course by kurt gurley. It covers the basics of mathcad, including operators, regions, range variables, and functions. How to create and use regions, equation regions, text regions, graphics regions, and disabled equations. It also discusses the concept of areas and aligning regions. Furthermore, it introduces the use of range variables to create vectors and generalize end points of evenly spaced vectors. Lastly, it provides an overview of functions and their creation in mathcad.
Typology: Assignments
1 / 9
This page cannot be seen from the preview
Don't miss anything!






( ) ‘ ^ highest level, first priority
y := 2 x := 3 * y^2 x = 12
y := 2 x := (3*y)^2 x = 36
y := 2 x := 3 * y + 2 x = 8
z := 36+62/4 z = 21
x := 5^2/2 x = 12.
We’ll each develop a simple template to use to start any new homework. The idea of a template is to lay- out the basic structure of what goes into a homework assignment, minus the actual input, calculations, and output necessary for a specific assignment.
To create template: Simply start a new worksheet and type in what you want on the template. Then use Save As and pick the mathcad Template option.
To use template: From mathcad, open the template through the File --> Open command and change the Files of Type box at the bottom to Mathcad Template. Before adding any information to the template, save it as a standard worksheet of desired name by using File --> Save As. Note that the Save as Type box at the bottom auto- matically is set to standard Mathcad Worksheet format. Choose a name and save. Now the original tem- plate is preserved for the next use, and you can begin work on your new assignment.
The basic structure and ingredients for every homework is given below. We’ll base our template on this.
Title Page: Info: Name, Course, Assignment Number and Title.
Summary/Observations: A brief summary (description) of the assignment. What did the assignment ask for? What did you learn? Did you discover anything easy/difficult with the assignment? It doesn’t have to be long, just clear and concise.
Pseudocode: Pseudocode is a detailed description of the steps needed to solve the prob- lem from beginning to end.
Work Page(s):
Standard Code: Any Mathcad statements needed in every worksheet. (e.g. ORIGIN=1)
Input Section: Scalars, vectors, matrices needed to begin calculations. Includes both per- manent assignments and user prompted information as well as data file loading.
Calculation Section: Manipulations of the input information
Output Section: This should include all your results (vectors, graphs, etc.). Clearly label what each piece of output is.
Hand Verification: A sample problem by hand or other means independent of Mathcad. You need not verify every calculation, just samples to show your Mathcad results work.
Labeling the program using comments program title student information program summary
executable statements program input (load data from external files, assignment statements, etc.) perform operations needed (sequential execution, loops, etc.) display program output (graphs, numbers, output files, etc.) intersperse comments to explain program
Mathcad releases new versions of their product at a fairly quick pace. As a result, you will probably come across more than one version, including: Mathcad 8, Mathcad 2000, Mathcad 2001 (the latest). From 2000 or 2001, you can use Save As to save your worksheet in an older format if desired. This is neces- sary, for example, if you bought 2001 for your personal machine. Both 200 Weil and the Circa labs use Mathcad 2000 (we’re not convinced its worth the price to upgrade yet). Newer versions of mathcad CAN open worksheets made on older versions (2001 can open a 2000 worksheet), but older versions CAN’T open worksheets from newer versions (2000 can not open a 2001 worksheet). So if you create a work- sheet at home (2001), and try to open it at school, you won’t be successful. You can avoid this using the Save As older versions feature. That is, 2001 can save into 2000 format so you can create in 2001, and open in 2000. You can still open in 2001, but now you can also open in 2000.
A region is a spot in the worksheet where you enter text, equations or graphs.
Equation regions:
By default, when you click the cursor, mathcad assumes you are entering an equation into this new region. We’ve already seen how to assign numbers to variables, etc. Every number-manipulating type of expression is considered an equation region, including control structures (if statements, for loops, etc.)
Text regions:
You can also place the cursor and start typing your text. You may find that typing text doesn’t always look like you would like it to, since Mathcad expects an equation by default, and can make some assump- tions you didn’t intend. To ensure that the region you are starting is text (for headings, instructions, com- ments, etc.), just pace the cursor, then type “ to initiate a text region. Be sure to try out the Format menu to practice with changing fonts, styles, colors etc. to give your worksheet a professional look.
Graphics regions:
These regions can be initiated from the Insert menu, from the View -> toolbars -> graphs tab, or keyboard shortcuts ( typing @ creates a 2-D graph). You must fill in the placeholders for the x and y axes to tell Mathcad what to plot.
Inserting Equation regions into text regions
When using text to explain the contents of a worksheet (talking through the equations so others can fol- low your work), it is possible to import an equation region directly into a text region. This can be done by initiating your text, then placing the cursor where you want the equation, and using Insert -> Math Region.
Enabled and Disabled Equation Regions
You may find occasion to wish you could ‘turn off’ an equation without actually deleting it. For example, an equation that appears for explanatory reasons within text may only be for show, not for function. Other reasons will come about as you begin to debug more complicated worksheets, and you want to see what happens if equation A wasn’t there (but you want to save it for later). Disabling an equation is easily done with the cursor by right-clicking in a equation region and clicking ‘Disable Evaluation’. A small mark will appear by the equation to let you know its disabled. It will remain disabled until you turn it back on in the same manner (right-click, and click Enable Evaluation).
Alignment of regions
After entering numerous different text, equation, and graphics regions, the look of the worksheet can get to look a little messy. For example, headings for sections may not be in line with each other vertically, equations that are next to each other may not be aligned exactly. You can adjust each region individually to fix this, but this can be imprecise, and tedious. Mathcad has an automated aligning feature to help neaten-up the look. Try entering three separate lines of text. Now use the mouse to highlight all three regions. Now use Format -> Align regions to line them all up neatly. If you nave many regions, and desire different alignments to different groups of regions, you can hold the Ctrl button and left click selected regions, then align.
An area is a section of the worksheet you create, in which you can place various regions. The purpose is to be able to group regions that you might want to hide or even lock from other users seeing, changing, or both. All equation and graphics regions within an area work just like they would anywhere else. Try cre- ating a region by placing the cursor and using Insert --> Area. You will see two horizontal lines span the page. The area is the region between the lines. You can enlarge the area by clicking the upper or lower line defining the area and dragging it up or down. You can now drag regions into the area, or create new regions within the area.
Collapsing areas
The reason for creating areas is to allow you to collapse or hide groups or regions without losing their function. After setting up an area and creating a few regions within it, double click the upper or lower area line to collapse the area (you’ll see the regions disappear). Another method is to left click the upper or lower area line and then right click to make options appear, including ‘collapse’.
locking areas
You can also lock an area so that you (or more important, someone else) can’t change any regions inside the area. The equations still work. No one can change anything in the region until they enter a password that you determine when you lock the area. Of course, you can combine the locking and collapsing so that no one can even look at the regions in the area until entering the password.
Generalizing end points of an evenly spaced vector:
We can generalize the previous operation to arbitrary starting and ending points. We want to create a vec- tor that spans from -2 to 5 in even steps of 10.
first enter scalars and calculate increment begin := -2 end := 5 NP := 10 inc := (end-begin)/(NP-1)
Now create the range variable ‘i’ and use it to create the vector ‘x’ i := 1;10 x (^) i := begin + (i-1)*inc
Creating 2-D arrays using range variables:
We can extend the idea to arrays of 2 dimensions. Suppose I want a 3 by 5 matrix in which each element is the sum of its indices...
i :=1;3 j :=1;5 z (^) i,j := i + j
Note that the operation on the right hand side of the equal sign is calculated for every combination of the values in the range variables 1 and j.
Generalizing to nonlinear relationships:
How can I create a vector that contains the expression: for in steps of 0.25 ??
We can create two vectors (x,y) and pull the same stuff.
xT^1 2 3 4 5 6 7 8 9 1 -2 -1.222 -0.444 0.333 1.111 1.889 2.667 3.444 4.222 5 inc =0.778^ =
z
2 3 4
3 4 5
4 5 6
5 6 7
6 7 8
=
begin :=^ − 3 end :=^4 inc :=^ 0.25 NP end^ begin − inc
:= + 1
i := 1 ..NP xi := begin +(i − 1 ) inc⋅ y (^) i :=( xi)^2
(^05 0 )
10
20
y
A single or multiple commands can be assigned to a single word (or letter) that represents those com- mands, followed by a list of inputs within parenthesies. Once this assignment is made, you can re-issue all of those commands again and again by using the single word. A simple example is the creation of a long equation that you intend to use more than once. Why re-type over and over?
To the right I’ve created a function called ‘y’ which is a function of ‘t’. To use it, just ‘type y(number)=’ to view the result. Note that we can send in scalar values or a range variable ‘i:=1,1.5..2.5’ which produces 4 answers.
A function with more than one line of commands has a distinct look by the use of a verticle line to the right of the name we give the function, and to the left of the statements in the function. Let’s say we want to create a function to solve the quadratic equation, and we break down the solution into parts. The way to create the vertical line is either the right square bracket, or go to ‘add line’ from the ‘programming’ tool- bar (under view => toolbars)
Note that the solution requires 3 pieces of input information, and the output has two pieces of informa- tion. We can now call this function from wherever we like in this worksheet (after the function defini- tion). Of course I validated the answers I got to make sure they are correct.
IMPORTANT: None of the variables created in the function are recognized outside the function, except those listed at the end. In this case, ‘ans’ is listed at the end, while ‘radical’ is not. Therefore, the contents of ‘ans’ is transfered out to become the answers, while ‘radical’ is not recognized outside the function. You can see this above. I tried to type ‘radical = ‘, but Mathcad did not recognize the variable name, and
y t( ) := 5 + 0.6t− .2 t ⋅ 2 +log ( sin ( )t + 2 )
y .1( ) = 5.38 y 30( ) =−156.
x := 6 +y 4( ) 2 x =24.
i := 1 1.5, ..2.5 y i( )
=
QuadEq a b( , ,c) radical b 2 ← −4 a⋅ ⋅c
ans 1 b − +radical 2 a⋅
←
ans (^2) −b −radical 2 a⋅
←
ans
:=
QuadEq solves the quadratic equation of the form (^) a x ⋅ 2 + b x⋅ + c= 0
QuadEq 2 3( , , 1 )
−0. − 1
= QuadEq 4 0( , ,− 16 )
2 − 2
= radical :=
ans is the 2x1 vector to be reported as output from the function