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

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

Comparing vector elements and updating element values

JC_10909206
2-Guest

Comparing vector elements and updating element values

Hello,

 

I have been using mathcad for years as a basic user, but do not have much experience using it for matrix operations or programming. 

 

I am trying to create a worksheet that will allow me to feed in data in to several 3x1 matrices and then compare values of the elements of each matrix and then create a new matrix of only the largest values. 

 

However, the resulting output of what I have at the moment is a scaler. How do I instead get a vector result? Please note that I am using Mathcad 15 (and not Mathcad Prime).

 

Thanks!

 

JC_10909206_0-1704311812673.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
LucMeekes
23-Emerald III
(To:JC_10909206)

You get a scalar result from your function because a function always returns the result of the last statement executed.

 

You can define this function (I use a capital M, to distinguish it from the built-in function max ) :

LucMeekes_0-1704315071277.png

Then you can use it to compare two arrays/vectors, e.g.:

LucMeekes_1-1704315117406.png

like this:

LucMeekes_2-1704315128612.png

Note that the vectorise operator is used (the arrow over Max(A,B), you get it by selecting the function and pressing [CTRL _], that is Control-underscore ), if not you'll get an error message.

The vectors need to be the same size, but can be any length.

 

Success!
Luc

View solution in original post

3 REPLIES 3
LucMeekes
23-Emerald III
(To:JC_10909206)

You get a scalar result from your function because a function always returns the result of the last statement executed.

 

You can define this function (I use a capital M, to distinguish it from the built-in function max ) :

LucMeekes_0-1704315071277.png

Then you can use it to compare two arrays/vectors, e.g.:

LucMeekes_1-1704315117406.png

like this:

LucMeekes_2-1704315128612.png

Note that the vectorise operator is used (the arrow over Max(A,B), you get it by selecting the function and pressing [CTRL _], that is Control-underscore ), if not you'll get an error message.

The vectors need to be the same size, but can be any length.

 

Success!
Luc

Many thanks! My version of mathcad did not like that if statement syntax, but I did get it to work as needed.

LucMeekes
23-Emerald III
(To:JC_10909206)

I did not use an if-statement, but the if-function... And Mathcad 15 should be happy with that as well.

 

Luc

Top Tags