Using of the system design of MathCAD in

advertisement
Position 1.
Soft MathCAD
Use variables in Mathcad
Content
1. Start MathCAD
2. Structure a window of Mathcad (worksheet)
3. Using variables in MathCAD
4. Uppercase and lowercase letters in MathCAD
Lecturer– As. Prof. Volodymyr Shanayda
Why did we choose MathCAD?
What is MathCAD?
In the most general sense, Mathcad combines
• engineering-oriented mathematics notation and functionality,
• a powerful numeric and symbolic computational engine,
• flexible, full-featured word processing and visualization tools.
Mathcad is designed for engineering problem-solving productivity and
presentation of solutions. In a larger view, Mathcad allows engineers to work
with the most natural, powerful mathematics tools available while enabling
managers to easily access, track, and reuse work done in their departments.
Mathcad delivers all the solving capabilities, functionality, and robustness
needed for calculation, data manipulation, and engineering design work. Its
interface makes commonly used features accessible and natural. By allowing
text, math, and graphics to be combined in a single worksheet environment,
solutions are easy to visualize, illustrate, verify, and annotate.
Lecturer– As. Prof. Volodymyr Shanayda
Start MathCAD
MathCAD must be installed
on your PC
You have few variant to start Mathcad:
1) To do double-click by left
button of mouse at file
MathCad in the folder whear
installed soft
2) To press button START in the
lower left corner of the screen and
further along the way :
Programs
MathSoftApps
(Software name)
Lecturer– As. Prof. Volodymyr Shanayda
Struture window of MathCAD (worksheet)
When you start Mathcad, you open a Mathcad worksheet. You can have
as many worksheets open as your available system resources allow.
Main title
bar
Math
toolbar
Main menu
Standard
toolbar
Window with name
worksheet
Formatting
toolbar
Side slider
Worksheet
Lower slider
Lecturer– As. Prof. Volodymyr Shanayda
You can customize the Standard and Formatting toolbars. To add and remove
buttons, right-click on the toolbar and choose Customize from the menu.
To detach and drag a toolbar around your window, place your cursor on the
edge of the toolbar. Then hold down the mouse button and drag. You can also
click on the blue (grey) title bar and drag.
You can hide toolbar
when press a red
button
Lecturer– As. Prof. Volodymyr Shanayda
You can choose to show or hide each toolbar from the View menu.
Every one of toolbar
you can placing under
main menu or place
arbitrarily on the screen
your PC
Lecturer– As. Prof. Volodymyr Shanayda
To assign settings worksheet on which will form a working paper in the Main menu must
select the position (File) and select (Page Setup)
The Page Setup dialog box contains the following:
At the top of the window, which shows the
layout of the page , we can see change
parameters (dynamically-Displays ) when
the user edits the paper settings and
margins
Lecturer– As. Prof. Volodymyr Shanayda
Using variables in MathCAD
Variable – it’s a names object that defined as numerical or symbolical
In MathCAD user often uses the following five (5) types of variables:
A discrete variables
A discrete variables with index
An indexed variables
A range
variables
The built-in
Mathcad variable
Lecturer– As. Prof. Volodymyr Shanayda
A discrete variables
A discrete variable – it is a variable, which assigned one value
Stages of:
Examples:
Define
Results
As
Name

Equal Sign
for Definition
23
Number (symbol)
mean
Lecturer– As. Prof. Volodymyr Shanayda
A discrete variables with index
Engineering theory and practice often uses the term, characterized by the name of the
actual index. For example:
stress
center-to-center spacing
Components of cutting force
A discrete variables with index are making when press button
with “point” (period
Stages of:
(
. ))
Type name variable
Press button with «point» (period “.”)
Type index
Lecturer– As. Prof. Volodymyr Shanayda
Range variables
None of engineering calculation is complete without a range variables
Definition range variables (RV) :
Range variable – its variable, which takes a range of values from smallest to largest
or from largest to smallest with a given step
Range variable – its variable with set limits for values
Please, note four types range variables
RV with integer quantity of step
RV with the Step size as “ 1”
RV when the step is a fractional
number
RV with analytical description of
the components
Lecturer– As. Prof. Volodymyr Shanayda
Structure for variable of range
Name
Equal Sign
for Definition
First value
Coma
Next value
Sign
“two points”
Last
value
Lecturer– As. Prof. Volodymyr Shanayda
Range variables
The step size is the difference between next
STEP size
for range variable
For these range variables
=
value and first value.
NEXT
value

