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

Community Tip - You can change your system assigned username to something more personal in your community settings. X

Another For loop problem

MikeArmstrong
5-Regular Member

Another For loop problem

I am trying to construct a for loop for to yield the following answers.

if check > 0 Acceptable

Unacceptable otherwise

Check is a vector with three different values.

Regards

Mike
19 REPLIES 19

You have a for loop (apparently written to work with any origin, but actually has ORIGIN=0 built into its assumptions) so you execute one of the two statements in the body for each element of the vector. The statements are just literal character strings, and so evaluate to the literal. The definition for the value of a program structure (and a for loop is a kind of program structure) is the value of the last expression evaluated. That will, of course, be the value evaluated for the last element of the vector. None of the other (previous) values have any effect, the entire loop is irrelevant.
__________________
� � � � Tom Gutman

Would there be a easier way to construct a function or statement to do the required?

Regards

Mike

See attach.
Viktor
Viktor

Fantastic cheers. 🙂

Regards

Mike

On 1/14/2010 6:52:26 AM, vikkor wrote:
>See attach.

Or possibly a vectorized approach?

Stuart


MikeArmstrong
5-Regular Member
(To:StuartBruff)

Neat, elegant and ascetically pleasing.

Cheers Stuart

Regards

Mike

Sure not fast and minimalistic as Stuart's solution, but it's another solution at the end.

Regards. Alvaro.
MikeArmstrong
5-Regular Member
(To:AlvaroDíaz)

Another good alternative.

It's always good to see the different ways each collab solves the problem.

Cheers guys

Regards

Mike

On 1/14/2010 7:38:31 AM, adiaz wrote:
>Sure not fast and minimalistic
>as Stuart's solution, but it's
>another solution at the end.

Your solution is probably faster as it will stop when it encounters a negative. However, if efficiency isn't a concern, mine could be modified to handle multi-column matrices by replacing the summation operator with max.

Stuart

MikeArmstrong
5-Regular Member
(To:StuartBruff)

Why does your modified version work with max and not with the summation operator?

Is it because the summation operator can only handle vectors?

Regards

Mike

On 1/14/2010 8:21:05 AM, Armo wrote:
== Why does your modified version work with max and not with the summation operator?
== Is it because the summation operator can only handle vectors?

Yes. Annoying isn't it 🙂 Matrix sums are a frequent operation, and there have been several threads on the best 'matrix sum moustrap'.

It would be nice to enhance the unadorned summation operator to act on multi-column matrices as well as vectors. I've also asked for an equivalent unadorned product operator (Π), which should also operate equally on matrices and vectors.

Stuart

Bravo, Stuart! Very elegantly.
Viktor
Viktor

On 1/14/2010 8:19:09 AM, vikkor wrote:
>Bravo, Stuart! Very elegantly.

Спасибо, Виктор

Stuart


Otherwise/more/different ...

jmG

Reading another programs syntax, it could be interesting implementing any(M,r), where M is a matrix and r a row (0 for the entire matrix), and the "inverse" function all; that's from matlab.

Actually I'm not very comfortable with the original matlab implementation.

First question could be which implementation is faster (I have my doubts, because vectorizacion is assumed to be faster that a for loop).

Second, which is symbollically evaluatable. To avoid using gthan or lthan symbols, could be using min(sign(Check))+1 (with vectorization over sign function), but this seems to not work with symbolic evaluation.

Regards. Alvaro.

On 1/14/2010 10:57:52 AM, adiaz wrote:
>Reading another programs
>syntax, it could be
>interesting implementing
>any(M,r), where M is a matrix
>and r a row ...

>Regards. Alvaro.
______________________________

In that sense, there maybe a more general way by using the Mathcad built-in (but undocumented) Dirac delta. Lot of work was published in the collab [jmG]... mask function and more.

jmG



Dirac delta and related are always the preferable solution because have well defined derivatives and integrals (not that well, in the coloquial sense, but at least figure in a lot of books), but maybe in this case it is needed some other kind of low level manipulation.

Regards. Alvaro.

"Dirac delta and related are always the preferable solution because have well defined derivatives and integrals ..."
_________________________

That one Dirac .



jmG

More in that topic.

jmG
Top Tags