User defined functions

User defined functions - Messages

#1 Posted: 7/23/2010 1:41:09 PM
Ragnedda

Ragnedda

0 likes in 3 posts.

Group: User

I report a situation that can be a source of errors.
If you define the simple function:


F(a):=I a:=a+3
I a

and calculate F(1),
using the "symbolic" optimization the result is 7;
using the "numeric" optimization the result is 4.
No error message is reported by the program.
I think this situation must be clarified to avoid serious errors.
Also, I have not found any document explaining how parameters are
passed to a function (by reference, by value ...)

Many thanks

Ragnedda
#2 Posted: 7/23/2010 4:32:25 PM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

Hello,
Wrote


F(a):=I a:=a+3
I a


I can not understand this, sorry. Could you be more specific or try to use MATH tags - choose BB/ and MATH tag, please. Inside math tags, just copy and paste from SMath. Or, see some posts with math and choose "quote" to see the post source. You can see this post as well by "quote". Here is an example:
[MATH]F(a)←I[/MATH]
[MATH]F(a)—I[/MATH]
[MATH]a←a+3[/MATH]
[MATH]I←a[/MATH]
[MATH]F(x)—3+x[/MATH]
[MATH]F(a)—9+a[/MATH]
[MATH]F(I)—12+a[/MATH]
[MATH]F(1)=4[/MATH]
It might look a bit confusing and I am not sure if there is any use of this example. It is just a demonstration of SMath symbolic features.
Wrote


...Also, I have not found any document explaining how parameters are passed to a function (by reference, by value ...)


Visit this link on the Wiki, please User functions.
I hope that will clarify how is this working (including the above example).

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#3 Posted: 7/23/2010 7:23:21 PM
Andrey Ivashov

Andrey Ivashov

2269 likes in 3729 posts.

Group: Super Administrator

omorr, thanks.

Ragnedda, as I understood you are talking about
[MATH lang=eng]F(a):line(a:a+3,a,2,1)[/MATH]

Wrote

and calculate F(1)


To say truth I've never tested SMath Studio with lines and loops at right part of math expressions. The behavior you are mentioned was not even designed by me... it is what it is, so it is a bug, that SMath Studio is not raises an error on such expressions.

Wrote

Also, I have not found any document explaining how parameters are
passed to a function (by reference, by value ...)


All the arguments passes to functions by value.

Best regards.
#4 Posted: 7/24/2010 2:38:05 AM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

Hello,

Please refer to this post concerning functions and lines
http://en.smath.info/forum/default.aspx?g=posts&m=2971#post2971

I continued to play with it, and here are the results:
I think this is Ragnedda problem reproduced:


Here is some more:


To be honest, I got confused now after all of these examples
Wrote


To say truth I've never tested SMath Studio with lines and loops at right part of math expressions. The behavior you are mentioned was not even designed by me... it is what it is, so it is a bug, that SMath Studio is not raises an error on such expressions.


I am convinced, Andrey, that you will pay attention to this as soon as you can. I think that we will get the multiline functions working properly by solving this

Regards,
Radovan

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#5 Posted: 7/24/2010 6:42:30 AM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

Hello,

Another simple test. Literal index, function as function arguments, multiline function (almost...)

As mentioned before. It is almost everything Ok. The variable "n" is problematic. It was defined twice ???, therefore it is "global" variable, seen outside the function "F". Variable "y" is "local" - not seen outside the function. It serves here to return the result.
As Andrey said, it is as it is - at the moment. I hope something could be done in the future about the problems mentioned in these posts. It would be a rather great improvement.

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
  • New Posts New Posts
  • No New Posts No New Posts