forum.alglib.net

ALGLIB forum
It is currently Sun Dec 22, 2024 7:41 pm

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Find Equation of Line
PostPosted: Thu Jul 21, 2011 2:00 pm 
Offline

Joined: Thu Jul 21, 2011 1:44 pm
Posts: 3
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


Top
 Profile  
 
 Post subject: Re: Find Equation of Line
PostPosted: Fri Jul 22, 2011 5:09 am 
Offline

Joined: Sun May 16, 2010 11:42 pm
Posts: 63
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.

_________________
Doug Jenkins
http://newtonexcelbach.wordpress.com/


Top
 Profile  
 
 Post subject: Re: Find Equation of Line
PostPosted: Sat Oct 22, 2011 2:08 am 
Offline

Joined: Sat Oct 22, 2011 1:55 am
Posts: 1
That's very impressive equations and plotting. It's really great because I really need this..thanks

Kima


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 43 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group