forum.alglib.net http://forum.alglib.net/ |
|
Find Equation of Line http://forum.alglib.net/viewtopic.php?f=2&t=401 |
Page 1 of 1 |
Author: | KeeganWB [ Thu Jul 21, 2011 2:00 pm ] |
Post subject: | Find Equation of Line |
I am attempting to recreate some of the functionality of Excel. In Excel, I can list a set of x,y coordinates and get a trend line that has been interpolated from said points. I have figured out how to do this with Alglib by using the 'spline1dbuildakima' function. Here is my problem: In excel you can choose to display the equation for the generated line. How can I do this with Alglib? I have been trying to interpret spline1dunpack but have been unable to decipher the output, and am not completely sure that I am heading in the right direction. I have confirmed that spline1dbuildakima is generating the correct line because I have tested it using spline1dcalc and it gives me the same answers for x and y that excel does. Below is the code I am using to generate the spline and I have also included the equation that excel gives me. Any help would be incredible!! Code: double[] x = new double[] { 0, .0833, .1667, .2500, .3333, .4167, .5000, .5833, .6667, .7500, .8333, .9167, 1 }; double[] y = new double[] { 0, .0705, .1516, .2641, .4029, .5410, .6781, .7943, .9042, .9519, .9836, 1.0001, 1 }; alglib.spline1dinterpolant s; double[,] tbl; alglib.spline1dbuildakima(x, y, out s); Excel Generated Formula: y = -3.7835x6 + 16.075x5 - 22.714x4 + 11.198x3 - 0.576x2 + 0.8x + 0.0004 spline1dunpack Generated Data below; each object in spline1dunpack is new line below 0 0.0833 0 0.78333458944077 0.756349891637399 0 0.0833 0.1667 0.0705 0.909342481387561 0.218848190553835 6.44486452138571 0.1667 0.25 0.1516 1.08032928518305 2.79880068138734 5.34247324050666 0.25 0.3333 0.2641 1.65782198113364 0.323658066682665 -2.66846591971681 0.3333 0.4167 0.4029 1.65619484058598 -0.00288634351093913 -0.0113319095767315 0.4167 0.5 0.541 1.65547693915743 0.114945343057455 -2.76608260064354 0.5 0.5833 0.6781 1.61704620462046 -5.09875644452016 29.2032573511532 0.5833 0.6667 0.7943 1.37550795216743 1.17650000824958 -22.4111717098455 0.6667 0.75 0.9042 1.10410140504906 -10.9086700546181 54.3631419609296 0.75 0.8333 |
Author: | Doug Jenkins [ Fri Jul 22, 2011 5:09 am ] |
Post subject: | Re: Find Equation of Line |
You might find the spreadsheet here useful: http://newtonexcelbach.wordpress.com/20 ... on-update/ The spreadsheet has a VBA implementation of the Alglib spline functions, including open source code. Note that it uses version 2.6 (which is the latest VBA version), but the code should provide suitable examples of how to unpack the curve equations. Any questions, please ask. |
Author: | kima123 [ Sat Oct 22, 2011 2:08 am ] |
Post subject: | Re: Find Equation of Line |
That's very impressive equations and plotting. It's really great because I really need this..thanks Kima |
Page 1 of 1 | All times are UTC |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |