Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Offline MarB  
#1 Posted : 15 April 2017 18:59:18(UTC)
MarB


Rank: Advanced Member

Groups: Registered
Joined: 21/10/2016(UTC)
Posts: 73

Was thanked: 14 time(s) in 13 post(s)
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 (12kb) downloaded 37 time(s).

Thanks for your help!

Edited by user 15 April 2017 19:10:39(UTC)  | Reason: cosmetics

Offline Jean Giraud  
#2 Posted : 16 April 2017 01:12:32(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 5,679
Canada

Was thanked: 854 time(s) in 684 post(s)
Result is same as if done by hand.

vectorize.sm (12kb) downloaded 50 time(s).
Offline MarB  
#3 Posted : 16 April 2017 12:46:10(UTC)
MarB


Rank: Advanced Member

Groups: Registered
Joined: 21/10/2016(UTC)
Posts: 73

Was thanked: 14 time(s) in 13 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
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
Code:
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 (16kb) downloaded 28 time(s).
Offline omorr  
#4 Posted : 16 April 2017 15:42:18(UTC)
omorr


Rank: Administration

Groups: Registered, Administrators, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

Was thanked: 318 time(s) in 268 post(s)
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

Edited by user 16 April 2017 15:50:27(UTC)  | Reason: Not specified

When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
thanks 1 user thanked omorr for this useful post.
on 17/04/2017(UTC)
Offline Jean Giraud  
#5 Posted : 17 April 2017 01:57:44(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 5,679
Canada

Was thanked: 854 time(s) in 684 post(s)
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 (33kb) downloaded 61 time(s).
thanks 1 user thanked Jean Giraud for this useful post.
on 17/04/2017(UTC)
Offline MarB  
#6 Posted : 24 April 2017 15:53:59(UTC)
MarB


Rank: Advanced Member

Groups: Registered
Joined: 21/10/2016(UTC)
Posts: 73

Was thanked: 14 time(s) in 13 post(s)
Found another strange behavior (as I think):
Shouldn't vectorize handle 1-element vectors like any other with more elements?

vectorize_one.PNG
Offline Davide Carpi  
#7 Posted : 24 April 2017 18:26:05(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,418
Man
Italy
Location: Italy

Was thanked: 1203 time(s) in 794 post(s)
Originally Posted by: MarB Go to Quoted Post
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 Good (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.

Edited by user 26 April 2017 13:12:07(UTC)  | Reason: added BTS ID

If you like my plugins please consider a donation to SMath Studio; for personal contributions to me: paypal.me/dcprojects
Offline Jean Giraud  
#8 Posted : 24 April 2017 18:58:15(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 5,679
Canada

Was thanked: 854 time(s) in 684 post(s)
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".
Offline MarB  
#9 Posted : 24 April 2017 19:23:12(UTC)
MarB


Rank: Advanced Member

Groups: Registered
Joined: 21/10/2016(UTC)
Posts: 73

Was thanked: 14 time(s) in 13 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
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
Offline Jean Giraud  
#10 Posted : 25 April 2017 17:24:53(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 5,679
Canada

Was thanked: 854 time(s) in 684 post(s)
Not sure I understand your problem.
Visit "Samples" [2 months back or +]
several examples of vectorizing associated with functions.

Cheers, Jean

vectorize bolean.sm (22kb) downloaded 43 time(s).
Offline MarB  
#11 Posted : 25 April 2017 18:45:14(UTC)
MarB


Rank: Advanced Member

Groups: Registered
Joined: 21/10/2016(UTC)
Posts: 73

Was thanked: 14 time(s) in 13 post(s)
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.
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.