# TIP: Resolving non integer range constructors in MATRIX.

14 messages
Open this post in threaded view
|

## TIP: Resolving non integer range constructors in MATRIX.

 Administrator Normally in matrix one can do the following. COMPUTE x={1:10:1}. resolves to {1,2,3,4,5,6,7,8,9,10} However : COMPUTE x={.1:.9,.1} One would expect/hope to receive {.1,.2,.3,.4,.5,.6,.7,.8,9}. Well, instead: MATRIX. COMPUTE x={.1: .9 : .1}. PRINT x. END MATRIX. Run MATRIX procedure: >Error encountered in source line #   150 >Warning # 12575 >Non-integer range values were specified.  Any non-integer range value will >be rounded to an integer. >Error encountered in source line #   150 >Error # 12557 >Increment value in the range operator is zero. >This command not executed. >Error encountered in source line #   151 >Error # 12492 >An attempt has been made to use previously undefined matrix (or scalar). >This command not executed. Matrix - 'X       ' is undefined >Error encountered in source line #   151 >Error # 12332 >Undefined variable in PRINT. ------ END MATRIX ----- LOVELY eh? Doh!!! Ninja workaround. Also returns a column vector rather than a row vector (usually what I want in such cases). DEFINE ParsePar ( !Pos !CHAREND ("/") /!POS !CMDEND). +  COMPUTE ParseErr=0. +  COMPUTE #Z={!1}. +  DO IF NCOL(#z) EQ 2. +    DO IF MSUM(ABS(MOD(#Z,1))) EQ 0. +      COMPUTE #Z={#Z,1}. +    ELSE. +      PRINT / TITLE "WARNING:  Non integer argument pairs should have explicit increment.". +      COMPUTE !2=T({!1}). +      COMPUTE ParseERR=1. +    END IF. +  ELSE IF NCOL(#z) EQ 1. +    COMPUTE #Z={#Z,#Z,1}. +  END IF. +  DO IF ParseErr=0. +    COMPUTE #M=MOD(#Z,1). +    COMPUTE #Pwr=1. +    DO IF MSUM(ABS(#M )) GT .0000001. +      LOOP. +        COMPUTE #Pwr=#Pwr*10. +        COMPUTE #Z=#Z*10. +        COMPUTE #M=MOD(#Z,1). +      END LOOP IF MSUM(ABS(#M)) LE .0000001. +    END IF. +    COMPUTE !2=T({#Z(1):#Z(2):#Z(3)}/#Pwr). +  END IF. !ENDDEFINE. MATRIX. ParsePar -.9,.9,.1 / ParOut . PRINT ParOut. END MATRIX. Run MATRIX procedure: PAROUT   -.9000000000   -.8000000000   -.7000000000   -.6000000000   -.5000000000   -.4000000000   -.3000000000   -.2000000000   -.1000000000    .0000000000    .1000000000    .2000000000    .3000000000    .4000000000    .5000000000    .6000000000    .7000000000    .8000000000    .9000000000 ------ END MATRIX ----- Please reply to the list and not to my personal email. Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Open this post in threaded view
|

