Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Offline Jeff Butler  
#1 Posted : 01 November 2016 21:58:54(UTC)
Jeff Butler

Rank: Newbie

Groups: Registered
Joined: 01/11/2016(UTC)
Posts: 5
United States
Location: New England

I ran into a couple of issues while running some calculations.

In order to minimize repeated blocks of operations, I found a need to pass a function which contains programming elements to another function or program. It would appear that this is either not possible, or more probably, I am doing something wrong.

I have attached a simplified case that exhibits the issue.

WhatAmIDoingWrong1.sm (10kb) downloaded 45 time(s).

Would someone please let me know what I am doing wrong?

THANKS!
-Jeff

P.S. Additionally I found that negative values with temperature units requires parentheses.
Offline Jean Giraud  
#2 Posted : 01 November 2016 23:47:23(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 4,022
Canada

Was thanked: 709 time(s) in 555 post(s)
Smath shhould do what you want.
The matter is to dress correctly.
Two typical examples. The Gaussian
spot take ~ 12 sec to show image.
Let it run.

Jean

Utilities Discrete Algo Range.sm (18kb) downloaded 33 time(s).
Offline omorr  
#3 Posted : 02 November 2016 00:37:48(UTC)
omorr


Rank: Administration

Groups: Registered, Administrators, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,731
Man
Serbia

Was thanked: 311 time(s) in 265 post(s)
Originally Posted by: Jeff Butler Go to Quoted Post
I ran into a couple of issues while running some calculations.

In order to minimize repeated blocks of operations, I found a need to pass a function which contains programming elements to another function or program. It would appear that this is either not possible, or more probably, I am doing something wrong.

I have attached a simplified case that exhibits the issue.

WhatAmIDoingWrong1.sm (10kb) downloaded 45 time(s).

Would someone please let me know what I am doing wrong?

THANKS!
-Jeff


Hello Jeff,

I think this might be a bug Umnik

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline Alex M.  
#4 Posted : 02 November 2016 02:29:08(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 402
Canada

Was thanked: 119 time(s) in 92 post(s)
Originally Posted by: Jeff Butler Go to Quoted Post
I ran into a couple of issues while running some calculations.

In order to minimize repeated blocks of operations, I found a need to pass a function which contains programming elements to another function or program. It would appear that this is either not possible, or more probably, I am doing something wrong.

I have attached a simplified case that exhibits the issue.

WhatAmIDoingWrong1.sm (10kb) downloaded 45 time(s).

Would someone please let me know what I am doing wrong?

THANKS!
-Jeff

P.S. Additionally I found that negative values with temperature units requires parentheses.


Hey I ran into similar before. For one reason or another the built in if() does not work in programming when cases() from plugins does, see attached.

I feel this is a bug, but I would wait for more knowledgeable members to chime in.

P.S.: cases() is more flexible version of if() anyway.

In regards to negative temperature value you more or less answered it yourself. In first case you applied "C" unit to 196 only, while in the second case you have applied unit "C" to (-196). Smath Studio does not differentiate between "-" as an operator and "-" as a sign, so units are applied to the previous number 196 only, unless you force it otherwise. You can actually clearly see to which expression you are applying units if you keep pressing right arrow before you press ' to apply units.

WhatAmIDoingWrongSOLVED.sm (12kb) downloaded 25 time(s).
WhatAmIDoingWrongSOLVED.png

Edited by user 02 November 2016 02:41:50(UTC)  | Reason: Not specified

thanks 2 users thanked Alex M. for this useful post.
on 02/11/2016(UTC),  on 02/11/2016(UTC)
Offline Jean Giraud  
#5 Posted : 02 November 2016 06:07:48(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 4,022
Canada

Was thanked: 709 time(s) in 555 post(s)
Your construction looks in conflict

if.gif
Offline Davide Carpi  
#6 Posted : 02 November 2016 14:00:45(UTC)
Davide Carpi


Rank: Advanced Member

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

