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

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Calculating a Scalar in a Matrix

amaurer
1-Newbie

Calculating a Scalar in a Matrix

I have a matrix, where each column in the matrix represents a different calculation. I need to create a new column in the matrix where I sum the values in the first column and compare it to each individual value in the second column. I'm having trouble programming this in a for loop because Mathcad keeps telling me the value must be a matrix of scalar elements. I've attached an example worksheet. Let me know if you have any questions.

thanks!!

16 REPLIES 16

You're not doing a summation.

I don't understand the double loop!

Fred

wayne
3-Visitor
(To:amaurer)

Anne

You are summing an element ( TEST[k,1) , change to summing the column ( TEST<1> )

Fred_Kohlhepp
23-Emerald I
(To:wayne)

Wayne Reid wrote:

Anne

You are summing an element ( TEST[k,1) , change to summing the column ( TEST<1> )

Since Anne is developing the first column row by row as she iterates through the matrix the sum of the lolumn will change each time through. Need to be careful!

Hi Fred,

I know, I think that might be what she wants though, can't really tell as her example is just a test and not the real thing?

amaurer
1-Newbie
(To:wayne)

Gentlemen,

I need to sum the total of the first column and compare this value to each element in the 2nd column (TEST<2>) , so using the summation of TEST<1> works. It makes sense that you cannot sum TEST[k,1], because this represents the addition of each element in the column vs. the column itself. Is this a correct interpretation?

thanks!!

RichardJ
19-Tanzanite
(To:amaurer)

It's not clear to me what you want (or, judging from the other replies, to Fred or Wayne either). The text of your post implies that you have an existing matrix, and want to subserviently sum column 1, and compare the sum to column 2, so the sum does not change for each comparison. But your worksheet implies that you are creating the matrix at the same time that you are doing the sum and comparison, in which case the sum is different for each comparison. Which is correct?

Richard,

I want to compare the additive total of Column 1 to each element in Column 2. Therefore, the sum should not change, only the "flag" (i.e. either 1 or 0). I'm trying to build a "failure" flag into my programming loop in order to determine when the individual values in Column 2 exceed the total of Column 1. I hope this clarifies the question.

RichardJ
19-Tanzanite
(To:amaurer)

If the sum is constant then the matrix must exist before the program (or at least before the part of the program that does the sum and comparison). So will this work?

Richard,

I really need to keep everything in one programming loop, rather than using augment() to combine matrices. In my programming loop, I calculate a set of values in Column (1), a set of values in Column (2), and then in Column (3) I compare the sum of Column (1) to each element in Column (2). It looks like it is working (see attached). Let me know if you see a flaw in the programming.

RichardJ
19-Tanzanite
(To:amaurer)

There's no problem with the programming, but you said the sum should not change. But you calculate a new row, and then a new sum, each time round the loop .So of course the sum does change.

The sum does not change (i.e. total for Column (1) = 1775). This is the value I need to compare to each element in Column (2) (i.e. 1775 vs. 2 vs. 3 vs. 4, etc.). Am I not doing this?

RichardJ
19-Tanzanite
(To:amaurer)

Am I not doing this?

No. When k=1 you only have one row, so the sum is 11. When k=2 you have two rows, so the sum is 23. etc. See Fred's latest worksheet.

Anne Maurer wrote:

Richard,

I really need to keep everything in one programming loop, rather than using augment() to combine matrices. In my programming loop, I calculate a set of values in Column (1), a set of values in Column (2), and then in Column (3) I compare the sum of Column (1) to each element in Column (2). It looks like it is working (see attached). Let me know if you see a flaw in the programming.

Why do you need one loop?

Look at the attached sheet. SS is your program with another column added That sums the first column at each step; you can see the sum changing with each step because the values in the first column only go as high as the kth row.

SsS builds the first two columns, then passes through again to do the comparison. The fourth column shows that the sum of the first column does not change during the comparison pass.

Or, going back to the point I was trying to make before, if the matrix already exists, either inside the program or outside it, you only need one line to add the required column.

Now I understand!! You are right! I was only checking the overall total, not the total in each cell. Sorry it took me so long to see that! Fred, your addition to the programming loop worked! thanks for all of your help everyone!

StuartBruff
23-Emerald II
(To:amaurer)

Anne Maurer wrote:

Richard,

I really need to keep everything in one programming loop, rather than using augment() to combine matrices. In my programming loop, I calculate a set of values in Column (1), a set of values in Column (2), and then in Column (3) I compare the sum of Column (1) to each element in Column (2). It looks like it is working (see attached). Let me know if you see a flaw in the programming.

As Richard says, Anne, you are calculating the cumulative sum as you create Column(1) and not the final sum. In addition, you never reach your transition test condition as Column(1) itself will always be greater than Column(2), let alone its sum.

Perhaps the attached will help show the difference?

Stuart

Top Tags