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 - Сообщения

#1 Опубликовано: 03.07.2020 18:18:32
Harvey Hensley

Harvey Hensley

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

Группа: 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 Опубликовано: 03.07.2020 20:25:23
Jean Giraud

Jean Giraud

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

Группа: User

No document = No monkey see no monkey do
#3 Опубликовано: 03.07.2020 21:25:43
Harvey Hensley

Harvey Hensley

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

Группа: 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 Опубликовано: 04.07.2020 08:22:25
Jean Giraud

Jean Giraud

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

Группа: 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 пользователям понравился этот пост
Harvey Hensley 04.07.2020 18:38:00
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений