Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- multiplying a variable in a formula

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-01-2021
05:21 PM

03-01-2021
05:21 PM

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

Solved! Go to Solution.

Labels:

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-02-2021
12:37 AM

03-02-2021
12:37 AM

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

6 REPLIES 6

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-02-2021
12:37 AM

03-02-2021
12:37 AM

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-02-2021
02:43 AM

03-02-2021
02:43 AM

Re: multiplying a variable in a formula

Hi , how do i vectorise the formula?

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-02-2021
07:43 PM

03-02-2021
07:43 PM

Re: multiplying a variable in a formula

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

Good luck~

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-02-2021
07:59 PM

03-02-2021
07:59 PM

Re: multiplying a variable in a formula

Perhaps I should have included some additional details:

to add the subscript:

To vectorize the function:

Select or highlight the formula you want to vectorize:

Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-03-2021
09:00 AM

03-03-2021
09:00 AM

Re: multiplying a variable in a formula

Like this?

Success!

Luc

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-03-2021
09:53 AM

03-03-2021
09:53 AM

Re: multiplying a variable in a formula

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.