Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X
In mathCAD prime 10,
how to do element product in two column vectors?
For example,
A := [1 2 3]
B :=[4 5 6]
I want to have C=[4 10 18]. In this case, how can I express it in mathCAD?
Please help me!
Solved! Go to Solution.
You have to use "vectorization"!
Prime 10 file attached
Thanks a lot!
but I have another issue.
Here is my worksheet.
N:= 50 n := 0..N-1
w(s) := cos(2*pi*n)
f0(s) :=sin(10*n)
I need to do element product here.
Vectorizing f0(s)*w(s) doesn't work.
Hi,
n := 0..N-1
your n is not vector, it is a range.
Here is my worksheet.
Unfortunately its NOT here! You should attach your worksheet using the area or "browse" button at the end of the editor window:
N:= 50 n := 0..N-1
w(s) := cos(2*pi*n)
f0(s) :=sin(10*n)
Its not clear to me what you are trying to do?
w(s):=... and not w[n:=... ???? Your function argument "s" is not used in the definition and the range (not vector!) "n" is misused that way. Prime would throw an error if you later would try to use w(s) or w(2) or w(n).
IMHO Prime should already refuse the definition of that function w but unfortunately it accepts it.
And cos(2*pi*n)=1 for any integer value of n! Are you trying to creatie vector consisting just of 1's ?
You sure have to show your original sheet for further help!!
Not sure if you intend to do something like this:
Not sure if the problem is already solve for you. Just to be on the safe side:
To create a vector you have to use the matrix index. You will notice a small rectangle when you are editing the expression.
You can't use the literal index to do so
The syntax v(..) can only be used to access vector elements, not to create a vector
I for myself dislike this way to access vector elements an prefer the second way shown in the picture using the matrix index.
The reason I dislike it is because the syntax with the parentheses is used for functions.
When you defined something like
you defined a function with the formal argument "n". This n at this moment has nothing to do with the range "n" you defined before. You could have used any name.
You also can evaluate the function for any argument you like
And now the trap you felt in. When you write
you are actually dealing with an invalid object. Unfortunately Prime allows it to be displayed and it looks like a vector. Bit its neither a vector nor a range - its invalid.
You can see that if you try to assign it a variable:
You get an error and this also is the case when you try to use this expression in other calculations.
To create a true vector you can use the method described above, but you also could use that function w very similar to the failing expression:
You may think of a range as an implicit loop. Here n is uses as matrix index on the left hand side and so it loops through its values an that way creates a true vector. Behind the scenes a loop is calculated similar to the explicit loop here:
But you are not alone - many users find it difficult to distinguish between ranges and vectors and to use ranges correctly 😉