Beginner Needs Help (Least Squares Analysis

This is a discussion on Beginner Needs Help (Least Squares Analysis within the C Programming forums, part of the General Programming Boards category; I'm a beginner. I need to create a very basic C program. Basically the program has to perform least square ...

  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.
    Attached Images Attached Images  

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    I don't see any structure or mechanical errors with the code. Must be a formula issue.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    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,831
    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:
    Attached Images Attached Images  
    Last edited by kd001; 11-03-2009 at 03: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
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,230
    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, 01:11 PM

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