# forum.alglib.net

ALGLIB forum
 It is currently Wed Sep 11, 2024 8:40 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.

 Page 1 of 2 [ 20 posts ] Go to page 1, 2  Next
 Print view Previous topic | Next topic
Author Message
 Post subject: How to use modified Shepard methodPosted: Mon Sep 13, 2010 1:27 am

Joined: Mon Sep 13, 2010 12:58 am
Posts: 14
Hi

It is my first using of AlgLib. So sorry if I'll wrong.

I have nonuniform mesh with data in some point and I need to recieve approximated value in other point of mesh. And if I understand right I need to use Shepard method ("idwbuildmodifiedshepard") for my purpose.

I have 2D arrary m_Array with double values

Code:
double m_Array[iArrayWidth][iArrayHeight];
//.....
// filling m_Array with value
//....

Then I've created:

Code:
ap::real_2d_array xy;
xy.setlength(iArrayWidth, iArrayHeight);

for ( int i = 0; i < iArrayHeight; i++ )
{
for ( int j = 0; j < iArrayWidth; j++ )
{
xy(i,j) = m_Array[i][j];
}
}

// pass to the idwbuildmodifiedshepard

Is it true when I fill xy array with my values?

Thanks a lot.
Best regards, Aleksey.

Top

 Post subject: Re: How to use modified Shepard methodPosted: Mon Sep 13, 2010 2:05 pm

Joined: Fri May 07, 2010 7:06 am
Posts: 922
You should store your points in rows, one row = one point. First iArrayWidth-1 columns store coordinates, last column stores function value.

Top

 Post subject: Re: How to use modified Shepard methodPosted: Mon Sep 13, 2010 4:20 pm

Joined: Mon Sep 13, 2010 12:58 am
Posts: 14
Did you mean that should I write something like that

Code:
ap::real_2d_array xy;
xy.setlength(m_iArrayHeight, m_iArrayWidth);

for ( int i = 0; i < m_iArrayHeight; i++ )
{
for ( int j = 0; j < m_iArrayWidth; j++ )
{
xy(i*j,0) = XXX;
xy(i*j,1) = m_ppArray[i][j].dValue;
}
}

And if it true, what is XXX ?

Thanks
Best regards, Aleksey.

Top

 Post subject: Re: How to use modified Shepard methodPosted: Mon Sep 13, 2010 7:48 pm

Joined: Fri May 07, 2010 7:06 am
Posts: 922
It should be something like

Code:
ap::real_2d_array xy;
xy.setlength(NumberOfPoints, NumberOfCoordinates+1); // NumberOfCoordinates=3, for example

for ( int i = 0; i < NumberOfPoints; i++ )
{
xy(i,0) = x[i]; // x-value
xy(i,1) = y[i]; // y-value
xy(i,2) = z[i]; // z-value
xy(i,3) = f[i]; // function value
}
}

Top

 Post subject: Re: How to use modified Shepard methodPosted: Tue Sep 14, 2010 1:13 am

Joined: Mon Sep 13, 2010 12:58 am
Posts: 14
Hi, Sergey. Thank you very much! :) It is now clearly for me.

Now I fill my array with following way
Code:
xy.setlength(m_iArrayHeight * m_iArrayWidth, 3);

int k = 0;
for ( int i = 0; i < m_iArrayHeight; i++ )
{
for ( int j = 0; j < m_iArrayWidth; j++ )
{
xy(k, 0) = m_ppArray[i][j].point.x;
xy(k, 1) = m_ppArray[i][j].point.y;
xy(k, 2) = m_ppArray[i][j].dValue;
k++;
}
}

Now I have another question. Then I pass "xy" to "idwbuildmodifiedshepard" method, which returns IDW interpolant - Z. And if I see right, Z will contain approximated values. So which field of Z contains these values? I've tried following code:
Code:
k = 0;
for ( int i = 0; i < m_iArrayHeight; i++ )
{
for ( int j = 0; j < m_iArrayWidth; j++ )
{
double val = Z.q(k++, 2);
}
}

But values of "val" are the same as in m_ppArray[i][j].dValue, i.e. it no changed. Maybe I've made something wrong again?

Thanks a lot!
Best regards, Aleksey.

Top

 Post subject: Re: How to use modified Shepard methodPosted: Tue Sep 14, 2010 4:50 am

Joined: Fri May 07, 2010 7:06 am
Posts: 922
You should use idwcalc() function to calculate the value of the interpolant at the points you need. Never try to work with its fields directly.

Top

 Post subject: Re: How to use modified Shepard methodPosted: Tue Sep 14, 2010 2:56 pm

Joined: Mon Sep 13, 2010 12:58 am
Posts: 14
Hi Sergey. Thank you again! :)

To calculate the value of the interpolant I use following code:
Code:
ap::real_1d_array x;
idwinterpolant z1;
int n = m_iArrayWidth * m_iArrayHeight;

idwbuildmodifiedshepard(xy, n, 2, 1, 15, 25, z1);

x.setlength(nx);

for( int i = 0; i < n; i++ )
{
x(0) = xy(i, 2);
//ap::vmove(&x(0), 1, &xy(i, 2), 1, ap::vlen(0,nx-1));
double val = idwcalc(z1, x);
idwerrors = ap::fp_neq(val, xy(i,nx));
}

In my case method idwcalc almost always returns 0 and sometimes -1.7054547436862421e+073. So I think I've made something wrong again. Could you help me once again please?

Thanks
Best regards, Aleksey.

Top

 Post subject: Re: How to use modified Shepard methodPosted: Wed Sep 15, 2010 7:40 pm

Joined: Fri May 07, 2010 7:06 am
Posts: 922
Can you post here (as zip-file) your program with all its data? It is hard to tell what's wrong without looking into it. I think that IDW is too robust to produce such large deviations (1E+73), but I have to look at it myself.

Top

 Post subject: Re: How to use modified Shepard methodPosted: Thu Sep 16, 2010 1:22 am

Joined: Mon Sep 13, 2010 12:58 am
Posts: 14
Hi, Sergey

I've added to archive "signal.txt" file with my data and cpp file with one method which reads signal.txt file and calcs interpolant.

Best regards, Aleksey.

Top

 Post subject: Re: How to use modified Shepard methodPosted: Fri Sep 17, 2010 3:29 pm

Joined: Mon Sep 13, 2010 12:58 am
Posts: 14
Hey Sergey.

Did you see my example code? Is it wrong? Or may be did you want something else?

Thanks!
Best regards, Aleksey.

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 2 [ 20 posts ] Go to page 1, 2  Next

 All times are UTC

#### Who is online

Users browsing this forum: No registered users and 60 guests

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

Search for: