Challenging question.

This is a discussion on Challenging question. within the C Programming forums, part of the General Programming Boards category; Hello I have this question to do which I'm finding it really hard basically: I have to write a program ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    3

    Challenging question.

    Hello I have this question to do which I'm finding it really hard basically:

    I have to write a program to perform a least-squares analysis (also called linear regression) of the data shown below this page, and find the line of best-fit relating log velocity to magnitude. They have given me a start to this: which is shown in the attachment along with the data given.



    I calculated sumx, sum y, sumxx, and sumxy and inputted it into the program...but it was telling me to declare variables:

    j, m, nd, gradient, intercept, logvel


    so i declared j, m and nd to int and the others to a float...But it said that incorrect value or array. Clearly i'm missing a lot of code, but I just dont know how to go from here, if anyone can help i would really appreciate it,!


    Thanks a lot for your time
    From Steve
    Attached Files Attached Files

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    The code you attached is kinda unfinished so I can't check for a lot of things, but you cannot access arrays with floats or doubles. They're whole numbers. 0, 1, 2, 3, etc, not 1.1, 1.2, 1.3, 1.4, etc. So either do a cast or use ints.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Well, you seem to think that m[] and logvel[] should be arrays that hold the data. If that's true, you need to declare them as such. You also need to get the data into the array somehow. (Read from a file and take logarithms as necessary, I would guess.) Is nd your number of data? If so, you need to increment it as you read in a data point. Once you've got that, you're calculations look right at first glance.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21