Was thanked: 1115 time(s) in 729 post(s)
I guess the problem is that Function1() throws an error while his arguments are proprocessed to be passed to the procedure (possible fix: skip the exceptions at this level, if it is consistant). I'll move this topic in bug & problems, though. Umnik

If you like my plugins please consider a donation to SMath Studio; for personal contributions to me: paypal.me/dcprojects
thanks 1 user thanked Davide Carpi for this useful post.
on 02/11/2016(UTC)
Offline Jeff Butler  
#7 Posted : 02 November 2016 20:36:57(UTC)
Jeff Butler

Rank: Newbie

Groups: Registered
Joined: 01/11/2016(UTC)
Posts: 5
United States
Location: New England

Thank you all for your input.

Alex, thank you, I think the cases() function will allow me to work around the issue (with if-else).

I think most of you understand the the problem I presented, but let me try and clarify.

EXAMPLE THAT WORKS AS EXPECTED
Any function containing one or more "NORMAL" MATH FUNCTIONS, can be passed to another function without error.
good.gif

EXAMPLES THAT PRODUCE UNEXPECTED RESULTS
Any function containing ANY PROGRAMMING CONSTRUCTS, fails to function, or causes an error, when passed to another function.
while.gif

if-else.gif

I'd also just like to add that this one EXCELLENT piece of software! The units handling is a fantastic feature! SO MUCH easier to do engineering calculations than with Excel!

Best regards,
-Jeff

Offline Jean Giraud  
#8 Posted : 03 November 2016 06:13:31(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 4,022
Canada

Was thanked: 709 time(s) in 555 post(s)
Jeff,

