Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

General equation for a grid's internal nodes

  • 01-04-2008 7:40pm
    #1
    Registered Users, Registered Users 2 Posts: 3,615 ✭✭✭


    I wasn't sure whether to put this in programming or mathematics but I guess as It's just finding a general equation it gos here. Anyway


    If I have an NxM grid like so (N = 6 and M = 5 in this case)

    x x x x x x

    x x x x x x

    x x x x x x

    x x x x x x

    x x x x x x


    Where N = no. of columns
    M = no. of rows

    I need an equation of the form Q = f(N,j,i)

    Where j is the column number and i is the row number

    and Q is the number of an internal node


    For this one, if j = 2 and i = 2, Q = 1 as shown below



    x x x x x x

    x 1 2 3 4 x

    x 5 6 7 8 x

    x x x x x x

    The general equation is

    Q = (j-1)*N + i + c

    c for 6x5 happens to be = -N - i + 1


    What I need to do is find a general equation that will calculate the internal node numbers as a function of j,N,i,M (not sure if you use M) that will still work if I change N and M

    I'm pretty sure only c changes as the no. of columns and rows increase so I guess an expression for c is what I need

    for example I need an equation which will work for not just a 6x5 but for any combination of rows and columns. (They'll be getting larger)

    I need it to work no matter what N and M are. There could be 71 columns and 51 rows


    Is it possible to do this? Any help would be great my brain's fried from sitting in front of matlab for hours and can't think straight.

    Cheers


Comments

  • Registered Users, Registered Users 2 Posts: 1,595 ✭✭✭MathsManiac


    Q=(i-2)*(N-2)+(j-1)


  • Registered Users, Registered Users 2 Posts: 3,615 ✭✭✭Mr.Plough


    Great stuff thanks. As a matter of interest how did you come to that eqn?


  • Registered Users, Registered Users 2 Posts: 1,595 ✭✭✭MathsManiac


    If it weren't for the X's around the edge, then to get to the Qth position you would count (i-1) rows of N and then go across (i.e. add) j. [That would give Q= (i-1)*N + j.] The X's on the left and right of every row means your count has jumped to a new row on every N-2 instead of every N, and the row that you're not counting at the start means you need i-2 instead of i-1. Then, on the row you're actually in, the fact that you've an X at the start means you need j-1 instead of j.

    Finally, you check that it works!


Advertisement