1 страниц (11 вхождений)
Recursion - Сообщения
#1 Опубликовано: 29.03.2016 13:05:05
Three simple examples of recursion usage taken from this document: http://twt.mpei.ac.ru/ochkov/Recursion.pdf (created by V.F. Ochkov).
recursionExamples.sm (16 КиБ) скачан 109 раз(а).

Best regards.
recursionExamples.sm (16 КиБ) скачан 109 раз(а).
Best regards.
2 пользователям понравился этот пост
#2 Опубликовано: 29.03.2016 13:09:10
Regarding 3-rd example: solution can be tested here: http://www.softschools.com/games/logic_games/tower_of_hanoi/
Regarding 2-nd example: as I mentioned, I took this example from the document, created by V.Ochkov. But I did a significant change against to the source - I've used vectorize function. Please see screenshot from referenced PDF:

What I don't understand, is why Mathcad gives correct result after call Fibonacci function with vector passed as an argument? How it determines that user wants this function to be called for every single vector element? Miracle!
Best regards.
Regarding 2-nd example: as I mentioned, I took this example from the document, created by V.Ochkov. But I did a significant change against to the source - I've used vectorize function. Please see screenshot from referenced PDF:
What I don't understand, is why Mathcad gives correct result after call Fibonacci function with vector passed as an argument? How it determines that user wants this function to be called for every single vector element? Miracle!
Best regards.
1 пользователям понравился этот пост
Davide Carpi 29.03.2016 18:14:00
#3 Опубликовано: 29.03.2016 13:44:43
Hello Andrey,
Thank you for your recent elevated activity on SMath
It is not a miracle. If you use an interval variable in Mathcad (n in this example is an interval variable - not a vector) then if you use a function and pass that interval variable to it, you will have the result of every element in that interval variable (Fibonacci(n)= ). There is a restriction here though. You can call that function, but you can not assign its result to a variable.
Regards,
Radovan
P.S. V.Ochkov is one of the person who knows quite a lot about Mathcad and Mathcad Prime
Thank you for your recent elevated activity on SMath

Wrote
What I don't understand, is why Mathcad gives correct result after call Fibonacci function with vector passed as an argument? How it determines that user wants this function to be called for every single vector element? Miracle!
It is not a miracle. If you use an interval variable in Mathcad (n in this example is an interval variable - not a vector) then if you use a function and pass that interval variable to it, you will have the result of every element in that interval variable (Fibonacci(n)= ). There is a restriction here though. You can call that function, but you can not assign its result to a variable.
Regards,
Radovan
P.S. V.Ochkov is one of the person who knows quite a lot about Mathcad and Mathcad Prime
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
2 пользователям понравился этот пост
#4 Опубликовано: 29.03.2016 18:10:39
What you are saying Radovan is true, but NOT exactly: explain the nuance.
In Mathcad n:=1..5 is a "scalar vector". It will tabulate w/o rows
identification. It will not transpose as it does not exist as numbers,
just a "vanishing iterator" working when invoked.
Don't know how it is implemented in the Mathcad version Andrey is talking
about. Presumably it has Fibonacci built-in "Fibonacci(n)". It may have
two built-in algo: one giving Fibonacci(12)=144 ,,, and another one or the
same built-in around "IfIsArray". So, if given Fibonacci(12)=144
and for n:=1..12 it will run over each values of n=0,1,2,3....
thus tabulating Fibonacci(for each n)=1,1,2,3,5,8,13 ...
Fibonacci has a non-recursive form, something like pi from Simon Plouffe.
Jean

Pi [Simon Plouffe].sm (7 КиБ) скачан 72 раз(а).
In Mathcad n:=1..5 is a "scalar vector". It will tabulate w/o rows
identification. It will not transpose as it does not exist as numbers,
just a "vanishing iterator" working when invoked.
Don't know how it is implemented in the Mathcad version Andrey is talking
about. Presumably it has Fibonacci built-in "Fibonacci(n)". It may have
two built-in algo: one giving Fibonacci(12)=144 ,,, and another one or the
same built-in around "IfIsArray". So, if given Fibonacci(12)=144
and for n:=1..12 it will run over each values of n=0,1,2,3....
thus tabulating Fibonacci(for each n)=1,1,2,3,5,8,13 ...
Fibonacci has a non-recursive form, something like pi from Simon Plouffe.
Jean
Pi [Simon Plouffe].sm (7 КиБ) скачан 72 раз(а).
2 пользователям понравился этот пост
#5 Опубликовано: 29.03.2016 19:01:58
Hello Andrey,
If you ever meet Valery F. Ochov, his "colleagues" Konstantin, Viktor...
They helped me a lot in Mathsoft Collab and wish to thank them for Eternity.
My small brain is telling me the Mathcad "Vectorise Operator" is a creation
from the main inventors, mostly Allan Razdow. Generally, we can visualise
how it works under the hood like vectorising icfft(fft) ....
The code is deeper than reasonning. Vectorise over an RGB image will explode
the 3 R,G,B components side by side.
If you ever meet Valery F. Ochov, his "colleagues" Konstantin, Viktor...
They helped me a lot in Mathsoft Collab and wish to thank them for Eternity.
My small brain is telling me the Mathcad "Vectorise Operator" is a creation
from the main inventors, mostly Allan Razdow. Generally, we can visualise
how it works under the hood like vectorising icfft(fft) ....
The code is deeper than reasonning. Vectorise over an RGB image will explode
the 3 R,G,B components side by side.
#6 Опубликовано: 29.03.2016 19:14:32
Radovan,
Thank you! Now I see... it is just another type of data.

