error when creating a matrix from a function

error when creating a matrix from a function - resulting matrix only contains the last values of the nested "for' loops - Messages

#1 Posted: 7/3/2020 6:18:32 PM
Harvey Hensley

Harvey Hensley

4 likes in 21 posts.

Group: User

I have a function called "rfun(x,y) that calculates a dimensionless reaction rate. The function works fine when calculating a single
value, but when it appears in a program function used to create a matrix of rates for x and y vector inputs, it doesn't work properly.
All elements of the resulting matrix contain the same value which corresponds to the last value calculated. See below.

result using rfun directly

I found a workaround as shown in the next image. All of the elements produced by these two functions are correct.

the workaround

Can anyone explain why the first method doesn't work? If I try this method with simpler functions, it works fine. The rfun function involves some use of the Prode Physical properties which may be a cause. However, since the rfun function works fine for a single result, I don't understand why it doesn't work here. Also, the rfun function doesn't work in Maxima Draw3d either.

Also, is there a more elegant workaround that could be done in just one program function?
#2 Posted: 7/3/2020 8:25:23 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

No document = No monkey see no monkey do
#3 Posted: 7/3/2020 9:25:43 PM
Harvey Hensley

Harvey Hensley

4 likes in 21 posts.

Group: User

I found a solution. When I create the rfun function, I do it with a program. The first line of the program is a Clear() statement that clears the output of the rate function. The second line is the result = math expression, and the last line is the result variable for the output.

I had previously tried using clear statements in the matrix creation function with no success.
#4 Posted: 7/4/2020 8:22:25 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

I had previously tried using clear statements in the matrix creation function with no success.


When re-using matrix/vector in program, set [M, V]:=0

ClearMatrix.PNG

1 users liked this post
Harvey Hensley 7/4/2020 6:38:00 PM
  • New Posts New Posts
  • No New Posts No New Posts