Computer MODULE Introduction To MathCad (MathCad Organization)

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 53

14.

MODULE 3
Introduction to Mathcad
(Mathcad Organization)

By: Engr. Rizza P. Gamalinda


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

MODULE 3: MATHCAD

▪ WHAT IS MATHCAD ?

PTC Mathcad is the industry’s standard technical tool for Engineering


calculation software, enabling you to solve and analyze your most complex
problems. Its live mathematical notation, units intelligence and consistency, and
powerful calculation capabilities, presented with convenient interface, allows you
to capture and communicate your critical design and engineering knowledge.

Mathcad delivers all the solving resources, functionality, and strength


needed for calculation, data manipulation, and Engineering design work. It allows
you to document your calculations in the language of mathematics because
Mathcad merges a powerful computational engine, accessed through conventional
mathematical notation, with a full-featured word processor and graphing tools. By
combining equations, text, and graphics in a single worksheet, Mathcad makes it
easy to keep track of the most complex calculations and aids knowledge capture
and publication that helps management of large projects.

You can type any equation like how they are written on a paper. Simply type
your equations and Mathcad will provide you instant result, along with as much
text as you want to accompany the math. You can use Mathcad equations to solve
both symbolical and numerical equations. You can place text anywhere on the
worksheet and add two- or three-dimensional graphs to the worksheet.
Additionally, you may even illustrate your work with other images taken from
another application.

Mathcad lets you simply mix and convert between different unit systems.
You can work in your preferred unit system or switch to another system. You can
trace unit mistakes by checking your worksheets for dimensional consistency.

DISCLAIMER. The sample PTC Mathcad 14 in this module is to provide the reader
with knowledge of how Mathcad may be used in this subject and for future
references. Before using the worksheets in this application, the reader should
understand the content and usage of said application.

By: Engr. Rizza P. Gamalinda P a g e 1 | 26


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

EXPLORING THE PTC MATHCAD 14 ENVIRONMENT

The screenshot figures in this module are based on PTC


Mathcad 14 running on Windows 10.

Mathcad Icon

▪ THE MATHCAD WORKSPACE

When you open Mathcad, you see the interface like that shown in Figure
3-1. The MathCAD workspace is considerably different from most “spreadsheet
style” data analysis program (like Excel). Equations, data tables, graphs and
descriptive text can all be combined in one MathCAD document, making this
software particularly handy for application development.

Figure 3-1. Mathcad 14 Interface

By: Engr. Rizza P. Gamalinda P a g e 2 | 26


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

▪ MATHCAD FILE

Whenever a new Mathcad worksheet is created, it is named as [Untitled:1]


by default.

▪ CREATING A MATHCAD FILE

Whenever a new Mathcad worksheet is created, it is named as [Untitled:1] by


default. A new worksheet can also be created while working in an existing Excel
workbook by typing Ctrl + N (done by clicking the Ctrl key and N key
simultaneously) to bring up a blank worksheet the same setup with the existing file
or by selecting the File Menu tab, clicking on New to emerge the New Worksheet
Templates Dialogue box (see figure 3-2).

Figure 3-2. Creating new Mathcad file from the File Menu Tab and the New Worksheet Dialogue
Box.

▪ MATH TOOLBAR

Each button in the Math toolbar or Math Palette opens another toolbar of
operators or symbols.

Figure 3-3. Mathcad 14 Interface with various toolbars displayed.

By: Engr. Rizza P. Gamalinda P a g e 3 | 26


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

This Math Palette contains all the sub toolbars such as calculator, graph,
matrix, evaluation, Boolean, programming, Greek symbol and symbolic keyword
palette (see figure 3-3).

Calculator: Arithmetic operators.

Graph: Two- and three-dimensional plot types and graph tools.

Matrix: Matrix and vector operators.

Evaluation: Equal signs for evaluation and definition.

Calculus: Derivatives, integrals, limits, and iterated sums and


products.

Boolean: Comparative and logical operators for Boolean expression.

Programming: Programming constructs.

Greek: Greek letters.

Symbolic: Symbolic keywords and modifiers

▪ STANDARD TOOLBAR

The Standard toolbar provides quick access to many menu commands.

Figure 3-4. Standard toolbar.

▪ FORMATTING TOOLBAR

The Formatting toolbar contains scrolling lists and buttons to specify font
characteristics for both equations and text.

Figure 3-5. Formatting toolbar.

By: Engr. Rizza P. Gamalinda P a g e 4 | 26


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

NOTE:
▪ To know what the name and function of a button on any toolbar is, hover
the mouse cursor over the button until a tooltip appears beside with a
brief description.

▪ You can choose to show or hide any toolbar from the View Menu. To
detach and drag a toolbar around your window, place your cursor on the
edge of the toolbar on the left where a. Then hold down the mouse button
and drag.

▪ You can customize the Standard and Formatting toolbars. To hide, add
and remove buttons, right click on the toolbar, and choose Customize
from the menu to display Customize Dialogue Box.

▪ REGION

Mathcad allows you to enter text, equations, and plots anywhere in the
worksheet. Each piece of text, equation, or other element is known as a region. A
Mathcad worksheet is a collection of such regions.

To start a new region in Mathcad:

1. Click anywhere in a blank area of the worksheet. You see a small crosshair.
Anything you type appears at the crosshair (see figure 3-6).

2. If the region you want to create is a math region, just start typing anywhere you
put the crosshair. By default, Mathcad understands what you type as a
mathematical language see figure 3-6 for example.

3. To create a text region, (option 1) click Insert Menu and select Text Region,
(option 2) just click anywhere the worksheet and start typing or (option 3) simply
press [“] and then start typing.

Figure 3-6. Example of simple calculation and image for cursor in Mathcad.

By: Engr. Rizza P. Gamalinda P a g e 5 | 26


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

From figure 3-6, this is an example how Mathcad works on a calculation:

• Mathcad sizes fraction bars, brackets, and other


symbols to display equations the same way you
might see them in a paper.

• Mathcad understands which operation to perform


first. Mathcad knew to perform the PEMDAS and
displayed the equation accordingly. See Figure 3-
7 to check Mathcad’s result compare with a
calculator.

• As soon as you type the equal sign, Mathcad


returns the result. Mathcad processes each
equation as you enter it. Figure 3-7. Calculator

• As you type each operator, Mathcad


shows a small black rectangle called a
placeholder. Placeholders hold spaces
open for numbers or expressions not yet
typed. If you click at the end of an Figure 3-8. Placeholder
equation, you see a placeholder for units
and unit conversions.

• Once an equation is on the screen, you can edit it by clicking in it and typing
new letters,
numbers, or operators.

ADDITIONAL INFORMATION:

▪ To add a border or to highlight a certain region, select the region(s), then


right click to display menu, choose Properties from the list (see figure
on left).

▪ The Properties Dialogue Box will display, click on the Display tab and
click the check box beside “Highlight Region” and “Show Border” (see
figure on right) and click OK.

By: Engr. Rizza P. Gamalinda P a g e 6 | 26


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

▪ DEFINITIONS AND VARIABLES

Mathcad’s power and versatility quickly become apparent once you begin to
use variables and functions. By defining variables and functions, you can link
equations together and use intermediate
results in further calculations regions.

DIFFERENT EQUAL SIGNS (5)

1. EVALUATION OPERATOR (=)

Returns the numerical evaluation of an input data as a result on the right-hand


side.

You cannot directly edit what appears to the right of the [=]. You can, however,
change the format or units in which the numbers are displayed.

Figure 3-8. Equal sign for evaluation

By: Engr. Rizza P. Gamalinda P a g e 7 | 26


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

FORMATTING A RESULT

To change the default display of numerical and symbolic results in a worksheet


(see figure 3-9):

Figure 3-9. Working with Numerical and Symbolic Results

1. Go to Format Menu tab, select Result to display Result Format dialog


box, and choose your default settings.

2. To change the display of a particular result, click on the equation, and


follow the same steps.

3. To affect symbolic results, be sure to click the check box near "Apply to
symbolic results."

By: Engr. Rizza P. Gamalinda P a g e 8 | 26


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

2. DEFINITION OPERATOR (:=)

Evaluates the variables on the right side and assigns the result to the left side
(see figure 3-10).

The left side of the equation is any valid Mathcad variable or function name,
matrix of names, or subscripted variable name but never a numerical value. The
right side of the equation is any Mathcad expression that can be evaluated. If you
used an invalid let variable or function name on both sides, or suffers from other
syntax problems, you will see an appropriate error message. The Mathcad is also
configured to highlight the mistake in the equation to help the user re-check his
work.

