units and user functions issue

units and user functions issue - 消息

#1 已发布: 2012/7/9 05:04:08
Davide Carpi

Davide Carpi

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

组: Moderator

Hi

someone can confirm this issue?

seem that:

- it's not related with optimization

- appears only when you redefine an internal variable inside a line() in a user-function, making them dimensionless


best regards,

w3b5urf3r
debug.png
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#2 已发布: 2012/7/9 06:13:45
Radovan Omorjan

Radovan Omorjan

325个赞和1个踩,共2,052个帖子。

组: Moderator

Hello w3b5urf3r,

This is related to changing the function arguments. As your function is defined as f1(x) and you actually change x then if you call your function with f1(A) then A will change as well. Your function f4(x) actually changed its argument too.

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
1位用户喜欢此帖子
Davide Carpi 2012/7/10 12:55:00
#3 已发布: 2012/7/10 12:34:34
Davide Carpi

Davide Carpi

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

组: Moderator

Wrote

Hello w3b5urf3r,

This is related to changing the function arguments. As your function is defined as f1(x) and you actually change x then if you call your function with f1(A) then A will change as well. Your function f4(x) actually changed its argument too.

Regards,
Radovan



Hi Omorr


you're right, f4(x) cause the same issue...

I don't know if it's a bug or a feature, but it's quite strange for me... In my mind I think that
the input variable should not be modified, unless the change it's invoked directly (A:=something)


best regards,

w3b5urf3r
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#4 已发布: 2012/7/12 22:24:45
kilele

kilele

134个赞,共397个帖子。

组: User

yes i don't like it either, i mean this global redefinition from within a function, i think this was a change introduced by Andrey for something related to future animation capabilities of smath
#5 已发布: 2012/7/29 14:29:26
Andrey Ivashov

Andrey Ivashov

2,344个赞,共4,057个帖子。

组: Super Administrator

Hello.

Yes, this is by design. This feature called Output Arguments and it can be used within procedures (functions defined with line(..) at right). This allows to return any number of values from the function. One just should remember that changing value for the variable of the same name as defined in function's arguments for such functions will also override global value of that variable.

Regards.
1位用户喜欢此帖子
Davide Carpi 2012/7/29 21:17:00
#6 已发布: 2012/10/23 14:05:57
Ruben Sidranski

Ruben Sidranski

17个赞,共465个帖子。

组: User

I don't get this
Wrote

One just should remember that changing value for the variable of the same name as defined in function's arguments for such functions will also override global value of that variable.


I am running into a problem where I have f(x,y):=2x+y When I define x:=? and y:=? I get the correct result. However, WHEN I re-define x and y and reuse the function, the answer is ALL over the place. Can someone give an example explaining what Aundrey ment (see quote)
Michelle Pipe Insulation Rev e.smz (336.41 KiB)已下载 1560 次。
#7 已发布: 2012/10/23 14:19:55
Davide Carpi

Davide Carpi

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

组: Moderator

Wrote

I don't get this

Wrote

One just should remember that changing value for the variable of the same name as defined in function's arguments for such functions will also override global value of that variable.


I am running into a problem where I have f(x,y):=2x+y When I define x:=? and y:=? I get the correct result. However, WHEN I re-define x and y and reuse the function, the answer is ALL over the place. Can someone give an example explaining what Aundrey ment (see quote)



Hi,

I think that the image below could be useful to explain the behavior

Using f(a) the input variable - x, will be modified by the function;

Using g(a) the input variable - y, doesn't change.


regards,

w3b5urf3r
SMath Studio - [Page1]_3.png
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#8 已发布: 2012/10/23 14:22:43
Ruben Sidranski

Ruben Sidranski

17个赞,共465个帖子。

组: User

w3b5urf3r
See file I attached while you responded. See the grey non print area for page 2 and 3
#9 已发布: 2012/10/23 14:32:22
Davide Carpi

Davide Carpi

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

组: Moderator

Wrote

w3b5urf3r
See file I attached while you responded. See the grey non print area for page 2 and 3



I see

It's not related with the behavior of this topic, but with this: local and global variables


Simply change your function giving as input all variable parameters - so add: [MATH lang=eng]k.ins[/MATH],[MATH lang=eng]k.pipe[/MATH] (and others, if needed)


regards,

w3b5urf3r
SMath Studio - [Michelle%20Pipe%20Insulation%20Rev%20e.smz].png
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1位用户喜欢此帖子
ElSid 2012/10/23 16:35:00
#10 已发布: 2012/10/23 16:37:48
Ruben Sidranski

Ruben Sidranski

17个赞,共465个帖子。

组: User

引用

Simply change your function giving as input all variable parameters


I had combined various sheets into one sheet and totally spaced the fact that the other variables were changing. Originally, the k's were fixed.
  • 有新帖
  • 无新帖