Thread: Beginner Needs Help (Least Squares Analysis

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    4

    Beginner Needs Help (Least Squares Analysis

    I'm a beginner. I need to create a very basic C program. Basically the program has to perform least square analysis on 8 sets of data. The program needs to read the values (magnitude and velocity) from the keyboard. Magnitude is the x value and logvelocity is the y value. The program does work but its not giving me the correct results. Some help will be much appreciate. I have attached my attempt. Please keep it as simple as possible.

    Thanks a lot.

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    I don't see any structure or mechanical errors with the code. Must be a formula issue.
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I don't see any formula issues compared to Linear least squares - Wikipedia, the free encyclopedia either at first glance. First thing I would check, you're using "log", which computes ln. If you want to compute log, you need to use "log10".

  4. #4
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    You are not using the array logv[], but are assigning the logarithm of v[] into y[]...
    So maybe it has something to do with that. Formula/correct variable issue.

  5. #5
    Registered User
    Join Date
    Nov 2009
    Posts
    4
    These are the formulae. For some reason the program is not doing that:
    Last edited by kd001; 11-03-2009 at 04:37 PM.

  6. #6
    Registered User
    Join Date
    Nov 2009
    Posts
    4
    'tabstop' may be onto something. I should calculate log10velocity so when I get the chance I will try changing it to log10.

  7. #7
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by kd001 View Post
    The program does work but its not giving me the correct results.
    That's a strange definition of "works."
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  8. #8
    Registered User
    Join Date
    Nov 2009
    Posts
    4
    Quote Originally Posted by brewbuck View Post
    That's a strange definition of "works."
    By works I just meant it compiles and runs.


    Anyway changing from log to log10 solved the problem. Thanks to all those who gave their advice.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Generating an image of squares?
    By vopo in forum C# Programming
    Replies: 3
    Last Post: 10-21-2008, 10:15 AM
  2. Same old beginner question...
    By Sharmz in forum C Programming
    Replies: 15
    Last Post: 08-04-2008, 11:48 AM
  3. Forced moves trouble!!
    By Zishaan in forum Game Programming
    Replies: 0
    Last Post: 03-27-2007, 06:57 PM
  4. Dev-C++ Profile Analysis
    By Orborde in forum C++ Programming
    Replies: 0
    Last Post: 05-28-2005, 01:37 AM
  5. rhetorical analysis and why it is for YOU!
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 03-30-2003, 02:11 PM