1 Pages (10 items)
Possible Bug in Cases Formalism - Calculation ignores the if ranges in cases - Messages
#1 Posted: 2/26/2025 6:46:32 AM
My long-time experience with MATHCAD is probably causing me problems here.
I have two different Cases construction for the E-field. Neither is correct. I have shown images of the MATHCAD construction. If you enable the orange Cases calculation, the answer is correct for E1,E2 and E3a, but not E3b. If you disable the orange calculation, you only get the correct answer for E1 and E2. The late time E3a and E3b make no sense.
HEMP E1 PLUS E2 PLUS E3a PLUS E3b.sm (149 KiB) downloaded 65 time(s).
It works as expected in MATHCAD as shown in this graph. Also, MATHCAD allows for the maximum time = 1000 seconds or more. The maximum time in SMATH is limited to 100 because in the cases construction it apparently calculates all formulas for the entire time range, independent of the ranges defined inside the cases construction. This seems to be a bug to me.

Thanks
Reg
I have two different Cases construction for the E-field. Neither is correct. I have shown images of the MATHCAD construction. If you enable the orange Cases calculation, the answer is correct for E1,E2 and E3a, but not E3b. If you disable the orange calculation, you only get the correct answer for E1 and E2. The late time E3a and E3b make no sense.
HEMP E1 PLUS E2 PLUS E3a PLUS E3b.sm (149 KiB) downloaded 65 time(s).
It works as expected in MATHCAD as shown in this graph. Also, MATHCAD allows for the maximum time = 1000 seconds or more. The maximum time in SMATH is limited to 100 because in the cases construction it apparently calculates all formulas for the entire time range, independent of the ranges defined inside the cases construction. This seems to be a bug to me.
Thanks
Reg
Reg Curry
Loveland, CO
#2 Posted: 2/26/2025 4:00:35 PM
There's for sure a problem here:
(0.01≤el(t,k)) Always returns 0 or 1 depending on the actual value of el(t,k), therefore the following comparison is always 1, suppressing any subsequent condition.
I guess you were trying to check if the variable was within a range. In that case you have to chain single boolean comparisons with AND and OR operators(# and #|#). You can also use ltlt(#,#,#) from Custom Functions plugin to display it like #≤#≤#.
(0.01≤el(t,k))≤20
(0.01≤el(t,k)) Always returns 0 or 1 depending on the actual value of el(t,k), therefore the following comparison is always 1, suppressing any subsequent condition.
I guess you were trying to check if the variable was within a range. In that case you have to chain single boolean comparisons with AND and OR operators(# and #|#). You can also use ltlt(#,#,#) from Custom Functions plugin to display it like #≤#≤#.
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#3 Posted: 2/26/2025 4:02:11 PM
Finally got it working. Cases does indeed ignore the if ranges until after the calculation. I still consider this a bug.
HEMP E1 PLUS E2 PLUS E3a PLUS E3b.sm (144 KiB) downloaded 67 time(s).
HEMP E1 PLUS E2 PLUS E3a PLUS E3b.sm (144 KiB) downloaded 67 time(s).
Reg Curry
Loveland, CO
#4 Posted: 2/26/2025 4:07:31 PM
Davide,
Could you kindly show me how with an example?
Thanks,
Reg
Could you kindly show me how with an example?
Thanks,
Reg
Reg Curry
Loveland, CO
#5 Posted: 2/26/2025 4:10:11 PM
Davide,
Would it have the same issue if I had used if-else construction?
Thanks,
Reg
Would it have the same issue if I had used if-else construction?
Thanks,
Reg
Reg Curry
Loveland, CO
#6 Posted: 2/26/2025 4:57:41 PM
Hi reg,
Yes
Here you go:
![2025-02-26 09_52_32-SMath Solver - [booleans.sm].png](/en-US/file/3VcZhC/2025-02-26-09_52_32-SMath-Solver---_booleans_sm__png)
booleans.sm (6 KiB) downloaded 60 time(s).
It is a common mistake. Thet's why we have parenthesis surrounding booleans, the program itself doesn't require them, but users initially miss the underlying logic.
WroteDavide,
Would it have the same issue if I had used if-else construction?
Yes
WroteDavide,
Could you kindly show me how with an example?
Here you go:
booleans.sm (6 KiB) downloaded 60 time(s).
It is a common mistake. Thet's why we have parenthesis surrounding booleans, the program itself doesn't require them, but users initially miss the underlying logic.
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#7 Posted: 2/26/2025 5:09:51 PM
Davide,
Thanks much.
MATHCAD bites me again.
Reg
Thanks much.
MATHCAD bites me again.

Reg
Reg Curry
Loveland, CO
#8 Posted: 2/28/2025 5:20:09 PM
WroteDavide,
Thanks much.
MATHCAD bites me again.![]()
Reg
I'd propose that the custom functions plugin adds the ternary operators to the boolean palette. And perhaps also other functions where appropriate. That would make the plugin more inclusive for non-handbook readers.
Martin Kraska
Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#9 Posted: 3/11/2025 9:10:38 PM
WroteI'd propose that the custom functions plugin adds the ternary operators to the boolean palette. And perhaps also other functions where appropriate. That would make the plugin more inclusive for non-handbook readers.
Done, a beta plugin is available in the gallery.
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
6 users liked this post
churichuro 3/11/2025 10:17:00 PM, sergio 3/11/2025 10:29:00 PM, francesco rapuano 3/12/2025 6:16:00 AM, Martin Kraska 3/12/2025 10:52:00 PM, Alvaro Diaz Falconi 3/13/2025 12:08:00 PM, Oscar Campo 3/18/2025 3:29:00 AM
#10 Posted: 3/11/2025 11:23:22 PM
👍👍
Reg Curry
Loveland, CO
1 Pages (10 items)
-
New Posts
-
No New Posts