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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:43:22+00:00 2026-06-02T20:43:22+00:00

I am coding a matrix, whose entries are polynomials with rational coefficients. Any help

  • 0

I am coding a matrix, whose entries are polynomials with rational coefficients. Any help would be greatly appreciated.
I have rational number and rational polynomial declared:
rational_number.h

struct long_rational{
    long p;
    long q;
    };

typedef struct long_rational rational;

polynomial.h

#define MAX_DEGREE 200

struct rational_polynomial{
    long degree;
    rational coef[MAX_DEGREE]; //rational coefficients in increase power.
};

typedef struct rational_polynomial polynomial;

poly_mat.c in its entirety

#include "poly_mat.h"

#define NR_END 1
#define FREE_ARG char*

polynomial **poly_matrix( long nrl, long nrh, long ncl, long nch )
/* allocates a matrix with polynomial entries in the range m[nrl..nrh][ncl..nch] */
{
    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    polynomial **m;
    /* allocate pointers to rows */
    m=( polynomial ** ) malloc( ( size_t )( ( nrow+NR_END )*sizeof( polynomial* ) ) );
    if ( !m ) nrerror( "allocation failure 1 in matrix()" );
    m += NR_END;
    m -= nrl;
    /* allocate rows and set pointers to them */
    m[nrl]=( polynomial * ) malloc( ( size_t )( ( nrow*ncol+NR_END )*sizeof( polynomial ) ) );
    if ( !m[nrl] ) nrerror( "allocation failure 2 in matrix()" );
    m[nrl] += NR_END;
    m[nrl] -= ncl;
    for ( i=nrl+1; i<=nrh; i++ ) m[i]=m[i-1]+ncol;
    /* return pointer to array of pointers to rows */
    return m;
}

void **free_poly_matrix( polynomial **m, long nrl, long nrh, long ncl, long nch )
/* free a polynomial matrix allocated by poly_matrix() */
{
    free( ( FREE_ARG ) ( m[nrl]+ncl-NR_END ) );
    free( ( FREE_ARG ) ( m+nrl-NR_END ) );
}

void init_random_poly_matrix( int **m, long nrl, long nrh, long ncl, long nch )
/* initialize a random polynomial matrix with coefficient <=100*/
{
    long i,j;
    long iseed = ( long )time( NULL );
    srand ( iseed );
    for ( i=nrl; i<=nrh; i++ )
    {
        for ( j=ncl; j<=nch; j++ )
        {
            m[i][j].degree=( rand()%MAX_DEGREE );
            for ( k=0;k<=MAX_DEGREE;k++ )
            {
                m[i][j].coef[k].p = (rand()%100 );
                m[i][j].coef[k].q = (1+rand()%100 );
            }
        }
    }
}

Here is the enigmatic error message:

gcc -Wall   -c -o poly_mat.o poly_mat.c
poly_mat.c: In function ‘init_random_poly_matrix’:
poly_mat.c:6: error: expected declaration specifiers before ‘(’ token
poly_mat.c:28: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
poly_mat.c:35: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
poly_mat.h:14: error: old-style parameter declarations in prototyped function definition
poly_mat.c:51: error: expected ‘{’ at end of input
make: *** [poly_mat.o] Error 1

poly_mat.h with missing semicolon filled.

#ifndef POLY_MAT_H
#define POLY_MAT_H

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "nrutil.h"
#include "rational_number.h"
#include "polynomial.h"

/* matrix with polynomial entries */
polynomial **poly_matrix( long nrl, long nrh, long ncl, long nch );
void init_random_poly_matrix( int **m, long nrl, long nrh, long ncl, long nch );
void **free_poly_matrix( polynomial **m, long nrl, long nrh, long ncl, long nch );

#endif

Now I can not access member of polynomials in the array with dot operator.
New Error Message:

gcc -Wall   -c -o poly_mat.o poly_mat.c
poly_mat.c: In function ‘init_random_poly_matrix’:
poly_mat.c:43: error: request for member ‘degree’ in something not a structure or union
poly_mat.c:46: error: request for member ‘coef’ in something not a structure or union
poly_mat.c:47: error: request for member ‘coef’ in something not a structure or union
make: *** [poly_mat.o] Error 1

Edit 2: Found the mistake. declare it as int** instead of polynomial**.

  • 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-02T20:43:24+00:00Added an answer on June 2, 2026 at 8:43 pm

    without knowin poly_mat.h, but I grok the errormessage, that there is an syntactic error in poly_mat.h. I believe there is a missing bracket/brace or semikolon in or before line 14 while declaring the prototype for init_random_poly_matrix().

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

Sidebar

Related Questions

I have a small problem in coding confusion 3x3 matrix by using matlab... I
The coding below seperates the $state data, I need help putting the var_dump info
I have a sparse matrix that is not symmetric I.E. the sparsity is somewhat
I am trying to implement matrix multiplication usign OpenCL. I have an ATI Radeon
Coding in ASP.NET 4.0 / javascript/ jQuery/ WebServices The Scenario I have an analytics
When coding up Ajax calls in ASP.Net MVC we have a lot of options
When doing matrix operations, I would like to be able to see what the
I have a 3d m x n x t matrix , I want to
I'm new to python, coming from matlab. I have a large sparse matrix saved
I have a sparsely populated matrix that's the result of a series of left

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.