# Check difference between two vectors

Discussion in 'ASP .Net' started by shapper, Feb 15, 2008.

1. ### shapperGuest

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, Feb 15, 2008

2. ### shapperGuest

On Feb 15, 4:36 pm, shapper <> wrote:
> 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

shapper, Feb 15, 2008