Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline gth802s  
#1 Posted : 21 November 2023 06:06:52(UTC)
gth802s


Rank: Member

Groups: Registered
Joined: 21/11/2023(UTC)
Posts: 24
United States

Was thanked: 2 time(s) in 2 post(s)
Hi all, new SMath user here (transitioning from Mathcad). I am trying to recreate some of my old Mathcad sheets and have run into an issue for a scenario involving a for loop and multiple if statements. Hopefully this image works:



Any ideas as to what might be going on?

Thanks,
FT

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline Davide Carpi  
#2 Posted : 21 November 2023 07:23:53(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,647
Man
Italy
Location: Italy

Was thanked: 1329 time(s) in 875 post(s)
Hello gth802s Offline

Definitions inside cases() arguments should be avoided.

Originally Posted by: Davide Carpi Go to Quoted Post
I have to point out once again that in general you shouldn't put definitions inside cases().
Unlike if(), when a condition or a case fails instead of throwing an error the whole function is returned like if doesn't exists. The consequence is that every argument is exposed and preprocessed, with potential unwanted behaviors respect to the expected logic. This is on the edge of SMath possibilities, but is what makes possible to use cases() whereas if() usually fails.


In your case it should look like in the screenshot below:

2023-11-20 18_19_33-SMath Solver - [Worksheet1_].png


Notice that I initialize a local variable to avoid unintentional inheritance of existing vectors (if you call it twice and the second time h has less values than the first time, the second s.c_ctr will be the first vector with the initial values updated)





If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
Offline gth802s  
#3 Posted : 21 November 2023 09:19:42(UTC)
gth802s


Rank: Member

Groups: Registered
Joined: 21/11/2023(UTC)
Posts: 24
United States

Was thanked: 2 time(s) in 2 post(s)
Thanks for the responses so far. I think my problem is that the Boolean is somehow incomplete. I ran the iterations manually and the for loop works fine until j=4, but then the conditions change at j=5 saying that the variable is not defined. But I am not quite sure what the missing condition is; I guess Mathcad is more tolerant of this?

Thanks again.
Offline Razonar  
#4 Posted : 21 November 2023 09:56:36(UTC)
Razonar


Rank: Advanced Member

Groups: Registered
Joined: 28/08/2014(UTC)
Posts: 1,356
Uruguay

Was thanked: 815 time(s) in 516 post(s)
Hi. In the last expression before the otherwise, isn't a subscript j missing?

j.png

Best regards.
Alvaro.
Offline gth802s  
#5 Posted : 21 November 2023 09:56:44(UTC)
gth802s


Rank: Member

Groups: Registered
Joined: 21/11/2023(UTC)
Posts: 24
United States

Was thanked: 2 time(s) in 2 post(s)
I figured it out; it was a simple case of a missing subscript (as Alvaro pointed out) and parentheses in the wrong place... Should have stepped away from the computer sooner for that coffee; it was pretty clear what I had done wrong when I came back to my desk :-)

Thanks all; appreciate the quick responses!

Edited by moderator 23 November 2023 10:00:01(UTC)  | Reason: marked as solved

Offline Razonar  
#6 Posted : 21 November 2023 10:13:42(UTC)
Razonar


Rank: Advanced Member

Groups: Registered
Joined: 28/08/2014(UTC)
Posts: 1,356
Uruguay

Was thanked: 815 time(s) in 516 post(s)
It seems that your office lacks adequate modern equipment.

coffe.png

Best regards.
Alvaro.
Offline Jean Giraud  
#7 Posted : 21 November 2023 10:17:08(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: gth802s Go to Quoted Post
Thanks for the responses so far. I think my problem is that the Boolean is somehow incomplete.
.
Attach the Smath document for doctoring !

Offline overlord  
#8 Posted : 21 November 2023 19:55:27(UTC)
overlord


Rank: Advanced Member

Groups: Registered
Joined: 23/07/2013(UTC)
Posts: 1,128
Turkey

Was thanked: 509 time(s) in 339 post(s)
2023-11-21_085413.png
thanks 1 user thanked overlord for this useful post.
on 22/11/2023(UTC)
Offline Davide Carpi  
#9 Posted : 22 November 2023 02:59:56(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,647
Man
Italy
Location: Italy