Figure 3-10. Equal sign for definition

By: Engr. Rizza P. Gamalinda P a g e 9 | 26


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

3. SYMBOLIC SIGN OPERATOR (→)

The symbolic equal sign (→) evaluates expressions symbolically. It is a live


operator, meaning that if you make a change to the worksheet anywhere above
the expression (or to the left of it on the same line), Mathcad updates the result
automatically and uses previously defined functions and variables. You can use
the symbolic equal sign to evaluate expressions containing Mathcad operators,
including integrals, derivatives, matrix operations (and most matrix functions),
summations and products. See example for comparison of solution.

When you evaluate an expression with the symbolic equal sign, Mathcad
simplifies the result by performing arithmetic and combining like variables (see
example #4 on Figure 3-11).

1. 2.

3.

4.

Figure 3-11. Symbolic sign operator

From example #3 and Figure 3-12, both solutions gave us the same result.
Mathcad really helps the users to compress lengthy solution.

By: Engr. Rizza P. Gamalinda P a g e 10 | 26


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

Figure 3-12. Symbolic sign operator: Solution of Ex.2 based on Differential


Calculus

INSERTING A KEYWORD

To perform more complex symbolic operations, you can insert a keyword that
specifies the operation before the symbolic equal sign.

Suppose you want to factor the polynomial 𝒙𝟐 − 𝟒𝒙 + 𝟒: (see Scenario 1 on


Figure 3-13) To do so, type the polynomial and insert the keyword "factor" as
follows:

1. Click anywhere in the expression for the polynomial.

2. Press Ctrl + Shift + . to insert a placeholder (see figure 3-8) for the keyword,
followed by the symbolic equal sign.

3. Type the keyword "factor" in the placeholder.

4. Press Enter or click outside the region.

By: Engr. Rizza P. Gamalinda P a g e 11 | 26


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

SUPPRESSING ASSIGNED VALUE

You can use "explicit" to force Mathcad to temporarily ignore the assigned value
of a variable. For example in Scenario 4, suppose you have previously assigned
x the value 4 and then try to factor the polynomial 𝒙𝟐 − 𝟒𝒙 + 𝟒: (see Scenario 2)

Figure 3-13. Other functions perform by Symbolic sign operator

Mathcad first substitutes 4 for x in the polynomial to get 4 as a result, and then
factors 4 over the integers to get 𝟐𝟐 .

If instead you want to factor the polynomial without substituting assigned value x
= 5, use the keyword "explicit" before "factor" to suppress the value of x in a
single symbolic evaluation, as shown in the Scenario 4:

By: Engr. Rizza P. Gamalinda P a g e 12 | 26


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

The following lists the keywords and the operations they perform (see
Symbolic Tab in figure 3-3):

KEYWORDS OPERATIONS

assume Make assumptions about the domain of the variables.

coeffs Return the coefficients of a polynomial.

collect Collect terms containing like powers of a variable.

Combine terms in an expression using properties of


combine
elementary functions.

Calculate the continued fraction expansion of a number or


confrac
function.

expand Multiply powers and products from an expression.

Return expressions with the values of variables substituted


explicit
in place, but without reducing numerical expressions.

factor Factor an expression.

Return results with available numeric values reduced using


float
floating point calculations to the specified precision.

Expand a rational expression into a sum of fractions with


parfrac
linear or quadratic denominators.

Return results involving complex numbers separated into


rectangular
real and imaginary parts.

rewrite Rewrite expressions in terms of elementary functions.

Expand a function or expression in a Taylor or Laurent


series
series around 0.

simplify Algebraically simplify or evaluate an expression.

solve Solve an equation symbolically.

Replace all occurrences of a variable with another variable,


substitute
an expression, or a number.

transforms:
Fourier, Evaluate the transform or inverse transform of a function.
Laplace, and Z

By: Engr. Rizza P. Gamalinda P a g e 13 | 26


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

4. GLOBAL DEFINITION OPERATOR (≡)

Global definition operator is configured to return a globally defined variable


regardless of placement in the worksheet. Global definitions supersede other
worksheet evaluations or definitions.

Global definitions work exactly like local definitions except that they are
evaluated before any local definitions. If you define a variable or function with a
global definition, that variable or function is available to all local definitions in your
worksheet, regardless of whether the local definition appears above or below the
global definition.

In Mathcad, a variable can be globally defined only once in a worksheet. You


cannot redefine a variable, either with a normal definition or a global definition
operator, if it has already been once defined globally otherwise the math region
containing the redefinition will error.

Figure 3-14. Global definition operator.

By: Engr. Rizza P. Gamalinda P a g e 14 | 26


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

5. LOCAL ASSIGNMENT OPERATOR (←)

y←x

Evaluates x numerically and assigns its contents to y. Variables and


functions defined with this operator are only defined locally within the current
definition (see figure 3-15) and within a program (see figure 3-16). Returns the
value of the left-hand-side (see figure 3-15 & 3-16), for example.

From the function of local assignment operator, x is any valid Mathcad


expression while y is any valid Mathcad name for a variable or function.

Local variables or functions defined with this operator may be assigned to


values from the worksheet.

Figure 3-15. Local Assignment operator used on a worksheet.

For example, it is possible to define best := 100, satisfactory := 90,


good := 75, passing := 60 and failure := 59 in your worksheet, then define
a local variable A, B, C, D, and E by local assignment operator (←) together
with a chosen local variable/name on the right side after the operator on a
worksheet or inside a program will return the declared numerical values
assigned on your normal definition operator.

By: Engr. Rizza P. Gamalinda P a g e 15 | 26


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

AVERAGE GRADE
99-100 1.00
95-98 1.25
90-94 1.50
85-89 1.75
80-84 2.00
75-79 2.25
70-74 2.50
65-69 2.75
60-64 3.00
Below 60 5.00

Another example, the local assignment operator may also be used within a
program. Figure 3-16 shows that when input numerical values of “x”
satisfies one of the listed condition, the program is configured to return a
corresponding result with the use of local assignment operator (←).

Figure 3-16. Local assignment operator used within a program.

By: Engr. Rizza P. Gamalinda P a g e 16 | 26


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

▪ MATRICES

A matrix is defined as a rectangular array of quantities arranged in rows and


n columns. The size or order of a matrix is measured by its number of rows and
columns. Often, m is used to refer for the number of rows while n is for columns.

Normally, to know the value of an a11 a12 a13 .. a1n


element (particular location in a21 a22 a23 .. a2n
terms of row and column number), A= a31 a32 a33 .. a3n
we designate the 1st row and : : : :
column as row number 1 and am1 am2 am3 .. amn
column number 1, respectively.

But, in Mathcad, this the 1st row A00 A01 A02 .. A0n
and column are configured to be A10 A11 A12 .. A1n
row number 0 and column number A= A20 A21 A22 .. A2n
0. In that sense, the only : : : :
difference is that the counting will am0 am1 am2 .. amn
simply start from 0 and not 1
(see matrix beside).

Figure 3-17. Matrix

In figure 3-17, to find the specific elements Q00, Q11, and Q11 we have to
use the (option 1) Matrix Toolbar for the subscript or the (option 2)
subscript button of the standard toolbar found the right side, then the equal
sign and enter. Know that the 1st value corresponds to element Q00.

By: Engr. Rizza P. Gamalinda P a g e 17 | 26


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

▪ DEFINING A RANGE VARIABLE

Iterative processes in Mathcad worksheets depend on range variables.

To define a range variable:


1. Type the name of the variable followed by a colon (:) to create a definition.
2. In the placeholder, type the first number in the sequence of values.
3. Type a comma, or, if you're defining a sequence in increments of one, go to
step 5.
4. Type the second number in the sequence.
5. Type a semicolon [;]. Note that it appears as two dots ".."
6. In the remaining placeholder, type the last number in the sequence.

1 .. 20 gives the range 1,2,3,4 … 20


20 .. 1 gives the range 20,19,18 … 1
1,1.1 .. 5 gives the range 1,1.1,1.2 … 5
5,3 … -7 gives the range 5,3,1,-1 … -7

▪ 2-DIMENSIONAL PLOTTING

To visually represent a function or expression of a single variable or vectors of


data in Mathcad, you can create either a Cartesian X-Y plot or a polar plot.

Figure 3-18. Example 1 of graph of 2-Dimensional Plotting

By: Engr. Rizza P. Gamalinda P a g e 18 | 26


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

A typical polar plot shows angular values, θ, versus radial values, r. Figure 3-
18 shows several examples of 2D plots.

CREATING AN X-Y PLOT

To create an X-Y plot:

1. Define a range variable (see explanation form previous topic) for the range
of values over which to plot the expression, for example: a := 5, 3 .. -7, if
not listed, the Mathcad will define all values that can be plotted (see
example below).

2. From the Insert menu, click Graph > X-Y Plot, or type @ for its shortcut
key, to create an x-y plot operator.

3. In the middle placeholder along the x-axis (horizontal axis), enter the
range variable.

Figure 3-19. Alternate solution for the graph of the example 2-Dimensional Plotting using
Differential Calculus

Sketch the curve.


𝒚 = (𝟐𝒙 − 𝟏)𝟑 𝒂𝒕 𝒙 = 𝟏

1. Find the points of intersection with the axes.


1.1 𝑥 − 𝑖𝑛𝑡𝑒𝑟𝑐𝑒𝑝𝑡 (𝑤ℎ𝑒𝑛 𝒚 = 𝟎)
1
[0 = (2𝑥 − 1)3 ]3

By: Engr. Rizza P. Gamalinda P a g e 19 | 26


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

1
2𝑥 − 1 = 0; 𝑥 =
2
𝟏
𝒙 − 𝒊𝒏𝒕𝒆𝒓𝒄𝒆𝒑𝒕 ( , 𝟎)
𝟐

1.2 𝑦 − 𝑖𝑛𝑡𝑒𝑟𝑐𝑒𝑝𝑡 (𝑤ℎ𝑒𝑛 𝒙 = 𝟎)


𝑦 = (2(0) − 1)3 = −1
𝒚 − 𝒊𝒏𝒕𝒆𝒓𝒄𝒆𝒑𝒕 (𝟎, −𝟏)

2. Determine the behavior of 𝒚 for large values of 𝒙.


𝒘𝒉𝒆𝒏 𝒙 → +∞ 𝑠𝑎𝑦 1,000; 𝑦 = (2(1000) − 1)3
𝒚 → +∞

𝒘𝒉𝒆𝒏 𝒙 → −∞ 𝑠𝑎𝑦 − 1,000; 𝑦 = (2(−1000) − 1)3


𝒚 → −∞

∴ (+∞, +∞) 𝐐𝐔𝐀𝐃𝐑𝐀𝐍𝐓 𝐈 𝒂𝒏𝒅 (−∞, −∞) 𝐐𝐔𝐀𝐃𝐑𝐀𝐍𝐓 𝐈𝐈𝐈

3. Locate the points where 𝒚′ = 𝟎 and determine the maxima and minima.

3.1 Differentiate
𝑦′ = 𝟑(2𝑥 − 1)𝟑−𝟏 (𝟐)
𝒚′ = 𝟔(𝟐𝒙 − 𝟏)𝟐

3.2 Set 𝑦 ′ = 0 𝑎𝑛𝑑 𝑠𝑖𝑚𝑝𝑙𝑖𝑓𝑦


0 = 6(2𝑥 − 1)2 1
→ [0 = (2𝑥 − 1)2 ]2
6
𝟎 = 𝟐𝒙 − 𝟏

3.3 Solve the roots using applicable solution


0 = 2𝑥 − 1
𝟏
2𝑥 = 1 = 0; 𝒙 =
𝟐

3.4 Solve for the Critical Points, CP. Substitute the roots in the given
function.
3
1 𝟏
𝑦 = [2 ( ) − 1] = 𝟎; 𝑪𝑷 ( , 𝟎)
2 𝟐

3.5 Determine the maxima and minima

by 𝟏𝒔𝒕 𝐃𝐄𝐑𝐈𝐕𝐀𝐓𝐈𝐕𝐄 𝐓𝐄𝐒𝐓


Substitute a lower and higher neighbor value to the x-coordinate of CP.
𝟏
@𝑪𝑷 ( , 𝟎)
𝟐
𝑡𝑟𝑦 𝒙𝒍𝒐𝒘𝒆𝒓 = 𝟎 𝑎𝑛𝑑 𝒙𝒉𝒊𝒈𝒉𝒆𝒓 = 𝟏
𝑦 ′ = 6[2(0) − 1]2 = +6
𝑦 ′ = 6[2(1) − 1]2 = +6
if y′ does 𝐧𝐨𝐭 change sign ,
y coordinate is a 𝐧𝐞𝐢𝐭𝐡𝐞𝐫 maximum or minimum

4. Locate the points where 𝒚′′ = 𝟎 (𝒑𝒐𝒊𝒏𝒕𝒔 𝒐𝒇 𝒊𝒏𝒇𝒍𝒆𝒄𝒕𝒊𝒐𝒏, 𝒊𝒏 𝒎𝒐𝒔𝒕 𝒄𝒂𝒔𝒆𝒔) and
draw the tangent at each of those points.

4.1 Differentiate

By: Engr. Rizza P. Gamalinda P a g e 20 | 26


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

𝑦′ = 6(2𝑥 − 1)2
𝑦 ′′ = 6(𝟐)(2𝑥 − 1)𝟐−𝟏 (𝟐)
𝒚′′ = 𝟐𝟒(𝟐𝒙 − 𝟏)

4.2 Set 𝑦 ′′ = 0 𝑎𝑛𝑑 𝑠𝑖𝑚𝑝𝑙𝑖𝑓𝑦


0 = 24(2𝑥 − 1)
→ 𝟎 = 𝟐𝒙 − 𝟏
24

4.3 Solve the roots using applicable solution


𝟏
2𝑥 = 1; 𝒙 =
𝟐

4.4 Solve for the Points of Inflection. Substitute the roots in the given
function.
3
1 𝟏
𝑦 = [2 ( ) − 1] = 0; 𝑷𝑶𝑰 ( , 𝟎)
2 𝟐

4.5 Concavity
by 𝟐𝒏𝒅 𝐃𝐄𝐑𝐈𝐕𝐀𝐓𝐈𝐕𝐄 𝐓𝐄𝐒𝐓
Substitute CP in𝑦′′.
𝟏
@𝑪𝑷 ( , 𝟎)
𝟐
1
𝑦 ′′ = 24 [2 ( ) − 1] = 0
2
if y ′′ = 0, , the test fails
It says 𝒏𝒐𝒕𝒉𝒊𝒏𝒈 about the concavity.

5. If necessary, plot a few additional points.


𝒚 = (𝟐𝒙 − 𝟏)𝟑

𝒙𝒊 𝒚𝒊 𝑪𝑷 𝑷𝑶𝑰 𝑨𝑫𝑫𝑰𝑻𝑰𝑶𝑵𝑨𝑳 𝑷𝑶𝑰𝑵𝑻𝑺

1 1 1 1 5
𝒙 0 1 − 𝑜𝑟 − 0.25 𝑜𝑟 1.25
2 2 2 4 4
27 27
𝒚 0 −1 0 0 1 − 𝑜𝑟 − 3.38 𝑜𝑟 3.38
8 8

By: Engr. Rizza P. Gamalinda P a g e 21 | 26


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

Figure 3-20. Example 2 of graph of 2-Dimensional Plotting

Example 2: Find the equations of the tangent and the normal at the point
indicated. Sketch the curve.
𝟏 𝟏 𝟏 𝟏𝟏
𝒚 = 𝒙𝟑 − 𝒙𝟐 − 𝟐𝒙 + 𝟐 𝒂𝒕 ( , )
𝟑 𝟐 𝟐 𝟏𝟐

1 1
𝑦′ = (𝟑𝑥 𝟑−𝟏 ) − (𝟐𝑥 𝟐−𝟏 ) − 2𝑥 𝟏−𝟏 + 0
3 2
𝒚′ = 𝒙 𝟐 − 𝒙 − 𝟐

1 2 1
𝑚 = 𝑦′ = ( ) − ( ) − 2
2 2
−𝟗
∴𝒎= = 𝒎𝑻𝑳
𝟒

By: Engr. Rizza P. Gamalinda P a g e 22 | 26


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

𝑚𝑁𝐿 = 𝑁𝐸𝐺𝐴𝑇𝐼𝑉𝐸 𝑅𝐸𝐶𝐼𝑃𝑅𝑂𝐶𝐴𝐿 𝑂𝐹 𝑇𝐻𝐸 𝑆𝐿𝑂𝑃𝐸


𝟒
∴ 𝒎𝑵𝑳 =
𝟗

• Equation of the tangent line • Equation of the normal line


𝑦 − 𝑦1 = 𝑚TL (𝑥 − 𝑥1 ) 𝑦 − 𝑦1 = 𝑚NL (𝑥 − 𝑥1 )
𝟏𝟏 −𝟗 𝟏 𝟏𝟏 𝟒 𝟏
𝑦− = (𝑥 − ) 𝑦− = (𝑥 − )
𝟏𝟐 𝟒 𝟐 𝟏𝟐 𝟗 𝟐
11 −9 9 11 4 4
[𝑦 − = 𝑥 + ] (𝟐𝟒) [𝑦 − = 𝑥 − ] (𝟏𝟎𝟖)
12 4 8 12 9 18
24𝑦 − 22 = −54𝑥 + 27 108𝑦 − 99 = 48𝑥 − 24
∴ 𝟓𝟒𝒙 + 𝟐𝟒𝒚 − 𝟒𝟗 = 𝟎 ∴ 𝟒𝟖𝒙 − 𝟏𝟎𝟖𝒚 + 𝟕𝟓 = 𝟎

1. Find the points of intersection with the axes.


1.1 𝑥 − 𝑖𝑛𝑡𝑒𝑟𝑐𝑒𝑝𝑡 (𝑤ℎ𝑒𝑛 𝒚 = 𝟎)
𝑖𝑟𝑟𝑎𝑡𝑖𝑜𝑛𝑎𝑙, 𝑤𝑒 𝑐𝑎𝑛 𝑠𝑘𝑖𝑝 𝑡ℎ𝑖𝑠 𝑝𝑎𝑟𝑡 𝑖𝑓 𝑖𝑡 𝑖𝑠 𝑐𝑜𝑚𝑝𝑙𝑒𝑥 𝑡𝑜 𝑠𝑜𝑙𝑣𝑒

1.2 𝑦 − 𝑖𝑛𝑡𝑒𝑟𝑐𝑒𝑝𝑡 (𝑤ℎ𝑒𝑛 𝒙 = 𝟎)


1 1
𝑦 = (0)3 − (0)2 − 2(0) + 2 = 𝟐
3 2
𝒚 − 𝒊𝒏𝒕𝒆𝒓𝒄𝒆𝒑𝒕 (𝟎, 𝟐)

2. Determine the behavior of 𝒚 for large values of 𝒙.


1 1
𝒘𝒉𝒆𝒏 𝒙 → +∞ 𝑠𝑎𝑦 1,000; 𝑦 = (1000)3 − (1000)2 − 2(1000) + 2
3 2
𝒚 → +∞

1 1
𝒘𝒉𝒆𝒏 𝒙 → −∞ 𝑠𝑎𝑦 − 1,000; 𝑦 = (−1000)3 − (−1000)2 − 2(−1000) + 2
3 2
𝒚 → −∞

∴ (+∞, +∞) 𝐐𝐔𝐀𝐃𝐑𝐀𝐍𝐓 𝐈 𝒂𝒏𝒅 (−∞, −∞) 𝐐𝐔𝐀𝐃𝐑𝐀𝐍𝐓 𝐈𝐈𝐈

3. Locate the points where 𝒚′ = 𝟎 and determine the maxima and minima.

3.1 Differentiate
1 1
𝑦′ = (𝟑𝑥 𝟑−𝟏 ) − (𝟐𝑥 𝟐−𝟏 ) − 2𝑥 𝟏−𝟏 + 0
3 2
𝒚′ = 𝒙𝟐 − 𝒙 − 𝟐

3.2 Set 𝑦 ′ = 0 𝑎𝑛𝑑 𝑠𝑖𝑚𝑝𝑙𝑖𝑓𝑦


𝟎 = 𝒙𝟐 − 𝒙 − 𝟐

3.3 Solve the roots using applicable solution


(𝑥 + 1)(𝑥 − 2) = 0
𝑥 + 1 = 0; 𝒙 = −𝟏
𝑥 − 2 = 0; 𝒙 = 𝟐

3.4 Solve for the Critical Points, CP. Substitute the roots in the given function.
1 1 𝟏𝟗 𝟏𝟗
𝑦 = (−1)3 − (−1)2 − 2(−1) + 2 = ; 𝑪𝑷𝟏 (−𝟏, )
3 2 𝟔 𝟔
1 1 −𝟒 −𝟒
𝑦 = (2)3 − (2)2 − 2(2) + 2 = ; 𝑪𝑷𝟐 (𝟐, )
3 2 𝟑 𝟑

By: Engr. Rizza P. Gamalinda P a g e 23 | 26


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

3.5 Determine the maxima and minima


by 𝟏𝒔𝒕 𝐃𝐄𝐑𝐈𝐕𝐀𝐓𝐈𝐕𝐄 𝐓𝐄𝐒𝐓
Substitute a lower and higher neighbor value to the x-coordinate of CP.

𝟏𝟗
@𝑪𝑷𝟏 (−𝟏, )
𝟔
𝑡𝑟𝑦 𝒙𝒍𝒐𝒘𝒆𝒓 = −𝟐 𝑎𝑛𝑑 𝒙𝒉𝒊𝒈𝒉𝒆𝒓 = 𝟎
𝑦 ′ = (−2)2 − (−2) − 2 = +4
𝑦 ′ = (0)2 − (0) − 2 = −2

if y′ changes from (+) to (−), y coordinate is a 𝐦𝐚𝐱𝐢𝐦𝐚

−𝟒
@ 𝑪𝑷𝟐 (𝟐, )
𝟑
𝑡𝑟𝑦 𝒙𝒍𝒐𝒘𝒆𝒓 = 𝟏 𝑎𝑛𝑑 𝒙𝒉𝒊𝒈𝒉𝒆𝒓 = 𝟑
𝑦 ′ = (1)2 − (1) − 2 = −2
𝑦 ′ = (3)2 − (3) − 2 = +4

if y′ changes from (−) to (+), y coordinate is a 𝐦𝐢𝐧𝐢𝐦𝐚

4. Locate the points where 𝒚′′ = 𝟎 (𝒑𝒐𝒊𝒏𝒕𝒔 𝒐𝒇 𝒊𝒏𝒇𝒍𝒆𝒄𝒕𝒊𝒐𝒏, 𝒊𝒏 𝒎𝒐𝒔𝒕 𝒄𝒂𝒔𝒆𝒔) and
draw the tangent at each of those points.
4.1 Differentiate
𝑦′ = 𝑥 2 − 𝑥 − 2
𝑦′′ = 𝟐𝑥 𝟐−𝟏 − 𝑥 𝟏−𝟏 − 0
𝒚′′ = 𝟐𝒙 − 𝟏

4.2 Set 𝑦 ′′ = 0
𝟎 = 𝟐𝒙 − 𝟏

4.3 Solve the roots using applicable solution


0 = 2𝑥 − 1
1
𝑥=
2

4.4 Solve for the Points of Inflection. Substitute the roots in the given
function.
1 1 3 1 1 2 1 𝟏𝟏 𝟏 𝟏𝟏
𝑦 = ( ) − ( ) − 2( ) + 2 = ; 𝑷𝑶𝑰 ( , )
3 2 2 2 2 𝟏𝟐 𝟐 𝟏𝟐

4.5 Concavity
by 𝟐𝒏𝒅 𝐃𝐄𝐑𝐈𝐕𝐀𝐓𝐈𝐕𝐄 𝐓𝐄𝐒𝐓
Substitute CP in𝑦′′.
𝟏𝟗
@𝑪𝑷𝟏 (−𝟏, )
𝟔
𝑦 ′′ = 2(−1) − 1 = −3

if y′′ < 0, y coordinate is a 𝐦𝐚𝐱𝐢𝐦𝐮𝐦


The curve is 𝐂𝐎𝐍𝐂𝐀𝐕𝐄 𝐃𝐎𝐖𝐍𝐖𝐀𝐑𝐃.

−𝟒
@ 𝑪𝑷𝟐 (𝟐, )
𝟑
𝑦 ′′ = 2(2) − 1 = 3

if y′′ > 0, y coordinate is a 𝐦𝐢𝐧𝐢𝐦𝐮𝐦


The curve is 𝐂𝐎𝐍𝐂𝐀𝐕𝐄 𝐔𝐏𝐖𝐀𝐑𝐃.

By: Engr. Rizza P. Gamalinda P a g e 1 | 26


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

5. If necessary, plot a few additional points.

𝟏 𝟑 𝟏 𝟐
𝒚= 𝒙 − 𝒙 − 𝟐𝒙 + 𝟐
𝟑 𝟐

𝒚𝒊 𝑪𝑷𝟏 𝑪𝑷𝟐 𝑷𝑶𝑰 𝑨𝑫𝑫𝑰𝑻𝑰𝑶𝑵𝑨𝑳 𝑷𝑶𝑰𝑵𝑻𝑺

1
𝒙 0 −1 2 1 −2 −2.75 2.75
2
19 −4 11 −1 4
𝒚 2 −3.21 −0.35
6 3 12 6 3

Figure 3-21. Alternate solution for the graph of the example 2-Dimensional Plotting using
Differential Calculus

By: Engr. Rizza P. Gamalinda P a g e 2 | 26


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

▪ OVERVIEW OF UNITS AND DIMENSIONS

Mathcad provides a complete set of units in the SI (International System of Units),


CGS (Centimeter–Gram–Second), US (United States Customary System), and
MKS (Meter–Kilogram–Second) unit systems. You can multiply values by these
built-in units or by your own custom-defined units. Mathcad checks your worksheet
for dimensional consistency and automatically displays results in terms of the
appropriate units for the chosen unit system. The default unit system is SI
(International System of Units).

Click Insert Menu Tab and select (option 1) Unit to display Insert Unit Dialogue
box and see a list of currently available units or click its shortcut key Ctrl + U on
the keypad (see figure 3-22).

Figure 3-22. Units and Dimensions

By: Engr. Rizza P. Gamalinda P a g e 3 | 26


14.0

MODULE 4
Introduction to Mathcad
(Mathcad Programming)

By: Engr. Rizza P. Gamalinda


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

MODULE 4: MathCad Programming

▪ WHAT IS MATHCAD PROGRAMMING?


Programming is the process of writing instructions that get executed by
computers. These instructions are written in a programming language in which
the computer can comprehend and use to perform a certain task or even solve
a problem.

It is a great way to reduce the work and time necessary when a mathematical
process has to be
performed multiple times in a worksheet.

▪ SOME USEFUL COMMANDS or SHORTCUT KEYS


Working with Mathcad worksheet may take couple of times. To speed up your
work and make it more convenient, you can use the number of keyboard
shortcut list down below.

SHORTCUT DESCRIPTION
KEYS

Ctrl + A Its use is to select or highlight all contents of a worksheet.

Ctrl + C It is used to copy the selected content of a worksheet.

It offers the option to open find dialog box quickly. You can
Ctrl + F
also use Shift + F5 for it.

It allows you to find and replace the word or sentences in


a file. For example, if by mistake you have written a
Ctrl + H
computer instead of the computer at many places in your
sheet, you can replace it with the computer in one go.

Ctrl + J It is use is to insert page break.

Ctrl + N Its use is to open the new document or a workbook.

It offers users the option to open the dialog box where you
Ctrl + O
can choose a file that you want to open.

Ctrl + P It allows you to print a current sheet or a document quickly.

Ctrl + R It allows you to refresh the active worksheet.

Ctrl + S Its use is to save the document.

It offers users the option to display the create table dialog


Ctrl + T
box and insert picture.

Ctrl + U It is used to display Unit and Dimension dialogue box

By: Engr. Rizza P. Gamalinda P a g e 1 | 25


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

It provides users the option to paste the copied data. You


Ctrl + V are required to copy the data once, and then you can paste
it any number of times.

It is used to close the currently open document or a file


Ctrl + W quickly. It can also be done by pressing Ctrl + F4 shortcut
keys.

Ctrl + X It allows users the option to cut the entire data.

Ctrl + Y It provides users the option to redo any undo contents.

It is used to undo (get back) the deleted item. For example,


Ctrl + Z if you have deleted the data by mistake, you can press Ctrl
+ Z to retrieve the deleted data.

F1 It is used to open the MathCad help screen window.

It is used to display Context sensitive Help with the


Shift + F1
cursor.

F4 It provides users the option to repeat the last action.

F9 The function key F19 is used to calculate the region.

Ctrl + F9 The function key F19 is used to calculate the worksheet.

The function key F10 is used to activate the menu bar


then press the first letter of any of the menu bar. For
F10
example, if you want to open the file menu, you need to
press F10, then F or F10, then E for edit menu.

CALCULATOR
TOOLBAR

= To evaluate numerically

/ Division

Shift + / ÷ means in line division

\ To insert square root

Shift + \ | means Absolute value

Ctrl + \ To insert nth root

‘ To insert parenthesis

1 + i + Enter Imaginary unit

Shift + 6 ^ means exponentiation

Shift + 8 * means multiplication

Shift + ; : means Definition

Ctrl + Shift + = To insert Mixed Number

By: Engr. Rizza P. Gamalinda P a g e 2 | 25


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

Ctrl + Shift + P To insert pi, 𝜋

BOOLEAN
TOOLBAR

Ctrl + ! or Ctrl +
¬ Boolean NOT
Shift + 1

Ctrl + % or Ctrl +
⊕ Boolean XOR
Shift + 5

Ctrl + ^ or Ctrl +
v Boolean OR 
Shift + 6

Ctrl + & or Ctrl +


^ Boolean AND
Shift + 7

Ctrl + = = Boolean equals

Ctrl + 0 ≤ Greater than or equal

Ctrl + 3 ≠ Not equal

Ctrl + 9 ≥ Less than or equal

CALCULUS
TOOLBAR

d
? f(x) Derivative
dx

Ctrl + ? or Ctrl + 𝑑𝑛
f(x) Derivative
Shift + / 𝑑𝑥 𝑛

Ctrl + I ∫ f(x, y) Indefinite integral

b
& or Shift + & ∫a f(x)dx Definite integral

Ctrl + = = Boolean equals

Ctrl + 0 ≤ Greater than or equal

Ctrl + 3 ≠ Not equal

Ctrl + 9 ≥ Less than or equal

Ctrl + Shift + Z ∞ Infinity

Ctrl + # or Ctrl +
Shift + 3

= Iterated product

# or Shift + 3 
Iterated product with range variables

By: Engr. Rizza P. Gamalinda P a g e 3 | 25


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

Ctrl + Shift + B lim f(x) Left hand limit


x→0−

sin (x)
Ctrl + L lim Two-sided limit
x→0 x

Ctrl + Shift + A lim f(x) Right hand limit


x→0+

n
Ctrl + $ or Ctrl +
∑ xi Summation
Shift + 4
i=1

$ or Shift + 4 ∑ xi Summation
𝑖=1

Ctrl + Shift + G ∇x g(x) Gradient

EVALUATION
TOOLBAR

Ctrl + Shift + X Custom postfix

Ctrl + Shift + ; := means Definition

= = means Evaluation

~ ≡ means Global Definition

Ctrl + . → means Evaluate symbolically

MATRIX
TOOLBAR

Ctrl + M It is used to display Matrix Dialogue box.

Ctrl + 1 Transpose

Ctrl + 4 Vector Sum

Ctrl + 6 Column

Ctrl + 8 Cross product

* or Ctrl + 8 Inner (dot) product

; Range variable

Shift + | | means determinant

Ctrl + - Vectorize

By: Engr. Rizza P. Gamalinda P a g e 4 | 25


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

PROGRAMMING
TOOLBAR

] Add line

