Check difference between two vectors

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shapper

    Check difference between two vectors

    Hello,

    Is it possible given two vectors, A and B, create a third vector, C,
    using the following conditions, without a loop?

    D = A - B

    If D(i) * D(i-1) < 0 and D(i) 0 then C(i) = 1

    If D(i) * D(i-1) < 0 and D(i) < 0 then C(i) = -1

    If D(i) * D(i-1) 0 then C(i) = 0

    ---

    If D(i) * D(i-1) = 0 then

    If D(i) * D(i-2) < 0 and D(i) 0 then C(i) = 1

    If D(i) * D(i-2) < 0 and D(i) < 0 then C(i) = -1

    If D(i) * D(i-2) 0 then C(i) = 0

    end

    Basically I am creating a function that detects when a function
    crosses under or over another function or a constant level ...

    This was what I came up with ...
    .... the second part is because sometimes the values can be equal
    before the cross occurs ...

    I am trying to make this with vectors.

    Thank You,
    Miguel
  • shapper

    #2
    Re: Check difference between two vectors

    On Feb 15, 4:36 pm, shapper <mdmo...@gmail. comwrote:
    Hello,
    >
    Is it possible given two vectors, A and B, create a third vector, C,
    using the following conditions, without a loop?
    >
    D = A - B
    >
    If D(i) * D(i-1) < 0 and D(i) 0 then C(i) = 1
    >
    If D(i) * D(i-1) < 0 and D(i) < 0 then C(i) = -1
    >
    If D(i) * D(i-1) 0 then C(i) = 0
    >
    ---
    >
    If D(i) * D(i-1) = 0 then
    >
    If D(i) * D(i-2) < 0 and D(i) 0 then C(i) = 1
    >
    If D(i) * D(i-2) < 0 and D(i) < 0 then C(i) = -1
    >
    If D(i) * D(i-2) 0 then C(i) = 0
    >
    end
    >
    Basically I am creating a function that detects when a function
    crosses under or over another function or a constant level ...
    >
    This was what I came up with ...
    ... the second part is because sometimes the values can be equal
    before the cross occurs ...
    >
    I am trying to make this with vectors.
    >
    Thank You,
    Miguel
    Ooops, forget it. I posted this on the wrong group.

    Sorry,
    Miguel

    Comment

    Working...