## Re: TIP: Resolving non integer range constructors in MATRIX.

 Administrator David, doesn't this do what you want? MATRIX. COMPUTE x = t({-9:9:1} / 10). PRINT x. END MATRIX. OUTPUT: Run MATRIX procedure: X   -.9000000000   -.8000000000   -.7000000000   -.6000000000   -.5000000000   -.4000000000   -.3000000000   -.2000000000   -.1000000000    .0000000000    .1000000000    .2000000000    .3000000000    .4000000000    .5000000000    .6000000000    .7000000000    .8000000000    .9000000000 ------ END MATRIX ----- David Marso wrote Normally in matrix one can do the following. COMPUTE x={1:10:1}. resolves to {1,2,3,4,5,6,7,8,9,10} However : COMPUTE x={.1:.9,.1} One would expect/hope to receive {.1,.2,.3,.4,.5,.6,.7,.8,9}. Well, instead: MATRIX. COMPUTE x={.1: .9 : .1}. PRINT x. END MATRIX. Run MATRIX procedure: >Error encountered in source line #   150 >Warning # 12575 >Non-integer range values were specified.  Any non-integer range value will >be rounded to an integer. >Error encountered in source line #   150 >Error # 12557 >Increment value in the range operator is zero. >This command not executed. >Error encountered in source line #   151 >Error # 12492 >An attempt has been made to use previously undefined matrix (or scalar). >This command not executed. Matrix - 'X       ' is undefined >Error encountered in source line #   151 >Error # 12332 >Undefined variable in PRINT. ------ END MATRIX ----- LOVELY eh? Doh!!! Ninja workaround. Also returns a column vector rather than a row vector (usually what I want in such cases). DEFINE ParsePar ( !Pos !CHAREND ("/") /!POS !CMDEND). +  COMPUTE ParseErr=0. +  COMPUTE #Z={!1}. +  DO IF NCOL(#z) EQ 2. +    DO IF MSUM(ABS(MOD(#Z,1))) EQ 0. +      COMPUTE #Z={#Z,1}. +    ELSE. +      PRINT / TITLE "WARNING:  Non integer argument pairs should have explicit increment.". +      COMPUTE !2=T({!1}). +      COMPUTE ParseERR=1. +    END IF. +  ELSE IF NCOL(#z) EQ 1. +    COMPUTE #Z={#Z,#Z,1}. +  END IF. +  DO IF ParseErr=0. +    COMPUTE #M=MOD(#Z,1). +    COMPUTE #Pwr=1. +    DO IF MSUM(ABS(#M )) GT .0000001. +      LOOP. +        COMPUTE #Pwr=#Pwr*10. +        COMPUTE #Z=#Z*10. +        COMPUTE #M=MOD(#Z,1). +      END LOOP IF MSUM(ABS(#M)) LE .0000001. +    END IF. +    COMPUTE !2=T({#Z(1):#Z(2):#Z(3)}/#Pwr). +  END IF. !ENDDEFINE. MATRIX. ParsePar -.9,.9,.1 / ParOut . PRINT ParOut. END MATRIX. Run MATRIX procedure: PAROUT   -.9000000000   -.8000000000   -.7000000000   -.6000000000   -.5000000000   -.4000000000   -.3000000000   -.2000000000   -.1000000000    .0000000000    .1000000000    .2000000000    .3000000000    .4000000000    .5000000000    .6000000000    .7000000000    .8000000000    .9000000000 ------ END MATRIX ----- -- Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/"When all else fails, RTFM." NOTE: My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
Open this post in threaded view
|

## Re: TIP: Resolving non integer range constructors in MATRIX.

 Administrator It does, however I need users to be able to specify specific ranges without dealing with the internal logic. ex .5,.75,.01 ie start ,stop, increment This is a small piece of a larger simulation application and I need the UI to be very transparent. Bruce Weaver wrote David, doesn't this do what you want? MATRIX. COMPUTE x = t({-9:9:1} / 10). PRINT x. END MATRIX. OUTPUT: Run MATRIX procedure: X   -.9000000000   -.8000000000   -.7000000000   -.6000000000   -.5000000000   -.4000000000   -.3000000000   -.2000000000   -.1000000000    .0000000000    .1000000000    .2000000000    .3000000000    .4000000000    .5000000000    .6000000000    .7000000000    .8000000000    .9000000000 ------ END MATRIX ----- David Marso wrote Normally in matrix one can do the following. COMPUTE x={1:10:1}. resolves to {1,2,3,4,5,6,7,8,9,10} However : COMPUTE x={.1:.9,.1} One would expect/hope to receive {.1,.2,.3,.4,.5,.6,.7,.8,9}. Well, instead: MATRIX. COMPUTE x={.1: .9 : .1}. PRINT x. END MATRIX. Run MATRIX procedure: >Error encountered in source line #   150 >Warning # 12575 >Non-integer range values were specified.  Any non-integer range value will >be rounded to an integer. >Error encountered in source line #   150 >Error # 12557 >Increment value in the range operator is zero. >This command not executed. >Error encountered in source line #   151 >Error # 12492 >An attempt has been made to use previously undefined matrix (or scalar). >This command not executed. Matrix - 'X       ' is undefined >Error encountered in source line #   151 >Error # 12332 >Undefined variable in PRINT. ------ END MATRIX ----- LOVELY eh? Doh!!! Ninja workaround. Also returns a column vector rather than a row vector (usually what I want in such cases). DEFINE ParsePar ( !Pos !CHAREND ("/") /!POS !CMDEND). +  COMPUTE ParseErr=0. +  COMPUTE #Z={!1}. +  DO IF NCOL(#z) EQ 2. +    DO IF MSUM(ABS(MOD(#Z,1))) EQ 0. +      COMPUTE #Z={#Z,1}. +    ELSE. +      PRINT / TITLE "WARNING:  Non integer argument pairs should have explicit increment.". +      COMPUTE !2=T({!1}). +      COMPUTE ParseERR=1. +    END IF. +  ELSE IF NCOL(#z) EQ 1. +    COMPUTE #Z={#Z,#Z,1}. +  END IF. +  DO IF ParseErr=0. +    COMPUTE #M=MOD(#Z,1). +    COMPUTE #Pwr=1. +    DO IF MSUM(ABS(#M )) GT .0000001. +      LOOP. +        COMPUTE #Pwr=#Pwr*10. +        COMPUTE #Z=#Z*10. +        COMPUTE #M=MOD(#Z,1). +      END LOOP IF MSUM(ABS(#M)) LE .0000001. +    END IF. +    COMPUTE !2=T({#Z(1):#Z(2):#Z(3)}/#Pwr). +  END IF. !ENDDEFINE. MATRIX. ParsePar -.9,.9,.1 / ParOut . PRINT ParOut. END MATRIX. Run MATRIX procedure: PAROUT   -.9000000000   -.8000000000   -.7000000000   -.6000000000   -.5000000000   -.4000000000   -.3000000000   -.2000000000   -.1000000000    .0000000000    .1000000000    .2000000000    .3000000000    .4000000000    .5000000000    .6000000000    .7000000000    .8000000000    .9000000000 ------ END MATRIX ----- Please reply to the list and not to my personal email. Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Open this post in threaded view
