From adcce06995c12408dd66336afedb18b5f5c2e1f0 Mon Sep 17 00:00:00 2001 From: programarivm Date: Thu, 26 Sep 2019 15:04:21 +0100 Subject: [PATCH] M routines are added --- 03-routines/Main.m | 17 +++++++ 03-routines/MyMath.m | 28 +++++++++++ .../GenealogicalTree.m | 0 README.md | 47 +++++++++---------- 4 files changed, 66 insertions(+), 26 deletions(-) create mode 100644 03-routines/Main.m create mode 100644 03-routines/MyMath.m rename {03-databases => 04-databases}/GenealogicalTree.m (100%) diff --git a/03-routines/Main.m b/03-routines/Main.m new file mode 100644 index 0000000..8e706c5 --- /dev/null +++ b/03-routines/Main.m @@ -0,0 +1,17 @@ + + d hello^MyMath.m + + r "Enter n: ",n,! + + s areaCircle=$$areaCircle^MyMath.m(n) + w "areaCircle(",n,") = ",areaCircle,! + + s fibonacci=$$fibonacci^MyMath.m(n) + w "fibonacci(",n,") = ",fibonacci,! + + s factorialByVal=$$factorialByVal^MyMath.m(n) + w "factorialByVal(",n,") = ",factorialByVal,! + + s m=n + do factorialByRef^MyMath.m(.n) + w "factorialByRef(",m,") = ",n,! diff --git a/03-routines/MyMath.m b/03-routines/MyMath.m new file mode 100644 index 0000000..5eb93f8 --- /dev/null +++ b/03-routines/MyMath.m @@ -0,0 +1,28 @@ + +areaCircle(r) + q 3.1415926535898*r*r + +factorialByRef(n) + i n=1 q + s k=1 + f i=1:1:n d + . s k=k*i + s n=k + q + +factorialByVal(n) + i n=1 q 1 + s k=1 + f i=1:1:n d + . s k=k*i + q k + +fibonacci(n) + s f(1)=1,f(2)=1 + f i=3:1:n d + . s f(i)=f(i-1)+f(i-2) + q f(n) + +hello() + w "Hello!",! + q diff --git a/03-databases/GenealogicalTree.m b/04-databases/GenealogicalTree.m similarity index 100% rename from 03-databases/GenealogicalTree.m rename to 04-databases/GenealogicalTree.m diff --git a/README.md b/README.md index bb3346b..3b908a9 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,10 @@ The examples in this tutorial are run with both GPL Mumps and GT.M. - [MUMPS Technology Portal](http://mumps.cz/) +### Additional Documentation + +- [Sourceforge](http://mumps.sourceforge.net/) + --- ## Quick Setup @@ -181,30 +185,7 @@ Copy the examples into your `~/.fis-gtm/V6.3-003A_x86_64/r` folder and run: ### [`ArraysShortened.m`](https://github.com/programarivm/mumps-examples/blob/master/01-the-very-basics/ArraysShortened.m) - Approaching the solar system: - Mercury - Venus - Earth - Mars - Jupiter - Saturn - Uranus - Neptune - Pluto - - September 2019: - 26 27 28 29 30 31 1 - 2 3 4 5 6 7 8 - 9 10 11 12 13 14 15 - 16 17 18 19 20 21 22 - 23 24 25 26 27 28 29 - 30 1 2 3 4 5 6 - - Genealogical tree: - Harry and Emily had Jack - - Associative array: - Have you ever been to London? +> The output obtained is the same as that in [`Arrays.m`](https://github.com/programarivm/mumps-examples/blob/master/01-the-very-basics/Arrays.m) ## 2. User Defined Functions @@ -223,9 +204,23 @@ Copy the examples into your `~/.fis-gtm/V6.3-003A_x86_64/r` folder and run: Enter n: 9 F(9) = 34 -## 3. Databases +## 3. Routines -### [`GenealogicalTree.m`](https://github.com/programarivm/mumps-examples/blob/master/03-databases/GenealogicalTree.m) +### [`Main.m`](https://github.com/programarivm/mumps-examples/blob/master/03-routines/Main.m) + + Hello! + Enter n: 9 + + areaCircle(9) = 254.469 + fibonacci(9) = 34 + factorialByVal(9) = 362880 + factorialByRef(9) = 362880 + +> For further details also visit [MyMath.m](https://github.com/programarivm/mumps-examples/blob/master/03-routines/MyMath.m) + +## 4. Databases + +### [`GenealogicalTree.m`](https://github.com/programarivm/mumps-examples/blob/master/04-databases/GenealogicalTree.m) Genealogical tree: ^gtree(0,1,1) is Jessica