Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline omorr  
#1 Posted : 25 February 2012 23:47:47(UTC)
omorr


Rank: Administration

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

Was thanked: 318 time(s) in 268 post(s)
Hello,

Here is a picture of one of my test files (SMath 0.92)

Take a closer look please. It does not seem to be any problem. Actually, the problem is that the two function calls (bordered regions) give the same results (look ate the vectors "b" please) although the function Xmat() was called with different arguments. The problem is that the variable with the same name "X" appeared in the function Xmat() definition as a returning value and as a result in the two callings (bordered region). I do not know why is this happening. The resolution of the problem is to put X:=0 or X:=matrix(n,k) or something else for X as a first statement in the function Xmat() definition.

I do not understand this because matrix "X" appeared as a local variable in the function definition (although inside loops) and in spite of this it makes problems.
Here is the file> needs matrix().sm

I suppose this might be regarded as a bug.

Regards,
Radovan

Edited by moderator 30 May 2012 23:12:46(UTC)  | Reason: Not specified

When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline Andrey Ivashov  
#2 Posted : 26 February 2012 00:21:26(UTC)
Andrey Ivashov


Rank: Administration

Groups: Developers, Registered, Knovel Developers, Administrators, Advanced Member
Joined: 11/07/2008(UTC)
Posts: 1,616
Man
Russian Federation

Was thanked: 1978 time(s) in 666 post(s)


Regards.
Offline omorr  
#3 Posted : 26 February 2012 01:17:30(UTC)
omorr


Rank: Administration

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

Was thanked: 318 time(s) in 268 post(s)
Thanks Andrey,

As far as I understood, if a want a vector/matrix to be local inside function definition or defining a variable by using line(), and in order not to make a mess up with them - it is not advisable to have any assignment of a vector/matrix element by itself before we put some assignments to all the vector elements at once. We should preserve any problem of this kind by simply assign something to the entire vector/matrix at once (maybe just give to all the vector/matrix elements zero values first - something like A:=0 or A:=matrix(n,k)). By assigning vector/matrix particular elements only, the vector/matrix is still global - not local. In my example the second call of the Xmat() just give the results from the first call - as the variable "X" become a global variable on the first call. I hope I am right about it.

To be honest, my example still puzzled me. Take a look at this please.


It is still working correctly in spite of that that the variable "something" is global and undefined? How that can be?

Regards,
Radovan

Edited by user 26 February 2012 01:34:47(UTC)  | Reason: Not specified

When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline Andrey Ivashov  
#4 Posted : 26 February 2012 02:38:25(UTC)
Andrey Ivashov


Rank: Administration

Groups: Developers, Registered, Knovel Developers, Administrators, Advanced Member
Joined: 11/07/2008(UTC)
Posts: 1,616
Man
Russian Federation

Was thanked: 1978 time(s) in 666 post(s)
This is because all the expressions with errors just don't used in evaluations at all.

And it doesn't matter if you test it within the line(..) or simply on the worksheet. Please see the screenshot below:


Regards.
thanks 1 user thanked Andrey Ivashov for this useful post.
on 26/02/2012(UTC)
Offline omorr  
#5 Posted : 26 February 2012 11:14:17(UTC)
omorr


Rank: Administration

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

Was thanked: 318 time(s) in 268 post(s)
Hello Andrey,

I am following your comment and just to make this clear to myself - and maybe to other users - here is another example:
Here "a" changed but only with those "x" elements not defined by "a". Here "x" still have the influence on "a".

Here we first "destroy" the variable "x" in the definition of "a" - we could do that even with a nonexisting variable (actually "x" becomes undefined then). This way changing of "x" will not have any effect on "a".


To make long story short, if we want to use vector/matrix locally not influencing other global variables - we have to "destroy" it first.

Regards,
Radovan

Edited by user 26 February 2012 12:29:59(UTC)  | Reason: Not specified

When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
thanks 1 user thanked omorr for this useful post.
on 26/02/2012(UTC)
Users browsing this topic
Guest
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.