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
- :
- sum elements of a vector using if statement

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-25-2019
01:56 AM

02-25-2019
01:56 AM

Hello,

I have the vector from the attached file with the input data.

I need to do both the sum and the total number of all positive elements from N22 (only positive). How can i do this?

Thank you,

Otilia

Solved! Go to Solution.

Labels:

1 ACCEPTED SOLUTION

Accepted Solutions

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

02-25-2019
02:09 AM

6 REPLIES 6

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

02-25-2019
02:09 AM

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

02-25-2019
02:24 AM

02-25-2019
02:24 AM

Re: sum elements of a vector using if statement

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

02-26-2019
06:41 AM

02-26-2019
06:41 AM

Re: sum elements of a vector using if statement

For whatever it may be worth here is a slightly shorter approach

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

02-26-2019
01:13 AM

02-26-2019
01:13 AM

Re: sum elements of a vector using if statement

Hello,

I managed to get the results I wanted for a larger matrix (see attached) with the help from both of you and it is greatly appreciated.

What i still don't understand is the functions you used for sum and count. For count you used the 'vector sum' function, for sum it's some sort of product. No wonder with the vector sum i couldn't get anywhere when i started this exercise. Why?

Thank you,

Otilia

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

02-27-2019
03:43 AM

02-27-2019
03:43 AM

Re: sum elements of a vector using if statement

The result of (V>0) is a vector with the same size as V, where all elements are either 0 or 1. That is: 1 when the corresponding element in V is larger than 0, and 0 when it isn't.

The vector sum of (V>0) is the sum of all 1's, that's the count of all your positive elements in vector V.

If you multiply two vectors, like V*(V>0), the result is the total sum of all multiplications of all corresponding elements. So all positive elements of V get multiplied by 1, the other elements get multiplied by 0. The total sum of all those products is then the sum of all positive elements in V.

Success!

Luc

The vector sum of (V>0) is the sum of all 1's, that's the count of all your positive elements in vector V.

If you multiply two vectors, like V*(V>0), the result is the total sum of all multiplications of all corresponding elements. So all positive elements of V get multiplied by 1, the other elements get multiplied by 0. The total sum of all those products is then the sum of all positive elements in V.

Success!

Luc

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

02-27-2019
04:25 AM

02-27-2019
04:25 AM

Re: sum elements of a vector using if statement

It makes sense now.

Thank you.

Top Tags