First
value
Step size equal
Lecturer– As. Prof. Volodymyr Shanayda
Range variables
The previously defined range variables can be displayed
Stages to display the defined above
range variables
1 – Type name the RV
2 – Generate “sign of equality”
Lecturer– As. Prof. Volodymyr Shanayda
An indexed variables
An indexed variables – it’s variable, which have one name and different
numbers of indexes.
An example of a description of indexed variables in engineering practice
Хі
1
3
6
12
17
23
25
32
Уі
4
12
6
3
8
6
9
14
Array of values of variable «Х»
Х1
Х2
Х3
Х4
Х5
Х6
Х7
Х8
1
3
6
12
17
23
25
32
Array of values of variable «У»
У1
У2
У3
У4
У5
У6
У7
У8
4
12
6
3
8
6
9
14
Lecturer– As. Prof. Volodymyr Shanayda
An indexed variables
Stages of make an indexed variable:
Describe discrete variable with name “n” and define it value
equal number of elements of the array
Describe range variable with name “I”, which will be responsible
for the numbering of array elements
Assign name for indexed variable
Insert the subscript operator by clicking on the Calculator toolbar
or by typing “[“ (subscript operator)
Do not confuse range
variables with subscripts
on variable names.
Discreet variable
with subscript
Lecturer– As. Prof. Volodymyr Shanayda
An indexed variables
To type name RV, which a responsible for the numbering of array
elements
Exit of the mode edit for indexes:
press
Button “right Arrow”
Spacebar
To type Equal Sign for
Definition
To type the first value of
array
To type sign coma “,” of keyboard
After pressing button coma “,” of
keyboard on screen we can see
column of the first element of array
and cursor around placeholder for
fill next value.
Lecturer– As. Prof. Volodymyr Shanayda
An indexed variables
Step-by-step to type value for all elements of indexed
variable
For display value some element of indexed variable it need’s
to repeat the procedure so as making this variable.
Placeholder for index fill number element for display.
If you’ll type index outside the set value of RV,
the system will accent an incorrect index in red and will
show explanation of the error
Lecturer– As. Prof. Volodymyr Shanayda
Built-in variable ORIGIN in MathCAD
We will consider only one build-in variable (BV) for calculation in MathCAD - ORIGIN
By default, ORIGIN is 0, but you can change its value.
You can use Main Menu for
change value BV - ORIGIN
or defined ORIGIN as 1 in worksheet
Name ORIGIN write in worksheet in capital latters always
Lecturer– As. Prof. Volodymyr Shanayda
Built-in variable ORIGIN in MathCAD
build-in variable ORIGIN not only can take a value 1 or 0
build-in variable ORIGIN can take a arbitrary integer value in the range from -32767 to
32767
You can also reset the ORIGIN locally by redefining it in your worksheet, for example
we can assign ORIGIN
value of arbitrary
variable of integer type
Important to know
BV ORIGIN can not
to take value as fractional number
Lecturer– As. Prof. Volodymyr Shanayda
Capital and small latters in MathCAD
Internal system MathCAD distinguish between names of variables
of uppercase and lowercase letters
As seen from the above examples, MathCAD distinguishes typed from the keyboard letters are case
sensitive.
Variables fv, Fv and fV – are different variables!
Lecturer– As. Prof. Volodymyr Shanayda
Position 2.
Math expressions.
Function in MathCAD
Content
1. List rules for creating mathematical expressions
2. Global definition for mathematical expression
3. About function in MathCAD
Lecturer– As. Prof. Volodymyr Shanayda
Rules for creating mathematical expressions
The set of numbers, constants, variables, build-in functions and user’s functions that
were defined above, united signs of mathematical operations called – mathematical
expression
Numbers only
Constant and variable
Number, variable and two build-in
functions
Example for creating user’s function
(will be study later)
Constant, variables, build-in function and
user’s function “f(x)” defined above
Lecturer– As. Prof. Volodymyr Shanayda
Rules for creating mathematical expressions
Black border around limit of variable or of mathematic expression are making
automatically (as frame)
Each equation, piece of text, or other element is a region.
A Mathcad worksheet is a collection of such regions.
We can see often, when region nearby mathematic
expression is covering part or all region previous
mathematic expression
General view both mathematical structures after moving one
of the region down
Move the mouse pointer to one of the borders of a region. The
pointer turns into a small hand. Press and hold down the mouse
button.
Drag the mouse. The selected region(s) move with it. When the
region(s) are in position, release the mouse button.
Lecturer– As. Prof. Volodymyr Shanayda
Rules for creating mathematical expressions
An invisible rectangle surrounds each region.
To see the regions, choose Regions from the
View menu, or drag the mouse across them
to see dotted lines surrounding them.
Displays all regions in the default background
color leaving the rest of your worksheet gray.
The small dot to the left of each region is the
region's anchor point. The anchor point
indicates the exact location used to
determine order of evaluation as the
worksheet is calculated.
Lecturer– As. Prof. Volodymyr Shanayda
Rules for creating mathematical expressions
All variables, that are part of mathematic expression must define above and placed above or
to the left from the mathematical expression
If variables, that are part of mathematic expression placed down or
right to this mathematic expression, will be marked in red
To resolve this error should be placed
definition of the variable above or left of
expression;
And we can use sign for global definition
Result of use sign global
definition
Lecturer– As. Prof. Volodymyr Shanayda
Use global definition in worksheet
Global definition in MathCAD works as follows :
System check definition above all components that are part of
expression
If definition the variable is absent in worksheet above, system
check all worksheet down and looking for definition this variable
with sign a global definition
The variable is using value defined global to the next case for
local or global definition
In all following calculations system of MathCAD will be use
variable b with the value defined to it 12.
Lecturer– As. Prof. Volodymyr Shanayda
Functions in MathCAD
In MathCAD a user can to use two type of functions :
- build-in functions
- user’s functions.
Build-in functions – algorithms of calculation for which are recorded in internal
libraries of MathCAD
Build-in functions available to the user at
any time and anywhere in a worksheet
Build-in function we can choose of
window “Insert Function” or
type name this function of keyboard
following accepted syntax
Lecturer– As. Prof. Volodymyr Shanayda
Functions in MathCAD
Syntax of function:
Name of
function
Funk
List of
arguments
(x,y,z)
Sign of
define
:=
or

Mathematic expression for
calculation
x2 + (sin(yx+z))z-y
User’s function described above have
such general view in worksheet MathCAD
Users are not recommended to create a named
function, which is used as build-in.
Example: sin(x,y,z):=x2+y3-zx+y
After this definition build-in function sin
will be not available in this worksheet!!!
Lecturer– As. Prof. Volodymyr Shanayda
Functions in MathCAD
User’s function – algorithm of calculation for which are defined user after definition
sign in mathematic expression
The user’s function is available for use only after its definition, and only within the limits
of the worksheet where it was created.
User’s function we can to copy, to move and repeatedly define along worksheet
A variable, which are components of
mathematical expression for user’s
function and listed in parentheses in
the argument list can be not define
above
The other variables, which are components
of mathematical expression for user’s
function must be define above if it not
listed in parentheses in the argument list
Lecturer– As. Prof. Volodymyr Shanayda
Functions in MathCAD
Stages of to create user's function :
Keyboard
Screen
To type on the keyboard name for user’s function
Funkcia
Funkcia
(name can be as one word or include an index)
Index in function’s name will be make after press button
“period” ( . )
Funkcia
Funkcia
.
kor
Funkcia 
Funkcia kor
Open parenthesis
Write list of arguments with coma and close
parenthesis
Insert sign definition equal
Create mathematical expression to calculate
the function
Lecturer– As. Prof. Volodymyr Shanayda
Functions in MathCAD
Let's perform analysis of user errors when definition user’s function
Result calculation will be correct if you
define user’s function without wrong
Sometimes, for unknown reasons,
the user create two independent
mathematical expressions and move
one to one for cover regions.
Visually they get a correctly user’s
function
But result calculation such user’s function
have different by compared to the result
calculation correctly user’s function
To identify these errors is necessary to
activate the regions of mathematic
expressions
Lecturer– As. Prof. Volodymyr Shanayda
List of arguments for functions in MathCAD
As the arguments of function can be used :
- numbers
- constants
- variables
- Mathematical expressions
- Build-in functions
- User’s functions, which was defined above
All variables must be defined above if user will be to use them as arguments of
function.
This rule is true for variables, which are a part of mathematical expression for
use it as argument of function
Lecturer– As. Prof. Volodymyr Shanayda
List of arguments for functions in MathCAD
Numbers are used as arguments of function
Analyzing the proposed example should be noted that:
instead of argument х the number 2 will be presented;
instead of argument у mathematic expression
will be presented;
instead of argument z value of discreet variable а will
be presented.
The other variants to define above for list of arguments
Lecturer– As. Prof. Volodymyr Shanayda
Variants to define user’s function in MathCAD
The user created a few user’s functions
 2
funk1 ( x)  sin( x) cos x
funk3 ( x  y) 
funk2 ( x  y)  sin( x) cos ( x y)

a  3

ln ( y)
2
sin x y 

2

cos x  y
3
 1
Proba1 ( x)  funk1 ( x)  x cos  
 x
Proba1 ( x) 
a y
x funk2 ( x  y)
 C e 
x y
c
asd
Proba2 ( x  y) 
-0.086
0.549
-25.642
0.601
-123.459
0.6
2.403
2.4
2.4
Proba2 ( 1  1)
Proba2 ( 3  1)
Proba2 ( 5  1)
Proba2 ( 1  2)
Proba2 ( 3  2)
Proba2 ( 5  2)
b  4
asd  12
bcd  23
x  1  3  5
y  1  2
c  5
C  6
dab  34
w  2  2.3  4
User’s function defined above are part
of the mathematic expression for new
user’s functions
2
Proba2 ( x  y) 
A discrete and a range
variables are defined






0.549
0.601
0.6
2.403
2.4
2.4
Calculation results obtained on
display
Lecturer– As. Prof. Volodymyr Shanayda
Position 3.
Array in MathCAD
Creating an X-Y Plot
Content:
1. Orderly array of values
2. Matrix in MathCAD
3. Creating an X-Y plot in MathCAD
4. Formatting 2D plots in MathCAD
Lecturer– As. Prof. Volodymyr Shanayda
Orderly array of values
Ordered array of values – it’s an array of values that are placed one after
another with increasing (decreasing) value index.
An example of a description of indexed variables in engineering practice
Хі
1
3
6
12
17
23
25
32
Уі
4
12
6
3
8
6
9
14
Array of values named «Х»
Х1
Х2
Х3
Х4
Х5
Х6
Х7
Х8
1
3
6
12
17
23
25
32
Array of values named «y»
У1
У2
У3
У4
У5
У6
У7
У8
4
12
6
3
8
6
9
14
Lecturer– As. Prof. Volodymyr Shanayda
Orderly array of values
Algorithm create an ordered array is identical to the algorithm creating an indexed variable:
Describe discrete variable with name “n” and define it value
equal number of elements of the array
Describe range variable with name “I”, which will be responsible
for the numbering of array elements
Assign name for array
Insert the subscript operator by clicking on the Calculator toolbar
or by typing “[“ (subscript operator)
Do not confuse range
variables with subscripts
on variable names.
Discreet variable
with subscript
Lecturer– As. Prof. Volodymyr Shanayda
Orderly array of values
To type name RV, which a responsible for the numbering of array
elements
Exit of the mode edit for indexes:
press
To type Equal Sign for Definition
Button “right Arrow”
To type the first value of array
To type sign coma “,” of keyboard
After pressing button coma “,” of
keyboard on screen we can see
column of the first element of array
and cursor around placeholder for
fill next value.
Lecturer– As. Prof. Volodymyr Shanayda
Orderly array of values
Step-by-step to type for all elements of ordered array values
For display value some element of ordered array it need’s to
repeat the procedure so as making this array.
Placeholder for index fill number element for display.
If you’ll type index outside the set value of RV,
the system will accent an incorrect index in red and will
show explanation of the error
Lecturer– As. Prof. Volodymyr Shanayda
Using matrix in MathCAD
User can to use 3 types of vector in MathCAD
You can create a row vector
by creating a matrix with one
row and many columns :
The general term for a vector or
matrix is an array.
In Mathcad a column of numbers
is a vector and a rectangular array
of numbers is called a matrix.
The term vector refers
to a column vector. A
column vector is simply
a matrix with one
column
The first element of matrix has index
(0, 0) by default
For change value of index the first element of matrix we can define ORIGIN as 1 in
worksheet
Result displaying value of matrix elements
Lecturer– As. Prof. Volodymyr Shanayda
Using matrix in MathCAD
Important to know the following information:
Matrix column has in common with the orderly array in MathCAD:
value of any element of matrix column You can display pointing only
its consecutive index, as well as display value of element orderly
array
Orderly array
Matrix column
For display pointing only its
consecutive index
Lecturer– As. Prof. Volodymyr Shanayda
Using matrix in MathCAD
You can implement one of the following variants for create matrix
1
2
3
We will see insert matrix dialog box by implementing one version of the
proposed higher
Lecturer– As. Prof. Volodymyr Shanayda
Using matrix in MathCAD
Insert matrix dialog box is the same in all versions in MathCAD and regardless of the
language interface
Lecturer– As. Prof. Volodymyr Shanayda
Робота з матрицями у пакеті MathCAD
The view worksheet with matrix
As the elements of
matrix can be used :
- numbers
- constants
- variables
- Mathematical
expressions
- Build-in functions
- User’s functions,
which was defined
above
Matrix P created user
Result of calculation value of
elements matrix P
Lecturer– As. Prof. Volodymyr Shanayda
Creating an X-Y plot in MathCAD
Mathcad inserts a blank X-Y plot.
1
You can implement one of the following variants for create X-Y Plot:
1- Choose Graph > X-Y Plot from the Insert menu,
2- click on the Graph toolbar or
3- type [@].
2
3
We will see blank X-Y Plot by implementing one version of the proposed higher.
It will be located in the place where the red crosshair was localized
Lecturer– As. Prof. Volodymyr Shanayda
Creating an X-Y plot in MathCAD
The red crosshair, which defines your entry point, exists only outside a math or text region.
The upper left corner of the area graphs coincides
with the position where the red crosshair was
located
Blank X-Y plot have different
appearance from the version
to version in MathCAD
Fill the y-axis
placeholder
(left center) :
- numbers
- constants
- variables
- Mathematica
l expressions
- Build-in
functions
- User’s
functions,
which was
defined
above
Fill the x-axis placeholder
(bottom center)
List of functions argument
Lecturer– As. Prof. Volodymyr Shanayda
Creating an X-Y plot in MathCAD
We can plot X-Y graph don’t define functions or mathematic expression above.
Press button
“ F9 “
the cursor is
outside the
graph region
system specifies thresholds the graph
on places additional placeholders at
the vertical axis
system specifies
thresholds of
argument in places
additional
placeholders on the
horizontal axis
System will be plot X-Y graph for range
value from -10 to 10 if argument “X”
wasn’t defined above
Lecturer– As. Prof. Volodymyr Shanayda
Creating an X-Y plot in MathCAD
We can plot a few graph of one range variable (as argument) in this region
Range variable have name «х».
It have range values from 0 to 7 and step size equal 0.02
«a» is a discreet variable
User type ..... on central placeholder at
vertical axes:
Build-in function
Mathematic
expression
The system identifies a different color and a different type of lines each graph built in
region
Color scheme and type of line graphs, will be repeated in another region for graphs
Lecturer– As. Prof. Volodymyr Shanayda
Creating an X-Y plot in MathCAD
We can plot a few graph of few range variable (as arguments) in region
First argument “х” the system to use for plot graph the first function
Second argument “х” the system to use for plot graph the second function
Third argument “y” the system to use for plot graph the third function and the other
function will be typed after third function and without the other arguments
Lecturer– As. Prof. Volodymyr Shanayda
Creating an X-Y plot in MathCAD
Previously region can be edited and we can write list of argument of 2 elements
First argument “y” the system to use for plot graph the first function
Third argument “x” the system to use for plot graph the second and the third function
and the other function will be typed after third function and without the other
arguments
Lecturer– As. Prof. Volodymyr Shanayda
Formatting 2D plot in MathCAD
Previously considered variants of displaying the graph region can to change.
User can edit it. Two variants for action we can do for it.
Region of graph must be activated
We can do it left button the mouse
The process of editing will affect to the
selected (activated) region of graphs only
We can do double click left button
the mouse in region of graph and to
open the graph formatting dialog box
Lecturer– As. Prof. Volodymyr Shanayda
Formatting 2D plot in MathCAD
We see auxiliary lines that perform
graphics easier for reading
Auxiliary lines always light green.
Lecturer– As. Prof. Volodymyr Shanayda
Formatting 2D plot in MathCAD
On the last slides the region for graph was visible at Boxed Axis style
In the lower part the graph formatting dialog box placed field for editing axis style
In this example:
Disable display of auxiliary lines;
Style coordinate system changed from Boxed to Crossed
(brought to normal form)
Lecturer– As. Prof. Volodymyr Shanayda
Formatting 2D plot in MathCAD
The other important moment is the able to change style lines of graph (field 2)
In the activated region of graphs always show
all the elements that can influence the
process of displaying the graphs
Click “Apply” to see the effect of your changes
without closing the dialog box
Lecturer– As. Prof. Volodymyr Shanayda
Setting options for visualization graph
Options for all graph regions in the current document can be set at the beginning
of this document
After choose position X-Y Plot of button
Format of Main menu on screen will be
opened the graph formatting dialog box
with three fields (previously five) and
not active button “Apply”
We are setting options for general
view graph on the first field
Lecturer– As. Prof. Volodymyr Shanayda
Setting options for visualization graph
On second field we are setting options for types lines of graph
This parameters will be setting for all
graph regions in it document after press
button “OK”
The view graph region at edition
The region graph view according to preset
parameters
Lecturer– As. Prof. Volodymyr Shanayda
Position 4.
Using comparison operators
Least square method (LSM)
Content:
1. Logical operator
2. Operator conditional branching
3. Least square method
Lecturer– As. Prof. Volodymyr Shanayda
Logic operator
Logical operator has the following syntax
" mathematical expression 1  operator  mathematical expression 2 "
Fill the mathematical
expression 1 :
- numbers
- constants
- variables
- Mathematical
expressions
- Build-in functions
- User’s functions,
which was defined
above
≈
≠
≤
≥
<
>
Fill the mathematical
expression 2:
- numbers
- constants
- variables
- Mathematical
expressions
- Build-in functions
- User’s functions,
which was defined
above
MathCAD verify the truth of condition for both mathematical expressions. In the case
where the typed condition is satisfied (is true) MathCAD define value as - "1" for logic
operator, otherwise - "0".
Lecturer– As. Prof. Volodymyr Shanayda
Logic operator
Comparison of two functions
In the first row of the example described range
variable name - "x" that takes values range from "1"
to "4" increments equal to "0.5".
The first column contains the results of the
calculation of the built-in function
The second column contains the results of the
calculation of other a built-in functions
x
1  1.5  4
sin( x)
0.841
0.997
0.909
0.598
0.141
0.351
0.757
2
cos x
0.54
0.628
0.654
0.999
0.911
0.95
0.958
2
sin( x)  cos x
1
1
1
0
1
0
1
The third column shows the results comparing the first and
second function for each value of argument of these functions.
As can be seen from the above example, if the specified condition is
met, the system writes to the placeholders - "1", and otherwise - "0".
Lecturer– As. Prof. Volodymyr Shanayda
Logic operator
A practice use a logical operator
x  0  0.2  12
f ( x)  sin( x)
1
f ( x)
0
2
4
6
8
10
12
Suppose you want to convert all negative values of
the function into positive values in a given range
of values of the argument - "x". To perform this
task, it is necessary to plot the functions studied in
a given range of values of the argument.
1
x
ro1 ( x)  f ( x)  0
This example illustrates as the system select all
positive values of the function, and the rest
turned into - "0".
g1( x)  f ( x)  ro1 ( x)
1
g1 ( x) 0.5
0
0
2
4
6
8
10
12
x
ro2 ( x)  f ( x)  0
This example illustrates as the system select all
negative values of the function, and the rest
turned into - "0".
g2( x)  f ( x)  ro2 ( x)
0
g2 ( x) 0.5
1
0
2
4
6
8
10
12
x
Lecturer– As. Prof. Volodymyr Shanayda
Logic operator
A practice use a logical operator
ro2 ( x)  f ( x)  0
The next task is to move the obtained results
of plane negative values in the plane of
positive values. We can do it by multiplying
negative values investigated function on (-1).
g2( x)  f ( x)  ro2 ( x)
0
g2 ( x) 0.5
1
0
2
4
6
8
10
12
x
This example illustrates a move the obtained
results of plane negative values in the plane of
positive values.
g21 ( x)  g2( x)  ( 1)
1
g21 ( x) 0.5
0
0
2
4
6
8
10
12
x
g( x)  g1( x)  g21 ( x)
1
g( x)
0.5
0
0
2
4
6
x
8
10
12
As a result of these changes we received
two user's functions, which taken together,
form a set of positive values of the function
By adding these functions we add positive
value first function g1(x) to zero of second
function g21(x), and to positive values of
g21(x) add zero of g1(x). In this way, we will
create the resulting function g(x), that received
all positive values g1(x) and g21(x) functions
defined above.
Lecturer– As. Prof. Volodymyr Shanayda
Operator conditional branching
Operator conditional branching has the following syntax:
name function (list of arguments) := if (Condition, math1, math2)
Logic operator
- Variables
- Mathematical
expressions
- Build-in functions
- User’s functions,
which was
defined above
Fill the math1 or math2 :
- numbers
- constants
- variables
- Mathematical
expressions
- Build-in functions
- User’s functions,
which was defined
above
- The other operator
conditional branching
Lecturer– As. Prof. Volodymyr Shanayda
Operator conditional branching
A practice use an Operator conditional branching
x  1  1.02  7
Describe user's function f(x):=sin(x)cos(x2)
in the range 1 ≤ x ≤ 7.
2
f ( x)  sin( x)  cos  x 
1
Plot a graph of the function.
f ( x)
1
2
3
4
5
6
7
1
x
Convert negative values of the investigated
function to positive in a given range.
g( x)  if [ f ( x)  0  f ( x)  ( 1)  f ( x) ]
1
g( x)
0.5
1
2
3
4
5
6
7
5
6
7
x
The newly created function display on
worksheet.
1
f ( x)
g( x)
1
2
3
4
1
x
Lecturer– As. Prof. Volodymyr Shanayda
Operator conditional branching
A practice use an Operator f1conditional
branching
( x)  x
f2( x)  x  sin( x)
f3( x)  cos( x)
Consider the algorithm execution of other tasks: Construct
a graph for complex function:
x  1  1.02  14
x
, 1  x  5;


f ( x)   x  sin( x) , 5  x  10;
 cos( x) , 10  x  14.

g( x)  if ( x  5  f1( x)  if ( x  10  f2( x)  f3( x) ) )
10
5
f1( x)  x
g( x)
f2( x)  x  sin( x)
0
2
4
6
8
10
12
14
8
10
12
14
f3( x)  cos( x)
5
x  1  1.02  14
10
g( x)  if ( x  5  f1( x)  if ( x  10  f2( x)  f3( x) ) )
x
10
10
5
g( x)
5
0
2
4
6
8
10
12
14
g( x)
0
5
5
10
10
x
10
2
4
6
x
Lecturer– As. Prof. Volodymyr Shanayda
Least square method
  x  a  bx
yi ,
f(x)
Discrete set of points
f(xn )
- еn
yn
approximating straight
yk
+ еk
f(xk )
- еk+1
nodal points
x1
x
k
x k+1
xn
x
n
Q   ei2   [  xi   yi ]2  min
i 1
Lecturer– As. Prof. Volodymyr Shanayda
Least square method
Let described discrete set of points and the function of which is planned to approximate above
mentioned discrete set of points
 ( x)  a  x  b
Define partial derivatives of this function in the desired parameters
n
d
n
a
da
b  xi
yi
2
2  n a
2  b  xi
i= 1
i= 1
n
d
n
a
db
n
b  xi
yi
2  xi a
i= 1
n a
yi
i=1
n
i=1
n
xi  a
i=1
a
b
n
b  xi
i=1
2
2
2  xi yi
i= 1
The solution of the equation system, matrix
elements (a and b) is set to logical solutions of
system (parameters a and b).
n
b  xi
n
2  b  xi
i= 1
Given
n
i= 1
n
2
i= 1
2  yi
yi  xi
i=1
Find( a  b )
Lecturer– As. Prof. Volodymyr Shanayda
Least square method
n
8
Кількість
точок
number вузлових
of nodal points
i
1  n
Ранжирована
змінна,with
щоname
вс тановлює
порядковіс
ть
Describe range variable
“I”, which will
be responsible
вузлових
точок of array elements
for the numbering
Step-by-step мас
to type
all elements
of ordered array
values
Описуємо
ив for
значень
для дискретно
заданої
функції
Представимо
we plot a setмножину
of pointsточок
on the
дискретно заданої функції у координатній
coordinate plane
площині
15
10
y
i
5
i
xi
yi
1
2
3
4
5
6
7
8
1
3
5
8
10
11
13
15
2
3
7
7
10
12
11
13
0
0
5
10
x
15
i
Lecturer– As. Prof. Volodymyr Shanayda
Least square method
Given
n
n a
n
b  xi
i=1
n
i=1
n
xi  a
i=1
a
b
To plot a graphic representation approximating
direct introduce a new range variable - w,
which takes values from х1 to хn.
yi
n
b  xi
i=1
2
yi  xi
i=1
Find( a  b )
x1  x1
w
0.1  xn
f( w )
a
b w
D
f( 9 )
f ( 9 )  8.726
15
11.25
y
i
f( w )
To assess the accuracy of the
description of the analytical expression
given a function usually use the
concept of standard deviation. The
lower the value of the deviation, the
better this function describes gave set
of points.
7.5
D
3.75
0
2
4
6
8
x  w 9
i
10
12
14
n
yi
E
f xi
i=1
(n
1)
2
E  0.408
Lecturer– As. Prof. Volodymyr Shanayda
16
Least square method
n
d
dr
r  xi
2
p  xi
q
i= 1
4
r  xi
2
p  xi
q
i= 1
n
r  xi
2
p  xi
i= 1
2
n
n
2  xi q
i= 1
n
2  n q
i= 1
2  yi
i= 1
n
8
Кількість вузлових точок
i
1  n
Ранжирована змінна, що встановлює порядковість
вузлових точок
Описуємо масив значень для дискретно заданої функції
Представимо множину точок
дискретно заданої функції у координатній
площині
15
10
y
i
5
2  xi yi
i= 1
2  p  xi
i= 1
2
2  xi  yi
q
i= 1
2
i= 1
n
2  r  xi
yi
2  xi
2
i= 1
2  p  xi
i= 1
n
2
q
3
n
p
n
2  r  xi
yi
3
i= 1
n
2
n
2  xi
i= 1
d
dq
n
2  r  xi
yi
n
d
dp
n
2
i
xi
yi
1
2
3
4
5
6
7
8
1
3
5
8
10
11
13
15
2
3
7
7
10
12
11
13
Note that perform analytic
transformation (search for partial
derivatives) need to do above the
describe a discrete set of points
for a given analytic function
0
0
5
10
15
x
i
Lecturer– As. Prof. Volodymyr Shanayda
Least square method
Lecturer– As. Prof. Volodymyr Shanayda
Least square method
Lecturer– As. Prof. Volodymyr Shanayda
Least square method
ORIGIN  1





x 





2 
5
7
9
10
12
15




y  














The method is as follows: approximating straight
line (curve) should occupy a position in the
coordinate space, in which the sum of squared
deviations between theoretical and experimental
values in nodal points would be minimal
12 
8
9
4
6
3
2









15
10
y
s  x1  x1  0.25  x7
 ( s)  a  s  b
5
15
0
0
2
4
6
8
10
12
14
16
10
x
y
a  slope( x  y)
a  0.775
b  intercept( x  y)
b  12.93
( s )
5
0
0
2
4
6
8
10
12
14
16
x s
Lecturer– As. Prof. Volodymyr Shanayda
Least square method
Create a new worksheet.
ORIGIN  1





x 





2 
5
7
9
10
12
15





y 














In this document, we will work
with the matrix form of data
presentation; as recommended
at the start of the document
build-in variable ORIGIN define as
ORIGIN: = 1.
12 
8
9
4
6
3
2









15
Define arrays in the form of two
matrices ”x” and ”y”.
10
Plot the graph type point of
discrete set of points.
y
5
0
0
2
4
6
8
10
12
14
16
x
Lecturer– As. Prof. Volodymyr Shanayda
Least square method
The user's function must be described in matrix form, where indicators matrix to contain a
description elements that are part of the linear regression equation of general form.
 1 
 2 
 x 
Funk( x) 
 sin( x) 


 x 
We describe a vector for the unknown coefficients in linear
regression equation of general form and read the results.
 53.832
Koef  linfitx
(  y  Funk)
Koef  linfitx
(  y  Funk)
s  x1  x1  0.25  x7
 ( s)  Funk( s)  Koef
15
10
y
( s )
5
0
0
2
4
6
8
10
12
14
x s
n  7
i  1  n
n

E 
i
   xi  yi 2
1
n 1
E  1.322
16

Koef 53.832
  1.422
Koef   1.422 
 0.364
  0.364





The following actions describe the range
variable, which will use an argument when
creating approximating function. The initial
value of the range variable is set to the first
element of a given set of discrete points. The
following values calculated as the sum of the
value of the first element and the selected
increments of value. The final value of the
range variable assigned the value of the last
element of a given set of discrete points.
The user's function describe the approximation
function in a range of axis values nodal points.
Lecturer– As. Prof. Volodymyr Shanayda
Least square method
Create a new worksheet. Describes a nonlinear function as user's function.
sin( xb
 )
F (x  a  b)  a  x
Define partial derivatives of this function in the desired parameters
d
sin ( xb
 )
F ( x  a  b)  x
da
d
sin ( xb
 )
F ( x  a  b)  a  x
 cos ( x  b)  x  ln( x)
db
ORIGIN  1





x 





2 
5
7
9
10
12
15














y 





12 
8
9
4
6
3
2









 1

 1
s  
In this document, we will work with the matrix
form of data presentation; as recommended at
the start of the document build-in variable
ORIGIN define as ORIGIN: = 1.
Define arrays in the form of two matrices ”x”
and ”y” and the vector “s” of initial values of
the desired parameters.
Plot the graph type point of discrete set of
points (if you want).
Lecturer– As. Prof. Volodymyr Shanayda
Least square method
Form a user’s function in a column matrix. The number of elements of the matrix must be
equal to the sum of the number of partial to the desired preset parameters and functions.
The first element of the matrix should include analytical expression that describes a given
function. The second element is partial derivative to the first to desired parameter. Next - the
second partial derivative to desired parameter, to desired third parameter, etc.
sin( x b)

ax

sin( x b)
Fun( x k)  
x

sin( x b)
 cos ( x  b )  x  ln( x)
 ax





Please note that the argument list created user's functions as a matrix, haven't options - a
and b. These names replaces the vector k, which will be assigned the value of the desired
settings.
For further calculations need to replace the analytical expression desired options - a and b
on k1 and k2 respectively.
Lecturer– As. Prof. Volodymyr Shanayda
Least square method
sin xk
 2

k

x
1


sin xk
 2
Fun( x  k) 
x

sin xk
 2

k

x
 cos  x  k2  x  ln( x)
 1






Form a vector of unknown parameters by using the command genfit
Koef  genfit( x  y  s  Fun)
 2.448 
Koef  

1.035


Form a user’s function in a range of axis values nodal points.
s  x1  x1  0.25  x7
 ( s)  Fun( s  Koef ) 1
Note that in the description of approximating functions after the
description of the arguments set index - 1.
The index indicates which elements of the matrix is selected as
analytical expression for plotting.
Since the first place took function of investigation, the graph will
be built for this function.
Lecturer– As. Prof. Volodymyr Shanayda
Least square method
Create graphs given discrete set of points and approximating functions in the same plane.
40
30
y
( s )
20
10
0
0
2
4
6
8
10
12
14
16
x s
n  7
i  1  n
n

E 
i
   xi  yi 2
1
n 1
E  2.1
Calculate the standard deviation.
It should be noted that the mathematical expression to determine the standard deviation
include discrete variable n, number of items which are assigned a discrete set and range
variable "i" that sets the sequence of the list items specified discrete set of points.
Lecturer– As. Prof. Volodymyr Shanayda
Lecture completed
Thank you for
attention
Download