Function with range results

Function with range results - Messages

#1 Posted: 9/28/2023 11:52:31 AM
S0lo

S0lo

0 likes in 11 posts.

Group: User

Hi, Is there a reason why I'm getting those obviously wrong results?

wr.jpg
#2 Posted: 9/28/2023 12:35:00 PM
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1674 posts.

Group: User

Hi. Looks like a bug in the "implicit scalar expansion" according to the expression in matlab for vectorization. Use explicit SMath's vectorize as workaround.

Clipboard01.png

Best regards.
Alvaro.
#3 Posted: 9/28/2023 1:50:33 PM
S0lo

S0lo

0 likes in 11 posts.

Group: User

Thank you very much. At least there is a work around!
#4 Posted: 9/28/2023 7:59:28 PM
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1674 posts.

Group: User

Wrote

Hi. Looks like a bug ...


Or not. It depends on how x^3 is interpreted. If the usual recursive definition is used, x^3 = (x^2)*x, then x^2 = x*x would be a dot product, while x^3 = (x*x) *x would be the product of a scalar times a vector, and the SMath result would be correct, although perhaps not the 'expected' one.

Clipboard01.png

Best regards.
Alvaro.
#5 Posted: 9/29/2023 12:13:04 PM
⚜ Kenny Lemens, P.E. ᵂᴵ

⚜ Kenny Lemens, P.E. ᵂᴵ

74 likes in 164 posts.

Group: User

Greetings,

Just as a note of 'Good Programming'; don't use the same variable when defining your declaring your function as you are passing into said variable for evaluation.

For example:
  • instead of f(x):=x³ and x:=[0,1..3] and f(x)=▮;
  • declare f(_z):=_z³ and x:=[0,1..3] and f(x)=▮;


This way you can keep local and global variables separate and avoid confusion. I've had instances where local variables became global, and I accidently used a global variable locally. Else, you end up asking yourself "which x is being using? x as in the variable or x as in the parameter of the function?"


May this be of Good Help;
⚜ Kenny Lemens, P.E. ᵂᴵ
"No matter where you go, there you are." -Buckaroo BanzaiHotkeys: https://en.smath.com/forum/resource.ashx?a=45771&b=2
2 users liked this post
ioan92 9/29/2023 12:55:00 PM, NDTM Amarasekera 9/29/2023 1:46:00 PM
  • New Posts New Posts
  • No New Posts No New Posts