Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 :) .

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:

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

BM
Posted
Updated 20-Sep-18 23:30pm
v2

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?
:)
 
Share this answer
 
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)?
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900