Functions As Arguments

Functions As Arguments - Passing functions containing programming elements to other functions. Order of ops with temperature - Сообщения

#1 Опубликовано: 01.11.2016 15:58:54
jbutler

jbutler

0 сообщений из 5 понравились пользователям.

Группа: User

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 (9 КиБ) скачан 80 раз(а).

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.
#2 Опубликовано: 01.11.2016 17:47:23
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

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 (17 КиБ) скачан 68 раз(а).
#3 Опубликовано: 01.11.2016 18:37:48
Radovan Omorjan

Radovan Omorjan

325 сообщений из 2052 понравились пользователям.

Группа: Moderator

Wrote

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 (9 КиБ) скачан 80 раз(а).

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

THANKS!
-Jeff



Hello Jeff,

I think this might be a bug

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#4 Опубликовано: 01.11.2016 20:29:08
Alexander O. Melnik

Alexander O. Melnik

127 сообщений из 494 понравились пользователям.

Группа: Moderator

Wrote

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 (9 КиБ) скачан 80 раз(а).

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 (11 КиБ) скачан 48 раз(а).
WhatAmIDoingWrongSOLVED.png
2 пользователям понравился этот пост
Radovan Omorjan 02.11.2016 07:20:00, Davide Carpi 02.11.2016 08:22:00
#5 Опубликовано: 02.11.2016 00:07:48
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

Your construction looks in conflict

if.gif
#6 Опубликовано: 02.11.2016 08:00:45
Davide Carpi

Davide Carpi

1415 сообщений из 2872 понравились пользователям.

Группа: Moderator

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.

If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1 пользователям понравился этот пост
Radovan Omorjan 02.11.2016 09:22:00
#7 Опубликовано: 02.11.2016 14:36:57
jbutler

jbutler

0 сообщений из 5 понравились пользователям.

Группа: User

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

#8 Опубликовано: 03.11.2016 00:13:31
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

Jeff,

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

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

Jean

Maths 2D Plot Constrained.sm (9 КиБ) скачан 47 раз(а).
Inst_Segment Partial Random.sm (38 КиБ) скачан 39 раз(а).
#9 Опубликовано: 03.11.2016 00:49:08
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

... demo the "completely constrained"
combined in bolean.

Jean

Maths 2D Plot Constrained.sm (21 КиБ) скачан 47 раз(а).

2D Plot Region.gif
#10 Опубликовано: 03.11.2016 01:06:14
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

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.
#11 Опубликовано: 03.11.2016 13:24:36
jbutler

jbutler

0 сообщений из 5 понравились пользователям.

Группа: User

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 (26 КиБ) скачан 52 раз(а).

-Jeff
#12 Опубликовано: 03.11.2016 15:27:53
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

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


#13 Опубликовано: 04.11.2016 10:05:18
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

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
#14 Опубликовано: 22.11.2016 17:45:21
Arie

Arie

93 сообщений из 285 понравились пользователям.

Группа: User

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
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
#15 Опубликовано: 23.11.2016 00:27:54
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

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 (16 КиБ) скачан 40 раз(а).
#16 Опубликовано: 23.11.2016 01:06:12
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

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 (22 КиБ) скачан 41 раз(а).

2D BarStem MORE.sm (90 КиБ) скачан 40 раз(а).
#17 Опубликовано: 23.11.2016 01:17:55
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

... 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
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений