Multiply of a numeric vector times a unit fails.

Multiply of a numeric vector times a unit fails. - Сообщения

#1 Опубликовано: 17.06.2025 16:34:26
Martin Kraska

Martin Kraska

1 240 сообщений из 2 163 понравились пользователям.

Группа: Moderator

In the following worksheet the variable R points to a vector of numerical values (there is a glitch in the preview).

Multiplying this vector times a unit fails.

Mitigation is possible when using vectorize() or the custom simp() function. Yet it is strange why these tricks should be used. Multiplying a numerical vector times a scalar unit usually is no problem. Any idea?

1-2-Maßeinheiten.sm (116 КиБ) скачан 23 раз(а).

image.png
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#2 Опубликовано: 17.06.2025 18:16:37
Alvaro Diaz Falconi

Alvaro Diaz Falconi

1 011 сообщений из 1 680 понравились пользователям.

Группа: User

Hi Martin. You can use eval to avoid the error.

image.png

Best regards.
Alvaro.
2 пользователям понравился этот пост
sergio 17.06.2025 20:08:15, Martin Kraska 17.06.2025 20:36:46
#3 Опубликовано: 17.06.2025 19:43:34
Martin Kraska

Martin Kraska

1 240 сообщений из 2 163 понравились пользователям.

Группа: Moderator

Thanks, Alvaro.

Just like vectorize() this is another workaround. What is special with my vector R? It is stored as a column vector of numbers. Multiplying this with a unit should not require poking around for workarounds. I consider the behaviour being a bug.

Possibly, the preview (and also the storage display in the debugger) are unreliable and there is some hidden issue in the stored value of the variable R. That, however, would be a much bigger problem, because referring to the stored value for understanding what happens, would be at least partially pointless.

image.png
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
3 пользователям понравился этот пост
Alvaro Diaz Falconi 18.06.2025 12:16:36, Davide Carpi 17.06.2025 22:46:58, sergio 17.06.2025 20:08:30
#4 Опубликовано: 18.06.2025 02:55:03
Alvaro Diaz Falconi

Alvaro Diaz Falconi

1 011 сообщений из 1 680 понравились пользователям.

Группа: User

Wrote

... Just like vectorize() this is another workaround. What is special with my vector R? It is stored as a column vector of numbers. Multiplying this with a unit should not require poking around for workarounds. I consider the behaviour being a bug.


Yes, you're right: using eval is just another workaround, like the others that you present. I thought this might be a solution to the problem, but it really isn't. Perhaps I thought this because of the habit of resorting to evalb (eval as boolean) and evalm (eval as matrix) in older versions of Maple.

Wrote

... Possibly, the preview (and also the storage display in the debugger) are unreliable and there is some hidden issue in the stored value of the variable R. That, however, would be a much bigger problem, because referring to the stored value for understanding what happens, would be at least partially pointless.


If there's a bug, it might be in the multiple assignment. Using an intermediate variable, you can see why the dimensions don't match. However, since SMath doesn't run the calculations unless explicitly requested with eval, it's not clear why it works with eval(R)*'N, when by that theory it should be eval(R*'N). In the following image, all the optimizations are numerical.

image.png

Best regards.
Alvaro.
Отредактировано 18.06.2025 02:55:43
1 пользователям понравился этот пост
Martin Kraska 18.06.2025 21:29:29
#5 Опубликовано: 18.06.2025 21:27:37
Martin Kraska

Martin Kraska

1 240 сообщений из 2 163 понравились пользователям.

Группа: Moderator

Wrote


If there's a bug, it might be in the multiple assignment. Using an intermediate variable, you can see why the dimensions don't match. However, since SMath doesn't run the calculations unless explicitly requested with eval, it's not clear why it works with eval(R)*'N, when by that theory it should be eval(R*'N). In the following image, all the optimizations are numerical.

image.png

Best regards.
Alvaro.




I think that the multiple assignment can't be blamed per se, because in my previous post the multiple assignment works without eval() or other tricks (demonstrated with the vector v). So my question still is the same: What makes my vector so special that the behaviour is different?
I think this is important for a predictable user experience.
Отредактировано 18.06.2025 21:28:00
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
1 пользователям понравился этот пост
Alvaro Diaz Falconi 20.06.2025 07:18:30
#6 Опубликовано: 19.06.2025 14:53:32
overlord

overlord

564 сообщений из 1 338 понравились пользователям.

Группа: Moderator

Can roots() be the problem?
Actually, only solve() can do it right.

2025-06-19_17-57.png
Отредактировано 19.06.2025 14:57:38
#7 Опубликовано: 20.06.2025 10:04:30
Martin Kraska

Martin Kraska

1 240 сообщений из 2 163 понравились пользователям.

Группа: Moderator

Wrote

Can roots() be the problem?
Actually, only solve() can do it right.



I don't think that roots() or FindRoots() are to blame here. Other than solve() they don't scan a range for multiple solutions. Based on an initial guess they just return a single solution just like the Newton-Raphson algorithm. The dimension of the solution of roots() and FindRoots() matches the dimension of the vector of variables. Given a single scalar equation and a single variable there is no vector result to be expected, thus assigning the result to a vector of variables must fail.

Assignment of the solve() result succeeds because the equation happens to have two solutions in the search region (implicitly given by the UI setting).

Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений