SMath Studio Forum
»
SMath Studio
»
Questions
»
cases in definition of a function
Rank: Advanced Member Groups: Registered
Joined: 21/10/2016(UTC) Posts: 84
Was thanked: 21 time(s) in 17 post(s)
|
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. cases_in_function.sm (6kb) downloaded 28 time(s).I am using SMath 0.98 (6179) on Windows 10 x64 Edited by user 02 December 2016 17:45:53(UTC)
| Reason: addition
|
|
|
|
Rank: Advanced Member Groups: Registered, Advanced Member Joined: 13/01/2012(UTC) Posts: 2,647 Location: Italy Was thanked: 1329 time(s) in 875 post(s)
|
Hello
MarB
, 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 Edited by user 09 December 2016 01:40:55(UTC)
| Reason: marked as Solved |
If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects |
|
|
|
Rank: Guest
Groups: Registered
Joined: 04/07/2015(UTC) Posts: 6,866 Was thanked: 981 time(s) in 809 post(s)
|
My interpretation does not mean that your attempt wrt "cases" is not. Discontinuous functions must be specified completely, same in Mathcad/Mathsoft taking into account the different "if" coding.
|
|
|
|
Rank: Guest
Groups: Registered
Joined: 04/07/2015(UTC) Posts: 6,866 Was thanked: 981 time(s) in 809 post(s)
|
... interesting to see numerical integrator takes "cases". However of no interest as it will range from very uncertain to damned erroneous.
|
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 21/10/2016(UTC) Posts: 84
Was thanked: 21 time(s) in 17 post(s)
|
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.
|
|
|
|
Rank: Guest
Groups: Registered
Joined: 04/07/2015(UTC) Posts: 6,866 Was thanked: 981 time(s) in 809 post(s)
|
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 (53kb) downloaded 30 time(s).
|
|
|
|
Rank: Guest
Groups: Registered
Joined: 04/07/2015(UTC) Posts: 6,866 Was thanked: 981 time(s) in 809 post(s)
|
|
|
|
|
SMath Studio Forum
»
SMath Studio
»
Questions
»
cases in definition of a function
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.