1 страниц (7 вхождений)
cases in definition of a function - How to use for plot or integral - Сообщения
#1 Опубликовано: 02.12.2016 11:41:14
Hi,
I have a function using "cases".
Evaluation it for certain values works as I expect it.
But using this function for plotting a graph or as integrand, only a constant value is returned.
I don't know why, but I liked to and particularly I can't find a solution.
Файл не найден.Файл не найден.
I am using SMath 0.98 (6179) on Windows 10 x64
I have a function using "cases".
Evaluation it for certain values works as I expect it.
But using this function for plotting a graph or as integrand, only a constant value is returned.
I don't know why, but I liked to and particularly I can't find a solution.
Файл не найден.Файл не найден.
I am using SMath 0.98 (6179) on Windows 10 x64
#2 Опубликовано: 02.12.2016 14:34:57
Hello [userlink]MarB[/userlink],
This is because when the numerical evaluation of a condition throws an error (if none of the previous conditions was true) or when the result of a true condition return an error, the function returns itself. When cases() returns itself, acts like a function not yet defined; this makes all his content active and evaluable, therefore when it fails n:j and break are both evaluated and you get the first value of j (3).
The solution is to put the assignments out of the cases(...)' arguments
![2016-12-02 18_08_24-SMath Studio - [cases_in_function.sm_].png](/ru-RU/file/A3e3yd/2016-12-02-18_08_24-SMath-Studio---_cases_in_function_sm___png)
This is because when the numerical evaluation of a condition throws an error (if none of the previous conditions was true) or when the result of a true condition return an error, the function returns itself. When cases() returns itself, acts like a function not yet defined; this makes all his content active and evaluable, therefore when it fails n:j and break are both evaluated and you get the first value of j (3).
The solution is to put the assignments out of the cases(...)' arguments
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#3 Опубликовано: 02.12.2016 14:55:24
#4 Опубликовано: 02.12.2016 15:19:51
#5 Опубликовано: 02.12.2016 16:09:45
Thanks Davide for your help.
I think I am smarter now.
The reason why I tried my supposed solution was, that I "copied" a Mathcad function where I used "return j" instead of "n:j break n" and there it worked fine.
The other reason is, that I thaugt: why test all members of the vector when I know early that I have found the reason.
But this only to be mentioned by the way.
Jean, thanks for your help, too.
The reason for choosing a loop is that the count of the vector my vary and therefore nesting if/else is not practible.
I think I am smarter now.
The reason why I tried my supposed solution was, that I "copied" a Mathcad function where I used "return j" instead of "n:j break n" and there it worked fine.
The other reason is, that I thaugt: why test all members of the vector when I know early that I have found the reason.
But this only to be mentioned by the way.
Jean, thanks for your help, too.
The reason for choosing a loop is that the count of the vector my vary and therefore nesting if/else is not practible.
#6 Опубликовано: 02.12.2016 21:01:03
Whatever the "if/else" is presented to the user, the nested form
is computable in any number of loops and any size. The attached
example demonstrates a typical loop as it will appear in modern
"Programmable Logic Controller". From visible small sizes to
infinitely large sizes [very large sizes] system for controlling
industrial plants. As you can observe, the "nested" is essentially
based on the user 'recipe'.
The recursive construction belongs to the "logic ToolBox" as well
as the Bolean [not attached].
Integrate Discontinuous [Algo if].sm (52 КиБ) скачан 53 раз(а).
is computable in any number of loops and any size. The attached
example demonstrates a typical loop as it will appear in modern
"Programmable Logic Controller". From visible small sizes to
infinitely large sizes [very large sizes] system for controlling
industrial plants. As you can observe, the "nested" is essentially
based on the user 'recipe'.
The recursive construction belongs to the "logic ToolBox" as well
as the Bolean [not attached].
Integrate Discontinuous [Algo if].sm (52 КиБ) скачан 53 раз(а).
#7 Опубликовано: 03.12.2016 00:21:25
... same document but the recursive section deleted.
There is "shadow in the context".
Integrate Discontinuous [Algo if].sm (34 КиБ) скачан 49 раз(а).
There is "shadow in the context".
Integrate Discontinuous [Algo if].sm (34 КиБ) скачан 49 раз(а).
1 страниц (7 вхождений)
-
Новые сообщения
-
Нет новых сообщений