I'm not sure about what you are trying to do.
(x<a,x>b,x≤c,x≥d) ... semiconstrained is generally adequate
for plotting. In other instances must complete (x≤a,x≥Cool.
In other instances must be bolean ...

Test(x,y):=(y+y1(x)≥0)*(y-y1(x)≤0)

Jean

Maths 2D Plot Constrained.sm (10kb) downloaded 22 time(s).
Inst_Segment Partial Random.sm (39kb) downloaded 23 time(s).
Offline Jean Giraud  
#9 Posted : 03 November 2016 06:49:08(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 4,022
Canada

Was thanked: 709 time(s) in 555 post(s)
... demo the "completely constrained"
combined in bolean.

Jean

Maths 2D Plot Constrained.sm (22kb) downloaded 26 time(s).

2D Plot Region.gif
Offline Jean Giraud  
#10 Posted : 03 November 2016 07:06:14(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 4,022
Canada

Was thanked: 709 time(s) in 555 post(s)
Note: in the function Pts
you see the 1 in the x,y definitions
and in the while loop, they are not subscript
they are index to explode Random in vector.
Offline Jeff Butler  
#11 Posted : 03 November 2016 19:24:36(UTC)
Jeff Butler

Rank: Newbie

Groups: Registered
Joined: 01/11/2016(UTC)
Posts: 5
United States
Location: New England

Hi Jean,

Here is what I was trying to do. I was evaluating SMath Studio using an example I had implemented in other software (the equation for a Platinum RTD and its inverse using Newton-Raphson). I was only sharing my findings of what I *THOUGHT* should work, but didn't. My previous posts in this thread were simplified *examples*. They were not intended to show *real math*, only to highlight what I thought might be an issue. I have since learned that there are a few ways I can work around the issue. So, at this point, it is no longer a problem for me.

Since the RTD equations differ for t>0°C and t<0°C I started with an if() statement. But I couldn't seem to pass that to my N-R function, as shown here (with the cases() solution).
rtd.gif

I have since found that I could also implement it as shown here.
rtd2.gif

In the process of preparing this example, I found that NR() is evaluating to 0, unless the if() statement is within a line() block. Here are the tooltip captures.
tt1.gif

tt2.gif

Here is the file.
CVD.sm (27kb) downloaded 31 time(s).

-Jeff
Offline Jean Giraud  
#12 Posted : 03 November 2016 21:27:53(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 4,022
Canada

Was thanked: 709 time(s) in 555 post(s)
Hello Jeff,
New England [Maine], that's not far from Drummondville [QC] !
I visited many many times Maine, Vermont ... and many more.

Few things needs be known before the hard work:
0. Van Dusen Callendar is a dead horse.
1. RTD is a primary standard, governed by BIPM [Bureau International des Poids et Mesures].
2. BIPM gives the total range in two polynomial segments because of the low temperature elbow.
3. I still have them somewhere in Mathcad 11. They are in the public domain otherwise.
4. Being of polynomial format, therefore analytical, easy to solve for Ω from °C lab bath.

The other part of the story is much simpler.

Some years ago, I have published in my Mathcad web site a "very good" RTD formula.
What was not published is the technique behind the "finding". Was done Mathcad 11.

I will be back soon, my Smath RTD needs a bit of better presenation.

Cheers, Jean


Offline Jean Giraud  
#13 Posted : 04 November 2016 16:05:18(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 4,022
Canada

Was thanked: 709 time(s) in 555 post(s)
Jeff,

Please, visit Pt100 in "Samples" [posted last minute].
Observe 'argument(w,t)' passed in the solver:
Sol(w,t):=solve(argument(w,t)≡0,t,-260,970)
Your request: "Function(s) as Argument"

Jean
Offline alyles  
#14 Posted : 22 November 2016 23:45:21(UTC)
alyles


Rank: Advanced Member

Groups: Registered
Joined: 23/03/2016(UTC)
Posts: 203
United States

Was thanked: 69 time(s) in 44 post(s)
I was also having some strange issues with my programs that passed functions. Specifically really strange behavior with using ranges in the el() function. However, submatrix() worked just fine. I also had some issues with vectorization. If i tried performing a function within the program, I would receive an error. However, if the program returned the input to the function and I used the same call outside of the program, it worked fine.

I removed any if() statements used in my programs and replaced with cases(). The issues seemed to resolve themselves.

Edit: I'm using 0.98.6128.10018

Edited by user 22 November 2016 23:48:12(UTC)  | Reason: Not specified

Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
Offline Jean Giraud  
#15 Posted : 23 November 2016 06:27:54(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 4,022
Canada

Was thanked: 709 time(s) in 555 post(s)
Hello, Jeff

I don't understand what you are trying to do vs PT100 formulas.
Either formula I gave or from BIPM. AFAIU, you are trying to
inverse [solve] a discontinuous function. That is not native
in Smath older versions for which solvers don't take "if".

I'm not arguing that "cases" might do.
This is as far as I can help from what I understand.

Jean

Inst_Pt100 [VDC].sm (17kb) downloaded 22 time(s).
Offline Jean Giraud  
#16 Posted : 23 November 2016 07:06:12(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 4,022
Canada

Was thanked: 709 time(s) in 555 post(s)
This document includes solving both VDC segments.
Strictly speaking " Functions as arguments" ...
in "2D Bar Stem More.sm", observe in the first
collapsed area ... observe the last argument
Bar:=Stem(p), calling two first functions as
arguments [Smath is delighted doing !].

Jean

Inst_Pt100 [VDC].sm (23kb) downloaded 27 time(s).

2D BarStem MORE.sm (91kb) downloaded 25 time(s).
Offline Jean Giraud  
#17 Posted : 23 November 2016 07:17:55(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 4,022
Canada

Was thanked: 709 time(s) in 555 post(s)
... in VDC: move the positive segment a bit down to clear the 1rst dichotomy.
Observe the dramatic error of VDC at NEGPt100(BIPM=-259.3467)=-7.86 !!!

Jean
Users browsing this topic
Similar Topics
Passing conditional functions as arguments of Integrals etc (Feature Requests)
by sid87pl 27/07/2014 17:59:10(UTC)
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.