Ctrl + { or Ctrl + Break


Shift + [

Ctrl + [ Continue

Ctrl + “ or Ctrl +
For
Shift + ‘

} or Ctrl + Shift + If
]

{ or Ctrl + [ Local Assignment

Ctrl + ‘ On error

Ctrl + } or Ctrl + Otherwise


Shift + ]

Ctrl + | or Ctrl + Return


Shift + \

Ctrl + ] While

SYMBOLIC
TOOLBAR

Ctrl + . Evaluate symbolically

Ctrl + > Symbolic evaluation with keywords

DISCLAIMER. The sample Mathcad images in this module are to provide the
reader with examples of how Mathcad may be used in calculation from simple to
complex problems. Before using the worksheet in this module, the reader should
understand the operations and functions of the Mathcad application and carefully
verify that the application (1) are applicable to his or her problem situation and (2)
produce an acceptable answer. The reader assumes all risks from the use and/or
performance of these application.

By: Engr. Rizza P. Gamalinda P a g e 5 | 25


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

PROGRAMMING OPERATORS OF MATHCAD

Mathcad program is created by using its program operators. Mathcad 14 has 10


operators which are accessible from Program toolbar.

Figure 4-1. Programming operators.

1. add line – It is an operator to initiate a program or add a line to a program.


