Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array comparisons 2

Status
Not open for further replies.

haynewp

Structural
Dec 13, 2000
2,306
I am new at arrays in Mathcad. How can you compare the corresponding values in 2 arrays and write the maximum of the 2 to a new array?

For instance I have an array called "a" which has 1 column and 3 rows. I want to compare each value to the same position in "b" and write the maximum for each position to a new array called "c".

When I use c=max(a,b) it just returns one value for "c" instead of a new array.



 
Replies continue below

Recommended for you

Do it for each element ....

i:= 1..rows(a)
c:=max(a[i,b[i)

Rick D.
 
Type c:max(a,b) select the entire max(a,b) expression and type <ctrl><minus>, which will vectorize the function and perform it for each element in each vector.

Also, the above posting should say c[i:max(a[i,b[i) if you want to go that route.

TTFN



 
I was looking for something like that long time ago, now i make what rd78 and IRstuff said and nothing happends, i tried to <ctrl> <minus> and the arrow won't stay on of the (a,b), look:

=========================================================
rd787wb.jpg

=========================================================
irstuff12gq.jpg

=========================================================
irstuff22hx.jpg
 
Try initializing c in your final attempt, which otherwise looks fine to me. ie insert c[i:0 just below i:1;rows(a)

Sorry, i don't know if that will work, it just seems likely.



Cheers

Greg Locock

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
Default array indices in Mathcad start at 0. Therefore, the range variable i should be defined as i:0;rows(a)-1.

The error message relates to trying to access a[3 and b[3, which don't exist.

TTFN



 
Thanks to --> IRstuff

It worked!! look,.....

solution7hw.jpg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor