Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== 1.5.3.3 Function examples ====== <tabs> * [[#tab-en|EN]] * [[#tab-ua|UA]] <pane id="tab-en"> ===== Examples ===== === Example: how to get the smallest of two real numbers === a:=2.5 b:=5.7 c:=if{a<b}(a b) c=2.5 === Example: How to work with two nested IF functions === The first **if** function checks whether the variables "a" and "b" are equal to each other. If a=b, then the result is zero. If they are not equal, then the second function **if** checks the variable "a" for negativity. If a<0, then the result is 0.5, otherwise 1. a:=10 b:=-2 c:=if{a≠b}(if{a<0}(0.5 1) 0) c=1 === Example: how to change the units of measurement of a physical quantity === a:=2 m b:=convert(a {cm}) b=200 cm === Example: how to separate the numerical value of a physical quantity and then work with it as a real number === a:=2.5 m b:=2 c:=b*empiric(a) c=5 === Example: how to transfer a physical quantity into an empirical expression and assign the required units to the final result === F:=10 kN A:=√(4*empiric(F))•{mm^2} A=6,325 mm^2 === Example: How to find the largest element of a vector === A:=[1 2 3 4 5] Max(A)=5 === Example: How to find the largest element of a matrix === M:=[[1 2] [3 4] [5 6]] Min(M)=6 === Example: How to find the largest value of three variables === x:=-1.5 y:=6.6 z:=100 r=Max([x y z]) r=100 === Example: How to find a longer line segment === A:=10 cm B:=2 m min(A B)=2 m === Example: How to find a larger stress === F:=100 kN A:=5 cm^2 R:=400 MPa Smax:=max(F/A R)•{MPa} Smax=400 MPa </pane> <pane id="tab-ua"> ===== Приклади ===== === Приклад: як обрати найменше з двох дійсних чисел === a:=2.5 b:=5.7 c:=if{a<b}(a b) c=2.5 === Приклад: як працювати з двома вкладеними функціями IF === Перша функція **if** перевіряє, чи дорівнюють змінні "a" і "b" одне одному. Якщо a=b, то результатом є нуль. Якщо не дорівнюють, то друга функція **if** перевіряє змінну "a" на від'ємність. Якщо a<0, то результатом є 0.5, інакше 1. a:=10 b:=-2 c:=if{a≠b}(if{a<0}(0.5 1) 0) c=1 === Приклад: як змінити одиниці вимірювання фізичної величини === a:=2 m b:=convert(a {cm}) b=200 cm === Приклад: як відокремити числове значення фізичної величини і далі працювати з ним як з дійсним числом === a:=2.5 m b:=2 c:=b*empiric(a) c=5 === Приклад: як передати фізичну величину в емпіричний вираз і надати кінцевому результату потрібних одиниць вимірювання === F:=10 kN A:=√(4*empiric(F))•{mm^2} A=6,325 mm^2 === Приклад: як знайти найбільший елемент вектору === A:=[1 2 3 4 5] Max(A)=5 === Приклад: як знайти найбільший елемент матриці === M:=[[1 2] [3 4] [5 6]] Min(M)=6 === Приклад: як знайти найбільше значення серед трьох змінних === x:=-1.5 y:=6.6 z:=100 r=Max([x y z]) r=100 === Приклад: як знайти довший відрізок === A:=10 cm B:=2 m min(A B)=2 m === Приклад: як знайти більше напруження === F:=100 kN A:=5 cm^2 R:=400 MPa Smax:=max(F/A R)•{MPa} Smax=400 MPa </pane> </tabs> Last modified: 20.08.2023 17:%iby dystlab-wiki-admin