When it is click on the programming toolbar, a vertical bar and 2 placeholders
will be produced. │■
│■

2. ■ ← ■ – It is known as the Local assignment operator which define left holder


by the input
data on the right holder of arrow

3. ■ if ■ – It is a conditional operator which can be used whenever you want a


program statement to be executed only upon the occurrence of some
condition.

4. ■ otherwise - It is a conditional operator which can be used together with "if"


operator when you want a program to execute a statement when the condition
of "if" operator is false.

5. for ■ 𝝐 ■ - It is a looping operator which can be used when you know how many
times you want a
program statement to be executed repeatedly.

6. while ■ - It is a looping operator which can be used when you want to stop
execution of a statement
■ upon the occurrence of a condition but don't know exactly when the
condition will occur.

7. break – It is a control operator which can be used when you want to break out
of a loop upon the occurrence of some condition and which moves execution
to next statement outside the loop.

By: Engr. Rizza P. Gamalinda P a g e 6 | 25


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

8. continue - It is a control operator which can be used when you want to halt
current iteration of a loop upon the occurrence of a condition and force program
to continue next iteration of a loop.

9. return ■ - It is a control operator which can be used anywhere in a program


when you want to interrupt a program and to return a value different from the
value of last expression of a program.

10. ■ on error ■ - It is an operator for error control which can be used to return an
alternative value when an error happened in an expression

