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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:44:27+00:00 2026-06-01T10:44:27+00:00

I’m writing a program that sends an array through a function (upperhess) that will

  • 0

I’m writing a program that sends an array through a function (upperhess) that will turn it from a square nxn matrix into an upper hessenberg matrix. This is running fine, but then i need to send the array through another function, which I am having an issue with. I need to make a double equal to the first element of the array. However, instead it is setting the double (mu) equal to zero. I included my code below


#include <stdio.h>
#include <math.h>


int idx(int r, int c, int n)
{
    return r * n + c;
}

void transpose(double *a, int n, double *at)
{
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            at[(idx (i, j, n))] = a[(idx (j, i, n))];
        }
    }
}

void matrix_multiplication(double *a, double *b, int n, double *combo)
{

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            combo[(idx(i, j, n))] = 0;
            for (int k = 0; k < n; k++) {
                combo[(idx(i, j, n))] +=  a[(idx(i, k, n))] * b[(idx(k, j, n))];
            }
        }
    }

}

void identity(double *a, int n)
{
    for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j) {
                    a[(idx(i, j, n))] = 1;
                }
                else {
                    a[(idx(i, j, n))] = 0;
                }
            }
        }
}

void upperhes(double *a, int n, double *u, double *b)
{

    //Sets b equal to a
    for (int i = 0; i < (n*n); i++) {
        b[i] = a[i];
    }

    //Sets u equal to the identity matrix
    identity(u, n);

    int times = 0;
    for (int i = 0; i < (n-2); i++) {
        for (int j = n-1; j > (1 + times); j--) {
            double c, s, r;

            r = sqrt((b[(idx(j-1,i,n))] * b[(idx(j-1,i,n))]) + (b[(idx(j,i,n))] * b[(idx(j,i,n))]));
            if (r < 0) {
                r = (-1 * r);
            }
            if (r < pow(10,-50)) {
                c = 1;
                s = 0;
            }
            else {
                c = b[(idx(j-1, i, n))] / r;
                s = (-1 * b[(idx(j, i, n))]) / r;
            }

            //store takes the original values of specific points in matrix b and stores them, so the values of b can be manipulated
            double store[6];

            store[0] = b[(idx(j-1, i,n))];
            store[1] = b[(idx(j,i,n))];
            store[4] = b[(idx(i,j-1,n))];
            store[5] = b[(idx(i,j,n))];


            b[(idx (j,i,n))] = (s * store[0]) + (c * store[1]);
            b[(idx(j-1,i,n))] = (c * store[0]) + (-s * store[1]);

            for (int k= i+1; k<n; k++) {

                store[2] = b[(idx(j-1,k,n))];
                store[3] = b[(idx(j,k,n))];

                b[(idx(j-1,k,n))] = (c * store[2]) - (s * store[3]);
                b[(idx(j,k,n))] = (s * store[2]) + (c * store[3]);
            }


            b[(idx (i, j, n))] = (s * store[4]) + (c * store[5]);
            b[(idx (i, j-1, n))] = (c * store[4]) - (s * store[5]);

            for (int k = i + 1; k < n; k++) {

                store[2] = b[(idx(k, j-1, n))];
                store[3] = b[(idx(k, j, n))];

                b[idx(k, j-1, n)] = (c * store[2]) - (s * store[3]);
                b[idx(k, j, n)] = (s * store[2]) + (c * store[3]);
            }


            store[0] = u[(idx(j-1, 0, n))];
            store[1] = u[(idx(j, 0, n))];

            u[idx (j, 0, n)] = (s * store[0]) + (c * store[1]);
            u[idx(j-1, 0, n)] = (c * store[0]) + (-s * store[1]);

            for (int k= 1; k<n; k++) {

                store[2] = u[idx(j-1, k, n)];
                store[3] = u[idx(j, k, n)];

                u[idx(j-1, k, n)] = (c * store[2]) - (s * store[3]);
                u[idx(j, k, n)] = (s * store[2]) + (c * store[3]);
            }
        }

        times++;

    }

    //Sets ut equal to the transpose of u
    double ut[n*n];
    transpose(u, n, ut);

    //Multiplies u and a together.
    double ua[(n*n)];
    matrix_multiplication(u, a, n, ua);

    double b_check[(n*n)];
    matrix_multiplication(ua, ut, n, b_check);

    //Prints out the matrix!
    for(int i=0; i<n; i++){
        for(int j =0; j<n; j++){
            printf("(%+.3f)\t", b[(idx (i,j,n))]);
        }
        printf("\n\n");
    }
    printf("\n");

}

void two_through_five(double *b, int n, double *eigenvalues, int total)
{

    for (int times = 0; times < 100; times++){

        double mu = b[0];

        ..........
    }
}

void qr_symmetric(double *a, int n, double *b)
{

    //Creates a tridiagonal matrix by using a method that creates upper Hessenberg matrices on a symmetrical matrix a.
    double u[n * n];
    upperhes(a, n, u, b);

    //Creates an array to store the eigenvalues
    double eigenvalues[n];

    two_through_five(b, n, eigenvalues, n);
    for (int i = 0; i < n; i++) {
        printf("%d\t", eigenvalues[n]);
    }
    printf("\n");

}

int main(void)
{
    int n;
    n = 4;
    double a[(n*n)];
    a[0] = 1;
    a[1] = 2;
    a[2] = 3;
    a[3] = 4;
    a[4] = 2;
    a[5] = 6;
    a[6] = 7;
    a[7] = 8;
    a[8] = 3;
    a[9] = 7;
    a[10] = 11;
    a[11] = 15;
    a[12] = 4;
    a[13] = 8;
    a[14] = 15;
    a[15] = 16;
    double b[n * n];
    qr_symmetric(a, n, b);
    return 0; 
}
  • 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-01T10:44:29+00:00Added an answer on June 1, 2026 at 10:44 am

    Your code shoud work. For instance, this works for me:

    void two_through_five(double *b, int n, double *eigenvalues, int total)
    {
        int times;
        for (times = 0; times < 100; times++)
        {
            double mu = b[0];
            printf("%f\n", mu);
        }
    }
    
    int main()
    {
    
       int n = 18;
       int i =0;
    
       double * b = malloc(n*sizeof(double));
    
       for( i=0; i<n;i++) b[i] = 15.0;
    
       double eigenvalues[n];
    
       two_through_five(b, n, eigenvalues, n);
    
       return 0;
    }
    

    Outupts:

    15.000000
    15.000000
    15.000000
    15.000000
    15.000000
    15.000000
    15.000000
    15.000000
    15.000000
    ...
    

    So my quedtion is, are you sure b[0] is not 0?

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

Sidebar

Related Questions

I need a function that will clean a strings' special characters. I do NOT
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

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.