forum.alglib.net

ALGLIB forum
It is currently Fri Apr 19, 2024 7:31 am

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  [ 8 posts ] 
Author Message
 Post subject: Interpolation
PostPosted: Thu Jun 02, 2011 4:55 pm 
Offline

Joined: Thu Jun 02, 2011 4:50 pm
Posts: 4
Hi every one,
I need to use Spline&& polynomial && regression interpolation in C#.
how can i do that? is there any example to help me?
Thankssss


Top
 Profile  
 
 Post subject: Re: Interpolation
PostPosted: Thu Jun 02, 2011 6:02 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 906
You can find some information in the ALGLIB Reference Manual:

http://www.alglib.net/translator/man/ma ... t_spline1d
http://www.alglib.net/translator/man/ma ... nit_polint
http://www.alglib.net/translator/man/ma ... unit_lsfit

If you still have questions, feel free to ask them here.


Top
 Profile  
 
 Post subject: Re: Interpolation
PostPosted: Fri Jun 03, 2011 2:58 am 
Offline

Joined: Thu Jun 02, 2011 4:50 pm
Posts: 4
Many thanks :)
I actually impressed when i saw this powerful library.
I have two question at the moment :
1- I entered this code :
Code:
alglib.spline1dinterpolant output;
            double[] x = new double[] { -2, -1, 0, 1, 2 };
            double[] y = new double[] { 4, 1, 0, 1, 4 };

            alglib.spline1dbuildakima(x, y, out output);


The out put is {4,-4,1,0,1,-2,1,0,0,0,1,0,1,2,1,0}. it means that my equation curve is :
f(x) = 4 - 4x + x^2 +x^4 - 2x^5 + x^9 + x^11 + 2x^12 + x^13 ???

2- My second question is about my request:
I have 2 arrays x and y which show the coordinate. the distance between them are not same. Which function is then best fit Spline Interpolation equation for me?

Thanks
Regards


Top
 Profile  
 
 Post subject: Re: Interpolation
PostPosted: Fri Jun 03, 2011 10:42 am 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 906
1. you should not work with contents of spline1dinterpolant structure directly - use ALGLIB functions to work with it. In particular, if you want to extract coefficients - use spline1dunpack - it provides convenient and 100% documented interface

2. you can use parabolically terminated cubic splines


Top
 Profile  
 
 Post subject: Re: Interpolation
PostPosted: Sat Jun 04, 2011 4:52 am 
Offline

Joined: Thu Jun 02, 2011 4:50 pm
Posts: 4
Thanks for your help
i have gotten one run-time error "Exception of type 'alglib+alglibexception' was thrown"
i used
Code:
alglib.spline1dgriddiffcubic(mainPointX, mainPointY, out d1);
the mainPointX and mainPointY have 31 double numbers.
The numbers are :
Code:
double[] mainPointX = new double[] { 19, 20.5, 57, 144, 148, 154.5, 158.5, 178, 197.5, 269, 350, 379, 409, 473, 477.5, 485, 493, 497, 534.5, 572.5, 579, 584.5, 590, 605, 608, 609, 609, 609, 609, 609, 609 };
            double[] mainPointY= new double[] { 99, 92.5, 91.5, 92.5, 92.5, 92.5, 92.5, 93.5, 93.5, 95.5, 96.5, 97.5, 97.5, 98.5, 98.5, 98.5, 98.5, 98.5, 99.5, 99.5, 99.5, 99.5, 99.5, 101.5, 103.5, 105.5, 107.5, 109.5, 111.5, 113.5, 115.5 };


what is wrong for me to get this error?
Regards


Top
 Profile  
 
 Post subject: Re: Interpolation
PostPosted: Sat Jun 04, 2011 6:59 am 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 906
alglib.alglibexception class has msg field. If you read it, you will find description of situation which caused you program to abort. It tells that you have incorrect mainPointX - array size is correct, but data it holds are not. Several last elements are not distinct.


Top
 Profile  
 
 Post subject: Re: Interpolation
PostPosted: Mon Jun 06, 2011 11:20 am 
Offline

Joined: Thu Jun 02, 2011 4:50 pm
Posts: 4
Yup your correct my numbers weren't distinct. Thanks

Now i am looking for polynomial Regression, i used polynomialfit procedure to find equation line in n=4 for example.
but i dont know how i can get equation line. the out parameter ( or 'p') is barycentric type. it has some parameters in the structure.
which function can interpret this structure and the give me an equation line?

another question is that, i want first deviation and second derivation values. In spline interpolation i used spline1dgriddiffcubic and spline1dgriddiff2cubic , which function here can easily give me these values?

Thanks a lot
Regards


Top
 Profile  
 
 Post subject: Re: Interpolation
PostPosted: Mon Jun 06, 2011 1:40 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 906
barycentricbar2pow will convert your polynomial into power basis
barycentricdiff can be used to calculate first derivative
barycentricdiff2 can be used to calculate second derivative


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

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 70 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