TRUNCATION AND ROUNDING FUNCTIONS

1. floor(z) Returns the greatest integer ≤ z.


2. Floor(z, y) Returns the greatest multiple of y ≤ z.

3. ceil(z) Returns the smallest integer ≥ z.


4. Ceil(z, y) Returns the smallest multiple of y ≥ z.

5. round(z, [n]) Returns z rounded to n decimal places. If n is omitted, returns


z rounded to the nearest integer (n is assumed to be zero). If n < 0, returns
z rounded to n places to the left of the decimal point. If the (n + 1)th decimal
place is less than 5, the number is rounded down, otherwise, it is rounded
up.
6. Round(z, y) Returns round(z / y) · y, which rounds z to the closest
multiple of y. Note that round(z, 1) = Round(z, 0.1).

7. trunc(z) Returns the integer part of z by removing the fractional part.


8. Trunc(z, y) Returns trunc(z / y) · y.

Where:
z is a real or complex scalar or vector. For the lowercase functions, z must
be dimensionless.

For the two-argument uppercase functions, z and y must have the


same dimensions.

y is a real, nonzero scalar or vector.

n is an integer.

SOME EXAMPLES OF PROGRAMMING

By default, programming operator add line is configured to produce a vertical bar


and 2 placeholders. Therefore, we have to manipulate the function by letting of
another any variable that will represent the ration of x to y, before coming up with
𝐱
the expression 𝐥𝐨𝐠 ( ), that is the function of z in the program (see figure 4-2).
𝐲

