Possible Bug in Cases Formalism

Possible Bug in Cases Formalism - Calculation ignores the if ranges in cases - 消息

#1 已发布: 2025/2/26 06:46:32
RegRetired

RegRetired

8个赞,共144个帖子。

组: User

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.7 KiB)已下载 1878 次。

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.

HEMP FIELD 60 PERCENT.png

Thanks
Reg
Reg CurryLoveland, CO
#2 已发布: 2025/2/26 16:00:35
Davide Carpi

Davide Carpi

1,443个赞,共2,936个帖子。

组: Moderator

There's for sure a problem here:

(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 已发布: 2025/2/26 16:02:11
RegRetired

RegRetired

8个赞,共144个帖子。

组: User

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.53 KiB)已下载 1838 次。
Reg CurryLoveland, CO
#4 已发布: 2025/2/26 16:07:31
RegRetired

RegRetired

8个赞,共144个帖子。

组: User

Davide,
Could you kindly show me how with an example?

Thanks,
Reg
Reg CurryLoveland, CO
#5 已发布: 2025/2/26 16:10:11
RegRetired

RegRetired

8个赞,共144个帖子。

组: User

Davide,
Would it have the same issue if I had used if-else construction?
Thanks,
Reg
Reg CurryLoveland, CO
#6 已发布: 2025/2/26 16:57:41
Davide Carpi

Davide Carpi

1,443个赞,共2,936个帖子。

组: Moderator

Hi reg,

Wrote

Davide,
Would it have the same issue if I had used if-else construction?



Yes

Wrote

Davide,
Could you kindly show me how with an example?



Here you go:

2025-02-26 09_52_32-SMath Solver - [booleans.sm].png
booleans.sm (6.29 KiB)已下载 1885 次。


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 已发布: 2025/2/26 17:09:51
RegRetired

RegRetired

8个赞,共144个帖子。

组: User

Davide,

Thanks much.
MATHCAD bites me again.

Reg
Reg CurryLoveland, CO
#8 已发布: 2025/2/28 17:20:09
Martin Kraska

Martin Kraska

1,362个赞,共2,276个帖子。

组: Moderator

Wrote

Davide,

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.
Technische Mechanik mit SMath Studio: https://link.springer.com/book/10.1007/978-3-658-50592-9
#9 已发布: 2025/3/11 21:10:38
Davide Carpi

Davide Carpi

1,443个赞,共2,936个帖子。

组: Moderator

Wrote

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.



Done, a beta plugin is available in the gallery.

toolbox.png
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
6位用户喜欢此帖子
churichuro 2025/3/11 22:17:00, sergio 2025/3/11 22:29:00, francesco rapuano 2025/3/12 06:16:00, Martin Kraska 2025/3/12 22:52:00, Alvaro 2025/3/13 12:08:00, Oscar Campo 2025/3/18 03:29:00
#10 已发布: 2025/3/11 23:23:22
RegRetired

RegRetired

8个赞,共144个帖子。

组: User

👍👍
Reg CurryLoveland, CO
  • 有新帖
  • 无新帖