On this page:
2.19.1 Exercises 10
2.19.1.1 Question 32
2.19.1.2 Question 33
2.19.1.3 Question 34

2.19 Modules

Every functionality of Julia is stored and organized in modules. Every module is a unit containing a set of definitions. The Julia language is nothing more than an aggregation of modules that provide functionalities that are frequently needed. In addition to these, there are many other modules that we can only use if we specifically ask for them.

For example, Julia’s functionality for handling dates is not immediately available. This is visible in the following interaction

> today()

ERROR: UndefVarError: today not defined

Stacktrace:

 [1] top-level scope

   @ none:1

> using Dates

> today()

2021-11-17

Note that the first time we tried to use the function today, we got an error saying that the function was not defined. It was only after informing Julia that we needed the functionality provided by the module Dates (employing the using operation) that the function today became available.

2.19.1 Exercises 10
2.19.1.1 Question 32

Check Julia’s documentation and define a module called hyperbolic with the three following functions: hyperbolic sin (sinh), hyperbolic cosin (cosh) and hyperbolic tangent (tanh), based on the mathematical definitions: \[\sinh x = \frac{e^x-e^{-x}}{2}\] \[\cosh x = \frac{e^x+e^{-x}}{2}\] \[\tanh x = \frac{e^x-e^{-x}}{e^x+e^{-x}}\]

2.19.1.2 Question 33

In the same module, define the inverse hyperbolic functions: asinh, acosh, and atanh, whose mathematical definitions are:

\[\sinh^{-1} x=\ln(x+\sqrt{x^2+1})\] \[\cosh^{-1} x=\pm\ln(x+\sqrt{x^2-1})\] \[\tanh^{-1} x=\begin{cases} \frac{1}{2}\ln(\frac{1+x}{1-x}), & \text{if $|x|<1$}\\ \frac{1}{2}\ln(\frac{x+1}{x-1}), & \text{if $|x|>1$} \end{cases}\]

2.19.1.3 Question 34

Set the defined names, from the previous exercises, as available for other modules. Hint: see Julia’s documentation on export.