By: Engr. Rizza P. Gamalinda P a g e 7 | 25


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

Figure 4-2. Simple Programming in Mathcad.

Both program and synthetic calculator gave the same result for
Pair No. 1. Therefore, the program really worked.

FINDING THE COEFFICIENTS AND EXPONENTS OF A


POLYNOMIAL

To return the coefficients of a polynomial with respect to a particular variable, place


the cursor at the end of the polynomial and either:

Option 1: Press Ctrl + Shift + . and type the keyword "coeffs" in the placeholder
after the polynomial. Then, press Enter.

Option 2: Click “coeffs” on the Symbolic toolbar and type the polynomial
before the keyword. Then, press Enter.

Mathcad returns a vector containing the coefficients of the polynomial.


Mathcad returns the coefficients for the smallest exponent (constant) to the largest
(bearing the highest degree), in order, with zeros for any skipped exponents in the
expression.

By: Engr. Rizza P. Gamalinda P a g e 8 | 25


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

Figure 4-3. Using Mathcad to know the coefficients and degree (exponents).

To return a second column containing the exponents corresponding to each


coefficient, type the optional modifier "degree" after "coeffs" and a comma (see
2nd example on the right of figure 4-3).

FINDING THE COEFFICIENTS (IN TERMS OF EXPRESSION) OF A


POLYNOMIAL CONTAINING SEVERAL VARIABLES

If the polynomial contains more than one variable, type a comma after
"coeffs" followed by the variable with respect to which you want the coefficients
expressed. For an expression containing several variables, Mathcad internally
writes the expression as a polynomial in the variable you specify after "coeffs".
The coefficients are expressions involving the variables other than the one you
specify.

If the expression contains more than one variable, you must specify a
variable after "coeffs." Mathcad internally rewrites the expression as a polynomial
in that variable and returns a vector containing the coefficients of the polynomial.
For example,

Note that internally, Mathcad first rewrites the expression as a polynomial


in x. That is, it performs the same operation as the keyword "collect."

To collect terms of a polynomial containing like powers of a specified variable,


select the expression for the polynomial and either:

Option 1: Press Ctrl + Shift + . and type the keyword "collect" in the
placeholder after the polynomial. Then, press Enter.

Option 2: Click “collect” on the Symbolic toolbar and type the polynomial
before the keyword. Then, press Enter.

By: Engr. Rizza P. Gamalinda P a g e 9 | 25


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

Figure 4-4. Knowledge on ‘coeffs’ and ‘collect’

Mathcad adds the terms 5y2 + 3y, containing the term x2, and the terms 3x2
+ y, containing the term x. Furthermore, on the second program, Mathcad adds
the terms 5x2 + 7x, containing the term y2, and the terms 3x2 + x, containing the
term y. See figure 4-4 for example.

CONDITIONAL (IF and OTHERWISE) OPERATORS


Conditional statements allow Mathcad to execute or skip certain calculations. Use
a conditional statement whenever you want to direct program execution along a
particular branch.

IF
(Ctrl + Shift + [ or Ctrl + {)

OTHERWISE
(Ctrl + Shift + ] or Ctrl + })

designated variable(test variable) := true value if test variable satisfies


condition
false value otherwise

By: Engr. Rizza P. Gamalinda P a g e 10 | 25


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

Evaluates test variable with the if statement’s condition. When satisfied


by the input test variable, the program will return a true value otherwise a false
value will be the result. The otherwise operator only works with the if operator.

In the following example (see figure 4-5), the function returns true value 0
if absolute value of x is greater than 10 or less than −10. When x is between −10
and 10, the function returns the false value square root of x2.

Figure 4-5. Simple Programming

Another example (see figure 4-6), it is a program that may be used to solve
for the factorial of a number. Factorial (n) is programmed that if the input value for
variable n is 1, the program will return a result of 1, else, any other number will be
evaluated by the expression on the otherwise operator.

Figure 4-6. Simple Programming

By: Engr. Rizza P. Gamalinda P a g e 11 | 25


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

Know that the factorial of 3 is 1∙2∙3 = 6. With that, the program is checked.

LOCAL ASSIGNMENT OPERATOR IN A PROGRAM

Comprehensive explanation have been explained on Module 3. As further


explanation on this, we have figure 4-7.

Figure 4-7. Local Assignment Operator in a program.

Scenario 1: If the name of a local variable is the same as the worksheet


variable/name/function used to initialize it, it only takes the worksheet value the
first time it is assigned. Successive references to the same name, use the local
value rather than the global one.

For example, if the function y(x) := x + 1 is defined in your worksheet, and


you create a variable N ← y(2), all successive program references to the name “N”
use the local variable definition of 3, and no longer recognize it as a function name.
See figure 4-7.

Scenario 2: Additional to scenario 1, from concept of Global Definition Operator,


all values of variable u when defined by global definition will supersede all
preceding declared value (see last line of solution in scenario 2 on figure 4-7).
Contrary, on scenario 2, when you declared a numerical value for “u” (see 2nd line
of solution on figure 4-7), Mathcad is configured to evaluate that function with the
declared numerical and return its corresponding result.

By: Engr. Rizza P. Gamalinda P a g e 12 | 25


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

Figure 4-8. Local Assignment Operator in a program.

Scenario 3: With the same concept in Scenario 2, all defined values using a global
definition for variable k supersede all variables with the same name (see 3rd and
5th line of solution in scenario 3 on figure 4-8). But when you declared a numerical
value for “k” (see 4th and 6th line of solution on figure 4-8), Mathcad is configured
to evaluate that function with the declared numerical and return its corresponding
result.

MATRICES AND DETERMINANTS

▪ Addition and Subtraction

A matrix can only be added to (or subtracted from) another matrix if the two
matrices have the same dimensions. Say, MatA + MatB := [MatAij + MatBij]. See
figure 4-9 for example.

By: Engr. Rizza P. Gamalinda P a g e 13 | 25


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

Figure 4-9. Addition and Subtraction of Matrices.

▪ Multiplication