|

## Re: TIP: Resolving non integer range constructors in MATRIX.

 Note that the MATRIX documentation says Incremented Ranges of Integers. Use a second colon followed by an integer to indicate the increment. The matrix {1,3,5,7;2,5,8,11} can be written as {1:7:2;2:11:3}, where 1:7:2 indicates the integers from 1 to 7 incrementing by 2, and 2:11:3 indicates the integers from 2 to 11 incrementing by 3. �� You must use integers when specifying a range in either of these ways. Numbers with fractional parts are truncated to integers. A little Python code would solve this easily, however. Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From:        David Marso <[hidden email]> To:        [hidden email], Date:        04/20/2013 08:19 PM Subject:        Re: [SPSSX-L] TIP: Resolving non integer range constructors in              MATRIX. Sent by:        "SPSSX(r) Discussion" <[hidden email]> It does, however I need users to be able to specify specific ranges without dealing with the internal logic. ex .5,.75,.01 ie start ,stop, increment This is a small piece of a larger simulation application and I need the UI to be very transparent. Bruce Weaver wrote > David, doesn't this do what you want? > > MATRIX. > COMPUTE x = t({-9:9:1} / 10). > PRINT x. > END MATRIX. > > OUTPUT: > Run MATRIX procedure: > > X >   -.9000000000 >   -.8000000000 >   -.7000000000 >   -.6000000000 >   -.5000000000 >   -.4000000000 >   -.3000000000 >   -.2000000000 >   -.1000000000 >    .0000000000 >    .1000000000 >    .2000000000 >    .3000000000 >    .4000000000 >    .5000000000 >    .6000000000 >    .7000000000 >    .8000000000 >    .9000000000 > > ------ END MATRIX ----- > > David Marso wrote >> Normally in matrix one can do the following. >> COMPUTE x={1:10:1}. >> resolves to {1,2,3,4,5,6,7,8,9,10} >> However : >> COMPUTE x={.1:.9,.1} >> One would expect/hope to receive {.1,.2,.3,.4,.5,.6,.7,.8,9}. >> Well, instead: >> >> MATRIX. >> COMPUTE x={.1: .9 : .1}. >> PRINT x. >> END MATRIX. >> Run MATRIX procedure: >>>Error encountered in source line #   150 >> >>>Warning # 12575 >>>Non-integer range values were specified.  Any non-integer range value will >>>be rounded to an integer. >> >>>Error encountered in source line #   150 >> >>>Error # 12557 >>>Increment value in the range operator is zero. >>>This command not executed. >> >>>Error encountered in source line #   151 >> >>>Error # 12492 >>>An attempt has been made to use previously undefined matrix (or scalar). >>>This command not executed. >> >> Matrix - 'X       ' is undefined >>>Error encountered in source line #   151 >> >>>Error # 12332 >>>Undefined variable in PRINT. >> >> >> ------ END MATRIX ----- >> >> LOVELY eh? >> Doh!!! >> Ninja workaround. >> Also returns a column vector rather than a row vector (usually what I >> want in such cases). >> >> >> DEFINE ParsePar ( !Pos !CHAREND ("/") /!POS !CMDEND). >> +  COMPUTE ParseErr=0. >> +  COMPUTE #Z={!1}. >> +  DO IF NCOL(#z) EQ 2. >> +    DO IF MSUM(ABS(MOD(#Z,1))) EQ 0. >> +      COMPUTE #Z={#Z,1}. >> +    ELSE. >> +      PRINT / TITLE "WARNING:  Non integer argument pairs should have >> explicit increment.". >> +      COMPUTE !2=T({!1}). >> +      COMPUTE ParseERR=1. >> +    END IF. >> +  ELSE IF NCOL(#z) EQ 1. >> +    COMPUTE #Z={#Z,#Z,1}. >> +  END IF. >> >> +  DO IF ParseErr=0. >> +    COMPUTE #M=MOD(#Z,1). >> +    COMPUTE #Pwr=1. >> +    DO IF MSUM(ABS(#M )) GT .0000001. >> +      LOOP. >> +        COMPUTE #Pwr=#Pwr*10. >> +        COMPUTE #Z=#Z*10. >> +        COMPUTE #M=MOD(#Z,1). >> +      END LOOP IF MSUM(ABS(#M)) LE .0000001. >> +    END IF. >> +    COMPUTE !2=T({#Z(1):#Z(2):#Z(3)}/#Pwr). >> +  END IF. >> !ENDDEFINE. >> >> MATRIX. >> ParsePar -.9,.9,.1 / ParOut . >> PRINT ParOut. >> END MATRIX. >> >> Run MATRIX procedure: >> >> PAROUT >>   -.9000000000 >>   -.8000000000 >>   -.7000000000 >>   -.6000000000 >>   -.5000000000 >>   -.4000000000 >>   -.3000000000 >>   -.2000000000 >>   -.1000000000 >>    .0000000000 >>    .1000000000 >>    .2000000000 >>    .3000000000 >>    .4000000000 >>    .5000000000 >>    .6000000000 >>    .7000000000 >>    .8000000000 >>    .9000000000 >> >> ------ END MATRIX ----- ----- Please reply to the list and not to my personal email. Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/TIP-Resolving-non-integer-range-constructors-in-MATRIX-tp5719604p5719606.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Open this post in threaded view
