Comparing vector elements and updating element values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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!
Solved! Go to Solution.
- Labels:
-
Mechanical_Engineering
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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 ) :
Then you can use it to compare two arrays/vectors, e.g.:
like this:
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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 ) :
Then you can use it to compare two arrays/vectors, e.g.:
like this:
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Many thanks! My version of mathcad did not like that if statement syntax, but I did get it to work as needed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I did not use an if-statement, but the if-function... And Mathcad 15 should be happy with that as well.
Luc