Was thanked: 1329 time(s) in 875 post(s)
There is room for improvements in the conditions management.

Since the first case catches all the conditions where OCR[j] <= 1, the 2nd and third "(OCR[j] > 1) AND" checks are redundant.

Also, since Sigma'vf_ctr[j] <= pc[j] case is captured in the second condition, the third case can be written in the otherwise placeholder.

2023-11-21 13_53_09-bari.docx - Word.png
If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
Offline gth802s  
#10 Posted : 22 November 2023 04:12:30(UTC)
gth802s


Rank: Member

Groups: Registered
Joined: 21/11/2023(UTC)
Posts: 24
United States

Was thanked: 2 time(s) in 2 post(s)
Good catch :-) Here is the conceptual model for the soil consolidation problem which is what this sheet is written to solve. When the final stress exceeds p_c, the soil undergoes additional settlement in the second region whose slope is denoted by C_c. The reason I coded it like that is it makes it easier for me to explain to students that it is an increment of stress (beyond the pressure denoted by p_c) that causes soil settlement in that region.



This is also the reason why I try to code things as explicitly as possible (including in the if statements) so that the students can follow along easier.

Really appreciate all the thoughtful responses from everyone; loving the SMath community already!

Originally Posted by: overlord Go to Quoted Post
2023-11-21_085413.png

Edited by user 22 November 2023 04:14:01(UTC)  | Reason: Not specified

thanks 1 user thanked gth802s for this useful post.
on 23/11/2023(UTC)
Offline overlord  
#11 Posted : 22 November 2023 04:22:20(UTC)
overlord


Rank: Advanced Member

Groups: Registered
Joined: 23/07/2013(UTC)
Posts: 1,128
Turkey

Was thanked: 509 time(s) in 339 post(s)
Originally Posted by: Davide Carpi Go to Quoted Post
There is room for improvements in the conditions management.

If I didn't made a mistake, this is most simplified I could get.
Here is the file contains logarithmic simplification steps.

Regards

cases_simplified.sm (36kb) downloaded 9 time(s).

cases_simplified.png
thanks 1 user thanked overlord for this useful post.
on 23/11/2023(UTC)
Offline overlord  
#12 Posted : 22 November 2023 12:34:59(UTC)
overlord


Rank: Advanced Member

Groups: Registered
Joined: 23/07/2013(UTC)
Posts: 1,128
Turkey

Was thanked: 509 time(s) in 339 post(s)
Originally Posted by: gth802s Go to Quoted Post
... it makes it easier for me to explain to students ...

Wait, are you a teacher too?
How is everyone in this forum a teacher, academic, professor?
Am I the only simpleton here?
Offline gth802s  
#13 Posted : 22 November 2023 12:40:41(UTC)
gth802s


Rank: Member

Groups: Registered
Joined: 21/11/2023(UTC)
Posts: 24
United States

Was thanked: 2 time(s) in 2 post(s)
I am a practicing engineer with a PhD but I also teach a graduate level course at the local university (Georgia Institute of Technology). I am also living proof that having a PhD or being a professor doesn't make one any better/smarter than someone who is not an academic Biggrin

Originally Posted by: overlord Go to Quoted Post
Originally Posted by: gth802s Go to Quoted Post
... it makes it easier for me to explain to students ...

Wait, are you a teacher too?
How is everyone in this forum a teacher, academic, professor?
Am I the only simpleton here?


Offline Jean Giraud  
#14 Posted : 23 November 2023 01:39:57(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
Attach the Smath document for doctoring !

Give your data set of points
That will be enough to fit
Offline overlord  
#15 Posted : 23 November 2023 04:53:08(UTC)
overlord


Rank: Advanced Member

Groups: Registered
Joined: 23/07/2013(UTC)
Posts: 1,128
Turkey

Was thanked: 509 time(s) in 339 post(s)
Don't attach your smath document.
Issue is already solved, no need for demands.
thanks 1 user thanked overlord for this useful post.
on 23/11/2023(UTC)
Offline Jean Giraud  
#16 Posted : 24 November 2023 02:16:26(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
Give your data set of points
That will be enough to fit

Your log fit comes from Cat in the Hat.
A fitting session might be otherwise realistic,
while being more universal wrt to data collection.
As well more profitable for Students.

Users browsing this topic
Guest
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.