Figure 4-10. Multiplication of Matrices

By: Engr. Rizza P. Gamalinda P a g e 14 | 25


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

Finding the product of two matrices is only possible when the inner
dimensions are the same, meaning that the number of columns of the first
matrix is equal to the number of rows of the second matrix. See figure 4-10.

▪ Transpose of a Matrix

If A = [aij] is an m x n matrix, then the n x m matrix is AT = [aijT] where aijT =


aji is called the transpose of matrix A. See figure 4-11.

Figure 4-11. Transpose of Matrices.

▪ Determinant

A determinant is a scalar valued function whose domain is a set of square


matrices. It allows characterizing some properties of the matrix and the
linear map represented by the matrix. It is an element that identifies
or determines the nature of something or that fixes or conditions an
outcome.

a11 a12 a13 .. a1n


a21 a22 a23 .. a2n
A= a31 a32 a33 .. a3n
: : : :
am1 am2 am3 .. amn

By: Engr. Rizza P. Gamalinda P a g e 15 | 25


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

a11 a12 a13 .. a1n


a21 a22 a23 .. a2n
det A =│A│= a31 a32 a33 .. a3n
: : : :
am1 am2 am3 .. amn

For example,

1 −1 2
Find the determinant of given matrix A = [1 −2 3].
2 −2 1

Solution:
(-)
1 −1 2 𝟏 −𝟏
det A = │A│ = [1 −2 3] 𝟏 −𝟐
2 −2 1 𝟐 −𝟐
(+)
│A│ = (1 ∙ −2 ∙ 1) + (−1 ∙ 3 ∙ 2) + (2 ∙ 1 ∙ −2) − (2 ∙ −2 ∙ 2) − (−2 ∙ 3 ∙ 1)
− (1 ∙ 1 ∙ −1)

│A│ = −2 − 6 − 4 + 8 + 6 + 1

∴ │𝐀│ = 𝟑

See figure 4-12 for an alternative solution using the application and the topic’s
concept.

Figure 4-12. Determinant of a Matrix.

By: Engr. Rizza P. Gamalinda P a g e 16 | 25


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

From figure 4-12, we can see a simpler solution that eliminates the lengthy
solution for the computation of a determinant. It only needs the correct
arrangement of data that the application can comprehend with the help of right
use of operators.

We can also evaluate if the answer is correct if we will refer back to the concept
behind the solution of a 3 x 3 matrix. Another way to check the result is through
calculator technique but the limitation is that the given matrix size should be one
of the syntax saved in the calculator’s program (see figure 4-13).

Step 1: Click Mode, Step 2: Choose any Step 3: Choose size of Step 4: This will be
choose 6. matrix where to save matrix. The given matrix the setup of the
your data. Say choose size is 3x3. Therefore, calculator thereafter.
1. choose 1.

Step 5: Enter the Step 6: Click AC. The Step 7: Click Shift, 4, 7 Step 8: Click Shift, 3.
given data by data was already to perform and The number 3 pertains
typing the values stored in the calculate the to the matrix where
then click = key. calculator. determinant. you choose to store
your data at Step 2.
Click = to show the
result.

Figure 4-13. Calculator technique. Determinant of a Matrix.

By: Engr. Rizza P. Gamalinda P a g e 17 | 25


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

In linear algebra, the Rule of Sarrus is a mnemonic device for computing the
determinant of a 3 x 3 matrix named after the French mathematician Pierre
Frédéric Sarrus.

The determinant of the three columns on the


left is the sum of the products along the
down-right diagonals minus the sum of the
products along the up-right diagonals (see
figure 4-14a).

Figure 4-14a. Rule of Sarrus

Alternative vertical arrangement (see Figure


4-14b).

Figure 4-14b. Rule of Sarrus

Another way of thinking of Sarrus' rule is to


imagine that the matrix is wrapped around a
cylinder, such that the right and left edges
are joined (see Figure 4-14c).

Sarrus' rule can also be derived using the


Laplace expansion of a 3 x 3 matrix.

Figure 4-14c. Rule of Sarrus

▪ Minor and Cofactor of an Element

o The minor of the element a ij of a determinant size n is the


determinant of size n-1 obtained by deleting the ith row and jth
column of the original determinant. For example, │Mij│is the
minor of aij.

o The cofactor Cij of aij is defined as │Cij│= (-1)i+j│Mij│

Note that the sign of (−1)𝑖+𝑗 follows a checker board pattern.

By: Engr. Rizza P. Gamalinda P a g e 18 | 25


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

For example,
a11 a12 a13
A = [a21 a22 a23 ]
a31 a32 a33

𝑎 𝑎13
|M31 | = |𝑎12 𝑎23 | is the minor of a31.
22

𝑎12 𝑎13
C31 = (−1)3+1 |M31| → C31 = (−1)4 |𝑎 𝑎23 |
22
𝑎12 𝑎13
C31 = |𝑎 | is the cofactor of a 31.
22 𝑎23

▪ Laplace Expansion

If the elements of any row or of any column of a determinant are multiplied


by their respective cofactors and then added, the sum is the same for all
rows and for all columns. It is named after Pierre-Simon Laplace. It is
also called cofactor expansion.

For example,

1 2 −3 4
Find the determinant of given matrix A = [ −4 2 1 3 ].
3 0 0 −3
2 0 −2 3

Solution:

Option 1/8: Expand about the 1 st row.


𝑎22 𝑎23 𝑎24 𝑎21 𝑎23 𝑎24
|A| = (a11 )(−1)1+1 |𝑎32 𝑎33 𝑎34 | + (a12 )(−1)1+2 |𝑎31 𝑎33 𝑎34 |
𝑎42 𝑎43 𝑎44 𝑎41 𝑎43 𝑎44
𝑎21 𝑎22 𝑎24
+ (a13 )(−1)1+3 |𝑎31 𝑎32 𝑎34 |
𝑎41 𝑎42 𝑎44
𝑎21 𝑎22 𝑎23
+ (a14 )(−1)1+4 |𝑎31 𝑎32 𝑎33 |
𝑎41 𝑎42 𝑎43

2 1 3 2 1
|A| = (1)(−1)2 |0 0 −3| 0 0
0 −2 3 0 −2
−4 1 3 −4 1
+ (2)(−1)3 | 3 0 −3| 3 0
2 −2 3 2 −2
−4 2 3 −4 2
4
+ (−3)(−1) | 3 0 −3| 3 0
2 0 3 2 0
−4 2 1 −4 2
+ (4)(−1)5 | 3 0 0 | 3 0
2 0 −2 2 0

By: Engr. Rizza P. Gamalinda P a g e 19 | 25


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

|A| = (1)(1)(−12) + (2)(−1)(−9) + (−3)(1)(−30) + (4)(−1)(12)

∴ |𝐀| = 𝟒𝟖

Option 2/8: Expand about the 1 st column.


𝑎22 𝑎23 𝑎24 𝑎12 𝑎13 𝑎14
|A| = (a11 )(−1)1+1 |𝑎32 𝑎33 𝑎34 | + (a21 )(−1) 2+1 |𝑎32 𝑎33 𝑎34 |
𝑎42 𝑎43 𝑎44 𝑎42 𝑎43 𝑎44
𝑎12 𝑎13 𝑎14
+ (a31 )(−1)3+1 |𝑎22 𝑎23 𝑎24 |
𝑎42 𝑎43 𝑎44
𝑎12 𝑎13 𝑎14
+ (a14 )(−1)1+4 |𝑎22 𝑎23 𝑎24 |
𝑎32 𝑎33 𝑎34

2 1 3 2 1
|A| = (1)(−1)2 |0 0 −3| 0 0
0 −2 3 0 −2
2 −3 4 2 −3
( )( ) 3|
+ −4 −1 0 0 −3| 0 0
0 −2 3 0 −2
2 −3 4 2 −3
+ (3)(−1)4 |2 1 3| 2 1
0 −2 3 0 −2
2 −3 4 2 −3
5
+ (2)(−1) |2 1 3 |2 1
0 0 −3 0 0

|A| = (1)(1)(−12) + (−4)(−1)(−12) + (3)(1)(20) + (2)(−1)(−24)

∴ |𝐀| = 𝟒𝟖

Option 3/8: Expand about the 2 nd column.


