Skip to main content
1-Visitor
January 14, 2010
Question

Another For loop problem

  • January 14, 2010
  • 4 replies
  • 6304 views
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

4 replies

1-Visitor
January 14, 2010
More in that topic.

jmG
1-Visitor
January 14, 2010
Otherwise/more/different ...

jmG
12-Amethyst
January 14, 2010
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.
1-Visitor
January 14, 2010
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



1-Visitor
January 14, 2010
Would there be a easier way to construct a function or statement to do the required?

Regards

Mike
1-Visitor
January 14, 2010
See attach.
Viktor
1-Visitor
January 14, 2010
Fantastic cheers. 🙂

Regards

Mike
1-Visitor
January 14, 2010
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