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

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

multiplying a variable in a formula

JA_9802927
4-Participant

multiplying a variable in a formula

JA_9802927_0-1614637065220.png

Hi, I am trying to calculate n(variable) into the formula, but I am only getting the last value. How Can I change that? so i get all the values?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
FDS
12-Amethyst
12-Amethyst
(To:JA_9802927)

It is always better to attach your worksheet. To solve your problem vectorize the formula.

View solution in original post

6 REPLIES 6
FDS
12-Amethyst
12-Amethyst
(To:JA_9802927)

It is always better to attach your worksheet. To solve your problem vectorize the formula.

JA_9802927
4-Participant
(To:FDS)

Hi , how do i vectorise the formula?

I am new to this, I am thankful and appreciate your help.

Here is one possible method.  There may be other easier methods.

 

Good luck~

idahoan
11-Garnet
(To:idahoan)

Perhaps I should have included some additional details:

 

to add the subscript:

 

1aidaho_0-1614733010245.png

 

To vectorize the function:

Select or highlight the formula you want to vectorize:

1aidaho_1-1614733124010.png

 

Hope this helps.

 

LucMeekes
23-Emerald III
(To:JA_9802927)

Like this?

LucMeekes_0-1614779995338.png

Success!

Luc

Some remarks to what was already said:

 

You defined a range when you typed n:=0,1..4 but you immediately followed the definition by an evaluation (the = at the end to show the result). This is an undocumented trick to convert a range into a vector. Ranges and vectors may look similar but are quite different  beasts.

You have n^2 in your formula and n is a vector. Squaring is not defined for vectors and so Mathcad actually  could throw an error. Instead Mathcad is designed to perform an implicit vectorization in such cases which means it simply applies the operation on  every single element of the vectors. This vector in your formula is now multiplied by a scalar and another scalar is added to every vector element. And now you try to take the root of this vector which again triggers Mathcad's implicit vectorization. So the whole root expression in your formula is a vector. And this vector is multiplied with another vector (n*pi/1000) and vector multiplication IS a well defined operation and the result is a scalar (dot product). If you want the operation to be done element-wise you have to explicitly apply vectorization. How this is done was shown to you by 1aidaho.

 

On contrary you may note that Luc has NOT used an inline evaluation when he defined the range n. He evaluated it in a separate region. So n in his approach is still a range and can be used what a range is made for - indexing the elements of a vector or matrix. And this is exactly what Luc did. Note that he applied your formula to w[n (n is a vector index here) and not just to w. That way every vector element is calculated one after the other - you may see a range as some kind of implicit loop.

 

Just thought it might be necessary and helpful to explain in more details the working of the two solutions provided.

 

Top Tags