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 8780833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:09:16+00:00 2026-06-13T20:09:16+00:00

I was trying to understand how to store a band matrix, I found an

  • 0

I was trying to understand how to store a band matrix, I found an example in the book “C++ and Object Oriented Numeric Computing” but I cannot figure out what’s the purpose of the line bda[i] += P; and this also gives me problems when trying to print the band matrix. Here it is:

int N = 5; //Matrix of NxN
int P = 1; //Left bandwidth
int R = 2; //Right bandwidth

//Matrix A
double A[5][5] = { { 1, 6, 10, 0, 0 },
        { 13, 2, 0, 11, 0 },
        { 0, 14, 3, 8, 12 },
        { 0, 0, 0, 4, 9 },
        { 0, 0, 0, 16, 5 } };

//Allocate memory for rows
double** bda = new double*[N];
for (int i = 0; i < N; i++) {
    bda[i] = new double[P + R + 1]; //Allocate memory for cols
    bda[i] += P; //What's the purpose of this?
}
  • 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-06-13T20:09:17+00:00Added an answer on June 13, 2026 at 8:09 pm

    This is used for a compact way to store a matrix that has P nonzero diagonals to the left of the main diagonal, and R nonzero diagonals to the right, with all other elements being zero. For each row, we only allocate space for the P+R+1 elements around the main diagonal.

    The bda[i] += P line makes bda[i] point to an element on the main diagonal. This can make it more convenient to use the matrix: bda[i][0] is on the main diagonal for every i, bda[i][1] is on the first diagonal to the right, bda[i][-1] is on the first diagonal to the left, etc. This allows you to find elements on the main diagonal or near it without having to add P each time. Whether this is helpful depends on how you use the matrix.

    Note that if you do this, you will need to subtract P from bda[i] before you delete[] it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a simple example to understand how to store then retrieve
I’m new to object oriented database designs and I’m trying to understand how I
Trying to understand the options for will_paginate's paginate method: :page — REQUIRED, but defaults
I'm trying to understand how shifting with SSE works, but I don't understand the
I'm learning Squeryl and trying to understand the 'using' syntax but can't find documentation
I am trying to understand how ThreadPool.QueueWorkItem method works. But couldn't understand how it
I am trying to understand how far I can go with PHP5's closures/callbacks, but
I am trying to figure out how C and C++ store large objects on
I am trying understand ViewModels deeper and I have read many articles and blogs
Trying to understand what's the correct way of implementing OpenID authentication with Spring Security.

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.