𝑎21 𝑎23 𝑎24 𝑎11 𝑎13 𝑎14
|A| = (a12 )(−1)1+2 |𝑎31 𝑎33 𝑎34 | + (a22 )(−1)2+2 |𝑎31 𝑎33 𝑎34 |
𝑎41 𝑎43 𝑎44 𝑎41 𝑎43 𝑎44
𝑎11 𝑎13 𝑎14
+ (a32 )(−1)3+2 |𝑎21 𝑎23 𝑎24 |
𝑎41 𝑎43 𝑎44
𝑎11 𝑎13 𝑎14
+ (a42 )(−1) 4+2 |𝑎21 𝑎23 𝑎24 |
𝑎31 𝑎33 𝑎34

−4 1 3 −4 1
|A| = (2)(−1)3 | 3 0 −3| 3 0
2 −2 3 2 −2
1 −3 4 1 −3
( )( ) 4|
+ 2 −1 3 0 −3| 3 0
2 −2 3 2 −2
1 −3 4 1 −3
+ (0)(−1)5 |−4 1 3| −4 1
2 −2 3 2 −2
1 −3 4 1 −3
( )( ) 6|
+ 0 −1 −4 1 3 | −4 1
3 0 −3 3 0

By: Engr. Rizza P. Gamalinda P a g e 20 | 25


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

|A| = (2)(−1)(−9) + (2)(1)(15) + (0)(−1)(−21) + (0)(1)(−6)

∴ |𝐀| = 𝟒𝟖

See figure 4-15 for an alternative solution using the application and the topic’s
concept.

Figure 4-15. Determinant of a 4 x 4 Matrix.

From figure 4-15, we can see a simpler solution that eliminates the
lengthy solution for the computation of the determinant of a 4 x 4 matrix. It only
needs the correct arrangement of data that the application can comprehend with
the help of right use of operators.

We can also evaluate if the answer is correct if we will refer back to the concept
behind the solution of a 4 x 4 matrix.

▪ Adjoint of a Matrix

Let A = [aij] be an n x n matrix. The n x n matrix adj A (read as “adjoint of


A”) is the matrix whose ith and jth element is the cofactor of Aij of aij.
Thus,

A11 A12 … A1n


A A22 … A2n
adj A = [ 21 ]
⋮ ⋮ ⋱ ⋮
An1 An2 … Ann

For example,
1 −1 2
𝐴 = [1 −2 3]
2 −2 1

By: Engr. Rizza P. Gamalinda P a g e 21 | 25


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

−2 3
𝐴11 = (−1)1+1 | | = 1[(−2)(1) − (−2)(3)] =4
−2 1

1 3
𝐴12 = (−1)1+2 | | = −11[(1)(1) − (2)(3)] =5
2 1

1 −2
𝐴13 = (−1)1+3 | | = 1[(1)(−2) − (2)(−2)] =2
2 −2

−1 2
𝐴21 = (−1)2+1 | | = −11[(−1)(1) − (−2)(2)] = −3
−2 1

1 2
𝐴22 = (−1)2+2 | | = 1[(1)(1) − (2)(2)] = −3
2 1

1 −1
𝐴23 = (−1)2+3 | | = −1[(1)(−2) − (2)(−1)] = 0
2 −2

−1 2
𝐴31 = (−1)3+1 | | = 1[(−1)(3) − (−2)(2)] =1
−2 3

1 2
𝐴32 = (−1)3+2 | | = −1[(1)(3) − (1)(2)] = −1
1 3

1 −1
𝐴33 = (−1)3+3 | | = 1[(1)(−2) − (1)(−1)] = −1
1 −2

𝟒 −𝟑 𝟏
∴ 𝒂𝒅𝒋 𝑨 = [𝟓 −𝟑 −𝟏]
𝟐 𝟎 −𝟏

See figure 4-16.

▪ Inverse of a Matrix

If A is an n x n matrix and │A│≠ 0, then

A11 A12 A1n



|A| |A| |A|
1 A21 A22 A2n
A−1 = ∙ adj A = |A| …
|A| |A| |A|
⋮ ⋮ ⋱ ⋮
An1 An2 Ann

[ |A| |A| |A| ]

See figure 4-16.

By: Engr. Rizza P. Gamalinda P a g e 22 | 25


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

Figure 4-16. Adjoint and Inverse of a Matrix.

▪ Solution of Linear System (Systems of Linear Algebraic Expressions)

Given a linear system:


a11 𝑥1 + a12 𝑥2 + ⋯ + a1n 𝑥𝑛 = b1
a21 𝑥1 + a22 𝑥2 + ⋯ + a2n 𝑥𝑛 = b1
⋮ ⋮ ⋮ ⋮ ⋮
am1 𝑥1 + am2 𝑥2 + ⋯ + amn 𝑥𝑛 = bm

Maybe written as:

Let:
a11 a12 … a1n 𝑥1 𝑏1
a a22 … a2n 𝑥2 𝑏2
A = [ 21 ] 𝑥=[ ] B=[ ]
⋮ ⋮ ⋱ ⋮ ⋮ ⋮
am1 am2 … amn 𝑥3 𝑏𝑚

Where:
A – coefficient matrix
x – column matrix of unknown variables
B – constant values

By: Engr. Rizza P. Gamalinda P a g e 23 | 25


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

And,
B
A𝑥 = B 𝑥=A
𝒙 = 𝐀−𝟏 ∙ 𝐁

For example:
Find the values of the unknown variables in the linear systems as
shown (same example from Determinant).

𝑥 − 𝑦 + 2𝑧 = 0
𝑥 − 2𝑦 + 3𝑧 = −1
2𝑥 − 2𝑦 + 𝑧 = −3
Solution:
1 −1 2 𝑥 0
𝐴 = [1 −2 3] 𝑥 = [𝑦] 𝐵 = [−1]
2 −2 1 𝑧 −3

𝒙 = 𝐀−𝟏 ∙ 𝐁

−2 3
𝐴11 = (−1)1+1 | | = 1[(−2)(1) − (−2)(3)] =4
−2 1
1 3
𝐴12 = (−1)1+2 | | = −11[(1)(1) − (2)(3)] =5
2 1
1 −2
𝐴13 = (−1)1+3 | | = 1[(1)(−2) − (2)(−2)] =2
2 −2
−1 2
𝐴21 = (−1)2+1 | | = −11[(−1)(1) − (−2)(2)] = −3
−2 1
1 2
𝐴22 = (−1)2+2 | | = 1[(1)(1) − (2)(2)] = −3
2 1
1 −1
𝐴23 = (−1)2+3 | | = −1[(1)(−2) − (2)(−1)] = 0
2 −2
−1 2
𝐴31 = (−1)3+1 | | = 1[(−1)(3) − (−2)(2)] =1
−2 3
1 2
𝐴32 = (−1)3+2 | | = −1[(1)(3) − (1)(2)] = −1
1 3
1 −1
𝐴33 = (−1)3+3 | | = 1[(1)(−2) − (1)(−1)] = −1
1 −2
𝟒 −𝟑 𝟏
∴ 𝒂𝒅𝒋 𝑨 = [𝟓 −𝟑 −𝟏] and |𝑨 | = 𝟑
𝟐 𝟎 −𝟏
1
A−1 = ∙ 𝑎𝑑𝑗 𝐴
|𝐴 |

4 −3 1 4 1
−1
3 3 3 3 3
5 −3 −1 5 −1
A−1 = → A−1 = −1
3 3 3 3 3
2 0 −1 2 −1
[3 3 3] [3 0 3]

𝒙 = 𝐀−𝟏 ∙ 𝐁

4 1
−1
𝑥 3 3
5 −1 0
[𝑦 ] = −1 [−1]
𝑧 3 3 −3
2 −1
[3 0
3]

By: Engr. Rizza P. Gamalinda P a g e 24 | 25


CEP211L: Computer Fundamentals and Programming 2 (Laboratory)

4 1
( ) (0) + (−1)(−1) + ( ) (−3)
3 3
𝑥
5 1
[𝑦] = ( ) (0) + (−1)(−1) + (− ) (−3)
𝑧 3 3
2 1
( ) ( )( ) ( )
[ (3) 0 + 0 −1 + (− 3) −3 ]

𝑥 1−1 𝒙 𝟎
[𝑦] = [1 + 1] → ∴ [𝒚] = [𝟐]
𝑧 1 𝒛 𝟏

Therefore, the values for the unknown variables are x = 0, y = 2,


and z = 1. See Figure 4-17.

By using Mathcad, we can see the ease of solving for the values of
the unknown variables of a solution of linear systems. By knowing the
correct format to be used in Mathcad, the lengthy solution of linear systems
can be omitted (See figure 4-17).

Figure 4-17. Solutions of Linear Systems using Mathcad

By: Engr. Rizza P. Gamalinda P a g e 2 | 25

You might also like