cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

how to do element product in two column vectors?

영김_10389557
4-Participant

how to do element product in two column vectors?

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!

1 ACCEPTED SOLUTION

Accepted Solutions

You have to use "vectorization"!

Werner_E_1-1718344070332.png

Prime 10 file attached

View solution in original post

7 REPLIES 7

You have to use "vectorization"!

Werner_E_1-1718344070332.png

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.


Martin Hanák



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:

Werner_E_3-1718361417919.png

 



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).

Werner_E_4-1718361941736.png

 






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:

Werner_E_1-1718361332871.png

 

I'm sorry that I missed it. "w(s)" that I mentioned was "w(n)". It was typo.

My computer in my workplace is physically isolated from any internet for security reasons. So uploading an image is not easy but I'm going to try next time.

Anyway, your answer is exactly what I was looking for.

I didn't notice how to express and write mathmatics in mathCAD to get the result which you've given.

I really appreciate your help.

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.

Werner_E_0-1718374029100.png

You can't use the literal index to do so

Werner_E_1-1718374170444.png

The syntax v(..) can only be used to access vector elements, not to create a vector

 

Werner_E_3-1718374335476.png

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

Werner_E_4-1718374449244.png

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

Werner_E_5-1718374536113.png

 

And now the trap you felt in. When you write

Werner_E_6-1718374585050.png

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:

Werner_E_7-1718374705786.png

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:

Werner_E_8-1718374847372.png

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:

Werner_E_9-1718375021610.png

 

But you are not alone - many users find it difficult to distinguish between ranges and vectors and to use ranges correctly 😉

MartinHanak_0-1718343775282.png

MartinHanak_1-1718343788998.png

 


Martin Hanák
Top Tags