Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7622891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:34:07+00:00 2026-05-31T04:34:07+00:00

I am working with a MxM triangular matrix which has the following form: M

  • 0

I am working with a MxM triangular matrix which has the following form:

M = [m00 m10 m20 m30 m40]
    [m11 m21 m31 m41    ] 
    [m22 m32 m42        ]
    [m33 m43            ]
    [m44                ]

If it’s easier to picture this in terms of indexes, it would look like this:

M = [0 1 3 6 10]  
    [2 4 7 11  ]
    [5 8 12    ]
    [9 13      ]
    [14        ]

I know this way of indexing might look odd but it would be much easier if I could keep the indexing system as it is in order for this module to work well with others.

I am struggling with an algorithm that takes an index and size of the matrix that can return the row and column that the given index falls under. Ideally I would have 2 functions such as these:

int getRow (int index, int size);
int getCol (int index, int size);

So getRow (7, 5) would return 3

And getCol (7, 5) would return 1

I have come across this thread already but I cannot seem to modify the solution given there to work for the way I am indexing.

algorithm for index numbers of triangular matrix coefficients

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:34:08+00:00Added an answer on May 31, 2026 at 4:34 am

    New Answer

    You can find the row and column using the following formulas:

    int row = floor(-0.5 + sqrt(0.25 + 2 * index));
    int triangularNumber = row * (row + 1) / 2;
    int column = index - triangularNumber;
    

    This works because the first item in each row is a triangular number (0, 1, 3, 6, 10, 15, …). So the biggest triangular number that is lower than index gives us the row. Then column is simply the difference between index and that triangular number.

    Also, note that you don’t need the parameter M.


    Old Answer

    This code will give you both the row and column of index.

    int triangularNumber = 0;
    int row = 0;
    while (triangularNumber + row < index) {
        row ++;
        triangularNumber += row;
    }
    int column = index - triangularNumber;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working on a website that has Employee and Branch entities, using a database table
Working with python interactively, it's sometimes necessary to display a result which is some
Working SQL The following code works as expected, returning two columns of data (a
Working on a bunch of forms at the moment and I'm finding that I
Working on a rather small, and simple layout, I decided to use Meyer's CSS
Working on an irc client in Adobe AIR in JavaScript, and thinking about logging.
Working with Linq2Sql as a driver for a Wcf Service. Lets go bottom up....
Working on a movie website and would love to find an API that I
Working on a page with multiple sections. at the very top there is a
Working on my first Rails project, I used Ryan Bates' Nifty-Generators to create the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.