Jean,
Thank you for clarifications and example!
Best regards.
WroteIt is not a miracle. If you use an interval variable in Mathcad (n in this example is an interval variable - not a vector) then if you use a function and pass that interval variable to it, you will have the result of every element in that interval variable (Fibonacci(n)= ). There is a restriction here though. You can call that function, but you can not assign its result to a variable.
Thank you! Now I see... it is just another type of data.
Jean,
Thank you for clarifications and example!
Best regards.
#7 Опубликовано: 30.03.2016 01:28:23
WroteThank you! Now I see... it is just another type of data.
Yes Andrey: just a scalar vector, abusely used in Mathcad ,
mostly for quick plot and gone wth the wind, like butter in the pan.
Jean
#8 Опубликовано: 31.03.2016 00:46:01
Two things I want to note:
The latter indicates stack overflow, and absence of recursion depth checking. I hope that SMath will eventually implement a means of stack overflow protection, so that in such cases it will simply report "cannot evaluate: nesting too deep" instead of crash.
Also, it would be great if Andrey considered a kind of tail recursion optimization in the future.
- Over time, recursion has changed in SMath: in the past, it was possible to use recursion directly; currently it seems to require a programming function like line(), otherwise it reports "function not defined" error.
- Recursion isn't safe; improper termination condition that leads to infinite recursion will crash SMath. Try f(x):line(f(x),1,1) followed by f(2): (just remember to save your work first).
The latter indicates stack overflow, and absence of recursion depth checking. I hope that SMath will eventually implement a means of stack overflow protection, so that in such cases it will simply report "cannot evaluate: nesting too deep" instead of crash.
Also, it would be great if Andrey considered a kind of tail recursion optimization in the future.

С уважением,
Михаил Каганский
2 пользователям понравился этот пост
#9 Опубликовано: 24.06.2021 20:45:38
Hi. A way to handle recursions.
recursion.sm (85 КиБ) скачан 93 раз(а).
recursion.pdf (330 КиБ) скачан 85 раз(а).
Best regards.
Alvaro.
recursion.sm (85 КиБ) скачан 93 раз(а).
recursion.pdf (330 КиБ) скачан 85 раз(а).
Best regards.
Alvaro.
2 пользователям понравился этот пост
#10 Опубликовано: 25.06.2021 09:28:19
Recursion comes in many ways ... some attached.
1. Pure maths [Fibonacci, Factorial, Powers ...]
2. Curiosity [Hofstadter sequence]
3. Engineering application [Process Control Instrumentation]
4. Generate vector of functions [ChebyShev ...]
Jean.
PolyOrtho ChebyShev.sm (20 КиБ) скачан 61 раз(а).
Maths Sequence Hofstadter.sm (33 КиБ) скачан 59 раз(а).
Maths Fibonnaci.sm (71 КиБ) скачан 62 раз(а).
1. Pure maths [Fibonacci, Factorial, Powers ...]
2. Curiosity [Hofstadter sequence]
3. Engineering application [Process Control Instrumentation]
4. Generate vector of functions [ChebyShev ...]
Jean.
PolyOrtho ChebyShev.sm (20 КиБ) скачан 61 раз(а).
Maths Sequence Hofstadter.sm (33 КиБ) скачан 59 раз(а).
Maths Fibonnaci.sm (71 КиБ) скачан 62 раз(а).
#11 Опубликовано: 25.06.2021 10:45:03
Wrote3. Engineering application [Process Control Instrumentation]
Few more productive advanced applications.
Inst_Control ON_OFF.sm (21 КиБ) скачан 62 раз(а).
Inst_PID Discrete Schema EXAMPLE_3.sm (22 КиБ) скачан 61 раз(а).
Inst_PID Discrete Schema EXAMPLE_7.sm (28 КиБ) скачан 56 раз(а).
Inst_PID Discrete Schema EXAMPLE_2.sm (28 КиБ) скачан 60 раз(а).
Inst_PID Discrete Schema EXAMPLE_6.sm (30 КиБ) скачан 61 раз(а).
Inst_PID Discrete Schema EXAMPLE_1.sm (32 КиБ) скачан 67 раз(а).
1 страниц (11 вхождений)
-
Новые сообщения
-
Нет новых сообщений