Skip to content

Commit 1b78b50

Browse files
committed
Added discussion of the smooth operator
This closes #187
1 parent 491b0e3 commit 1b78b50

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,19 @@ This file collects the significant changes to the book since its initial public
1313
* Emphasized the use of equations over algorithms in discussion on
1414
hysteresis.
1515

16+
* Added padding and the end of the HTML body so page doesn't end abruptly
17+
18+
* Added discussion of the ``smooth`` operator (issue
19+
[#188](https://github.com/xogeny/ModelicaBook/pull/188)
20+
1621
#### Bug Fixes
1722

1823
* Completed discussion of synchronous clock features in section on Sampling.
1924

25+
* Completed table that discusses the relationship between events and
26+
various functions/operators (issue
27+
[#187](https://github.com/xogeny/ModelicaBook/pull/187)
28+
2029
### Version 0.3.2
2130

2231
#### Enhancements

ModelicaByExample/Functions/Polynomials/Differentiation2.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
within ModelicaByExample.Functions.Polynomials;
2-
model Differentiation2 "Model that differentiates a function using smooth"
2+
model Differentiation2 "Model that differentiates a function using derivative annotation"
33
Real yf;
44
Real yp;
55
Real d_yf;

text/source/behavior/discrete/events.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,33 @@ should also be noted that even a simple variable assignment, *e.g.,*
5252
5353
can trigger an event to be generated.
5454

55+
Piecewise Constructions
56+
***********************
57+
58+
There is an important special case when dealing with conditional
59+
expressions. In some cases, it is useful to create an expression that
60+
is constructed piecewise. For example,
61+
62+
.. code-block:: modelica
63+
64+
x = if (x<0) then 0 else x^2;
65+
66+
It is hard for a Modelica compiler to reliably determine that such a
67+
function is continuous or whether it has continuous derivatives. For
68+
this reason, Modelica includes the ``smooth`` operator to explicitly
69+
express such conditions. For example, using the ``smooth`` operator
70+
as follows:
71+
72+
.. code-block:: modelica
73+
74+
x = smooth(if (x<0) then 0 else x^2, 2);
75+
76+
indicates that the expression is continuous as is and will remain
77+
continuous if differentiated up to 2 times. Of course, in this case
78+
the expression is continuous regardless of the number of
79+
differentiations. But the ``smooth`` operator requires an upper bound
80+
to be specified.
81+
5582
Events and Functions
5683
^^^^^^^^^^^^^^^^^^^^
5784

@@ -108,4 +135,6 @@ Function Description
108135
``previous(x)`` During clock tick, value of ``x`` during previous clock tick
109136
``hold(x)`` Anytime, value of ``x`` during previous clock tick
110137
``sample(expr,clock)`` During clock tick, value of ``expr``
138+
``noEvent(expr)`` Suppresses events generated by ``expr``
139+
``smooth(expr,p)`` Indicates ``expr`` can be safely differentiated ``p`` times.
111140
====================== ========================================================

0 commit comments

Comments
 (0)