|

## Re: TIP: Resolving non integer range constructors in MATRIX.

Open this post in threaded view
|

## Re: TIP: Resolving non integer range constructors in MATRIX.

 In reply to this post by David Marso I  remember this sort of intransigent problem from my earliestdays of learning Fortran -- There is unfortunate ambiguity whenthe units and increments cannot be expressed with exact precisionin the underlying binary numbers.  Thus, 0.5 and 0.75 are fine, but0.01  is approximated to umpteen digits.  The resulting loops havethe risk of including an extra iteration.  Or falling short by one. If there's a classical compiler solution that avoids all error, I don't remember it. The pragmatic solution that I know of is to eventually use some version of Bruce's answer.   The mostly-safe way is to parse the user'sentry so that you do not risk the roundoff error.  Another way is tomultiply what the user enters (by 100, by 1000?), add a tiny fractionand truncate; then use fixed code with a fixed division.-- Rich Ulrich > Date: Sat, 20 Apr 2013 19:19:16 -0700> From: [hidden email]> Subject: Re: TIP: Resolving non integer range constructors in MATRIX.> To: [hidden email]> > It does, however I need users to be able to specify specific ranges without> dealing with the internal logic.> ex .5,.75,.01> ie start ,stop, increment> This is a small piece of a larger simulation application and I need the UI> to be very transparent.> > Bruce Weaver wrote> > David, doesn't this do what you want?> >> > MATRIX.> > COMPUTE x = t({-9:9:1} / 10).> > PRINT x.> > END MATRIX.> >> > OUTPUT:> > Run MATRIX procedure:> >> > X> > -.9000000000> > -.8000000000> > -.7000000000> > -.6000000000> > -.5000000000> > -.4000000000> > -.3000000000> > -.2000000000> > -.1000000000> > .0000000000> > .1000000000> > .2000000000> > .3000000000> > .4000000000> > .5000000000> > .6000000000> > .7000000000> > .8000000000> > .9000000000> >> > ------ END MATRIX -----> >> > David Marso wrote> >> Normally in matrix one can do the following.> >> COMPUTE x={1:10:1}.> >> resolves to {1,2,3,4,5,6,7,8,9,10}> >> However :> >> COMPUTE x={.1:.9,.1}> >> One would expect/hope to receive {.1,.2,.3,.4,.5,.6,.7,.8,9}.> >> Well, instead:> >>> >> MATRIX.> >> COMPUTE x={.1: .9 : .1}.> >> PRINT x.> >> END MATRIX.> >> Run MATRIX procedure:> >>>Error encountered in source line # 150> >>> >>>Warning # 12575> >>>Non-integer range values were specified. Any non-integer range value> will> >>>be rounded to an integer.> >>> >>>Error encountered in source line # 150> >>> >>>Error # 12557> >>>Increment value in the range operator is zero.> >>>This command not executed.> >>> >>>Error encountered in source line # 151> >>> >>>Error # 12492> >>>An attempt has been made to use previously undefined matrix (or scalar).> >>>This command not executed.> >>> >> Matrix - 'X ' is undefined> >>>Error encountered in source line # 151> >>> >>>Error # 12332> >>>Undefined variable in PRINT.> >>> >>> >> ------ END MATRIX -----> >>> >> LOVELY eh?> >> Doh!!!> >> Ninja workaround.> >> Also returns a column vector rather than a row vector (usually what I> >> want in such cases).> >>> >>> >> DEFINE ParsePar ( !Pos !CHAREND ("/") /!POS !CMDEND).> >> + COMPUTE ParseErr=0.> >> + COMPUTE #Z={!1}.> >> + DO IF NCOL(#z) EQ 2.> >> + DO IF MSUM(ABS(MOD(#Z,1))) EQ 0.> >> + COMPUTE #Z={#Z,1}.> >> + ELSE.> >> + PRINT / TITLE "WARNING: Non integer argument pairs should have> >> explicit increment.".> >> + COMPUTE !2=T({!1}).> >> + COMPUTE ParseERR=1.> >> + END IF.> >> + ELSE IF NCOL(#z) EQ 1.> >> + COMPUTE #Z={#Z,#Z,1}.> >> + END IF.> >>> >> + DO IF ParseErr=0.> >> + COMPUTE #M=MOD(#Z,1).> >> + COMPUTE #Pwr=1.> >> + DO IF MSUM(ABS(#M )) GT .0000001.> >> + LOOP.> >> + COMPUTE #Pwr=#Pwr*10.> >> + COMPUTE #Z=#Z*10.> >> + COMPUTE #M=MOD(#Z,1).> >> + END LOOP IF MSUM(ABS(#M)) LE .0000001.> >> + END IF.> >> + COMPUTE !2=T({#Z(1):#Z(2):#Z(3)}/#Pwr).> >> + END IF.> >> !ENDDEFINE.> >>> >> MATRIX.> >> ParsePar -.9,.9,.1 / ParOut .> >> PRINT ParOut.> >> END MATRIX.> >>> >> Run MATRIX procedure:> >>> >> PAROUT> >> -.9000000000> >> -.8000000000> >> -.7000000000> >> -.6000000000> >> -.5000000000> >> -.4000000000> >> -.3000000000> >> -.2000000000> >> -.1000000000> >> .0000000000> >> .1000000000> >> .2000000000> >> .3000000000> >> .4000000000> >> .5000000000> >> .6000000000> >> .7000000000> >> .8000000000> >> .9000000000> >>> >> ------ END MATRIX -----> ...
Open this post in threaded view
|

## Re: TIP: Resolving non integer range constructors in MATRIX.

Open this post in threaded view
|

## Re: TIP: Resolving non integer range constructors in MATRIX.

Open this post in threaded view
|

## Re: TIP: Resolving non integer range constructors in MATRIX.

Open this post in threaded view
|

## Re: TIP: Resolving non integer range constructors in MATRIX.

Open this post in threaded view
|

## Re: TIP: Resolving non integer range constructors in MATRIX.

Open this post in threaded view
|

## Autosvar: TIP: Resolving non integer range constructors in MATRIX.

 Hello, Thank you for your mail. I am out of the office till 23th of the April.  If urgent, please call or send a text message to +46708179069. Best regards, Jazgul Ismailova LynxEye brand consultants