User defined functions

User defined functions - Сообщения

#1 Опубликовано: 23.07.2010 13:41:09
Ragnedda

Ragnedda

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

Группа: 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 Опубликовано: 23.07.2010 16:32:25
Radovan Omorjan

Radovan Omorjan

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

Группа: 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 Опубликовано: 23.07.2010 19:23:21
Andrey Ivashov

Andrey Ivashov

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

Группа: 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 Опубликовано: 24.07.2010 02:38:05
Radovan Omorjan

Radovan Omorjan

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

Группа: 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 Опубликовано: 24.07.2010 06:42:30
Radovan Omorjan

Radovan Omorjan

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

Группа: 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!"
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений