Click here to Skip to main content
12,297,913 members (56,700 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C++
Hello,

I have been trying to curve fit a smooth and slightly oscillating curve. I have already tried to model this curve in MATLAB using the built in function 'polyfit' and to graph it using 'polyval'. Modeling and graphing using MATLAB was successful Smile | :) .

The ultimate goal of mine is to write this program in C++ in which I can model and retrieve polynomial coefficients using least squares fit. I was partially successful writing this program, however, the results compared to MATLAB result were not correct. I assume that the results I get from MATLAB is correct and this is a fairly good assumption for my case.

As a reference, I have used this sample program someone already has written, http://www.nr.com/forum/showthread.php?t=1452[^]. This program is evaluated using the headers from 'Numerical Recipes'.

I was wondering if there is any better way to approach the least squares fit problem. Confused | :confused:

Thank you for your time and hope to get some advise soon!

BM
Posted 31-May-10 7:32am
Edited 31-May-10 8:26am
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

What does you mean, exactly with
Jungyeoul Maeng wrote:
I was partially successful writing this program, however, the results compared to MATLAB result were not correct

?

What is unsatisfactory in your fit?
Smile | :)
  Permalink  
Comments
Jungyeoul Maeng 2-Jun-10 9:55am
   
The result I get from MATLAB and C++ programs are off by as much as 30%. I believe that the curve fit from C++ does not quite match the ideal curve fit from MATLAB. I was looking for a more precise curve fit result from C++. Is there any reference I can take a look about least squares fit?
CPallini 2-Jun-10 14:04pm
   
How do you measure it (sorry for being nitpick)?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160525.2 | Last Updated 11 Feb 2011
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100