vectorize with function/procedure

vectorize with function/procedure - vectorize not working as I expect to do - Сообщения

#1 Опубликовано: 15.04.2017 12:59:18
Martin_B

Martin_B

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

Группа: User

Please have a look a the following example:

The first two results look good.
But why assigning the formula to a variable not work?
And the result test2 doesn't look right, does it?

vectorize.PNG

vectorize.sm (11 КиБ) скачан 78 раз(а).

Thanks for your help!
#2 Опубликовано: 15.04.2017 19:12:32
Jean Giraud

Jean Giraud

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

Группа: User

Result is same as if done by hand.

vectorize.sm (11 КиБ) скачан 103 раз(а).
#3 Опубликовано: 16.04.2017 06:46:10
Martin_B

Martin_B

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

Группа: User

Wrote

Result is same as if done by hand.


Probably I don't really understand how vectorize works.
If _I_ would do it by hand,
  • I take the first element of "f" and the first element of "phi" (the two vectors in the expression)
  • I calculate the result and put it as first element in a vector
  • I continue with the the second elements ...
  • I would obtain a two-element-vector

that's what I get by evaluating the expression
vectorize(f*K.agh(φ,5*'°,0*'°,0*'°)

I don't understand why it's a different result if this expression is assigned to a variable.

If the first factor within vectorize is a scalar, the error "Matrix must be square." is shown. But again only if the expression is assigned to a variable.

Everything works fine with functions without the line command. (But it's not possible to to do it without line in every case.)

vectorize2.PNG

vectorize2.sm (15 КиБ) скачан 68 раз(а).
#4 Опубликовано: 16.04.2017 09:42:18
Radovan Omorjan

Radovan Omorjan

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

Группа: Moderator

Hello,

The problem is in the function definition with or without line environment (as you already noted), and using the function call inside vectorize. See the picture please.

lineornottoline.PNG

It might be a bit peculiar (maybe a bug) but one should be careful about it. It is advisable to assign the values to variables first and then to use vectorize (not to use function calls with vector arguments inside vectorize). Anyway, your gave an example where one can be easily confused.

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
1 пользователям понравился этот пост
Martin_B 17.04.2017 16:06:00
#5 Опубликовано: 16.04.2017 19:57:44
Jean Giraud

Jean Giraud

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

Группа: User

Nice comment Radovan,

The Mathcad vectorize operator is particular to Mathcad.
No fixed rule, just case by case. Same applies to Smath.

Jean

vectorize demo.sm (32 КиБ) скачан 123 раз(а).
1 пользователям понравился этот пост
Radovan Omorjan 17.04.2017 04:16:00
#6 Опубликовано: 24.04.2017 09:53:59
Martin_B

Martin_B

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

Группа: User

Found another strange behavior (as I think):
Shouldn't vectorize handle 1-element vectors like any other with more elements?

vectorize_one.PNG
#7 Опубликовано: 24.04.2017 12:26:05
Davide Carpi

Davide Carpi

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

Группа: Moderator

Wrote

Found another strange behavior (as I think):
Shouldn't vectorize handle 1-element vectors like any other with more elements?



It should. I think I can fix it, thank you (see BTS SS-2443)

As for the initial problem, I tend to consider it a bug/issue, simply because what you get when the function is on the left side of an evaluation is not what you get when the function is on the right side of an assignment.
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#8 Опубликовано: 24.04.2017 12:58:15
Jean Giraud

Jean Giraud

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

Группа: User

Vectorize operator operates on the RHS of an equation !
Example [1] is oK
Example [2] would not support the RHS of different unit dimensions [m, km ...]
"type conversion not supported".
#9 Опубликовано: 24.04.2017 13:23:12
Martin_B

Martin_B

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

Группа: User

Wrote

Vectorize operator operates on the RHS of an equation !
Example [1] is oK
Example [2] would not support the RHS of different unit dimensions [m, km ...]
"type conversion not supported".


OK.
Let's put the operator on the RHS and vary the units:
vector_1.PNG
#10 Опубликовано: 25.04.2017 11:24:53
Jean Giraud

Jean Giraud

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

Группа: User

Not sure I understand your problem.
Visit "Samples" [2 months back or +]
several examples of vectorizing associated with functions.

Cheers, Jean

vectorize bolean.sm (21 КиБ) скачан 91 раз(а).
#11 Опубликовано: 25.04.2017 12:45:14
Martin_B

Martin_B

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

Группа: User

I just mentioned, that vectorize cannot handle vectors with the length 1.
And I think it should.
Or the other way round: Why do you think, it is correct the way it works at current state.

And my previous post was a reply to your comment to show that RHS or not doesn't matter and that unit dimensions also don't affect "my" problem at all.
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений