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

  • Home
  • SEARCH
  • 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 8626573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:03:56+00:00 2026-06-12T08:03:56+00:00

I’m rather new to coding and have been building a code to interpolate a

  • 0

I’m rather new to coding and have been building a code to interpolate a cubic spline, but I am stuck on the last equation do the following error: _”invalid operands to binary ^ (have ‘double’ and ‘double’)|”

The problem is in the last bit of the code with “population =” for the two first lines. I would really appreciate it if someone could point me in the right direction.

#include <stdio.h>


main () {

    int x;
    int y;
    double stats[10][2];
    double gpp[8][9] = {0};
    double gppr[10] = {0};
    double year;
    double population;
    int xi = 0;
    year=1950;
    population=0;
    x=0;

    stats[0][0] = 1930; stats[1][0] = 1940; stats[2][0] = 1949;
    stats[3][0] = 1955; stats[4][0] = 1960; stats[5][0] = 1970;
    stats[6][0] = 1980; stats[7][0] = 1990; stats[8][0] = 2000;
    stats[9][0] = 2005;

    stats[0][1] = 21.058; stats[1][1] = 23.547; stats[2][1] = 20.167;
    stats[3][1] = 21.502; stats[4][1] = 24.989; stats[5][1] = 30.852; 
    stats[6][1] = 37.407; stats[7][1] = 43.390; stats[8][1] = 45.985;
    stats[9][1] = 47.041;

    //Initiate  g'' system of equation
    for (x=0;x<8;x++) {
        gpp[x][x] = ((stats[x+1][0]-stats[x][0])+(stats[x+2][0]-stats[x+1][0]))/3;
        if (x<7) {
            gpp[x][x+1] = (stats[x+2][0]-stats[x+1][0])/6;
        }
        if (x>0) {
            gpp[x][x-1] = (stats[x+2][0]-stats[x+1][0])/6;
        }
        gpp[x][8] = ((stats[x+2][1]-stats[x+1][1])/(stats[x+2][0]-stats[x+1][0]))-((stats[x+1][1]-stats[x][1])/(stats[x+1][0]-stats[x][0]));
    }

    //Forward sweep
    for (x=0;x<7;x++) {
        gpp[x+1][x] = 0;
        gpp[x+1][x+1] = gpp[x+1][x+1] - (gpp[x][x+1]/gpp[x][x])*gpp[x+1][x];
        gpp[x+1][8] = gpp[x+1][8] - (gpp[x][x+1]/gpp[x][x])*gpp[x][8];
    }
    //Backward sweep
    gppr[9] = 0;gppr[0] = 0;
    gppr[8] = gpp[7][8]/gpp[7][7];
    for (x=7;x > 0;x=x-1) {
        gppr[x] = (gpp[x][8]-(gppr[x+1]*gpp[x][x+1]))/gpp[x][x];
    }

    //check where is xi
    for (x=0;x<10;x++) {
        if (stats[x][0] > year) {
            xi = x;
            break;
        }
    }

//Calculate population at x
population = (gppr[xi]/6)*((((stats[xi+1][0]-year)^3.0)/(stats[xi+1][0]-stats[xi][0]))-(stats[xi+1][0]-stats[xi][0])*((stats[xi+1][0]-year)))
       + (gppr[xi+1]/6)*((((year-stats[xi][0])^3.0)/(stats[xi+1][0]-stats[xi][0]))-(stats[xi+1][0]-stats[xi][0])*((year-stats[xi+1][0])))
       + (stats[xi][1])*((stats[xi+1][0]-year)/(stats[xi+1][0]-stats[xi][0]))
       + (stats[xi+1][1])*((year-stats[xi][0])/(stats[xi+1][0]-stats[xi][0]));

}

I look forward to learning a little more about C!

Hugo

  • 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-12T08:03:57+00:00Added an answer on June 12, 2026 at 8:03 am

    ^ is the exclusive-OR operator in C and is unsuitable for doubles. It’s a bitwise operator and you can find more details on it (and the other bitwise operators) here.

    If you want to raise one number to the power of another, you need the pow() function.

    So something like:

    ((stats[xi+1][0]-year)^3.0)
    

    should actually be written:

    pow (stats[xi+1][0] - year, 3.0)
    

    Section 7.12.7.4 The pow functions of the latest (C11) standard states:

    Synopsis:
    #include <math.h>
    double pow(double x, double y);
    float powf(float x, float y);
    long double powl(long double x, long double y);

    Description:
    The pow functions compute x raised to the power y. A domain error occurs if x is finite
    and negative and y is finite and not an integer value. A range error may occur. A domain
    error may occur if x is zero and y is zero. A domain error or pole error may occur if x is
    zero and y is less than zero.

    The pow functions return xy.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but

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.