timholy / Grid.jl

Interpolation and related operations on grids
MIT License
47 stars 26 forks source link

help me interpolation #67

Closed jmarcellopereira closed 8 years ago

jmarcellopereira commented 8 years ago

I have this points: x = [0 0.50 1 1.50 2 2.50 3 3.50 4 4.50 5]; y = [1. 3. 4. 6. 9. 7. 8. 4. 3. 8. 10.];

How to yi function using interpolate? only works if x is a range.

timholy commented 8 years ago

You can do this with Grid, but Interpolations.jl is better in basically every way. See this section of the docs.

jmarcellopereira commented 8 years ago

Hi Tim. I used this code:

using Interpolations

x = [0 0.50 1 1.50 2 2.50 3 3.50 4 4.50 5]; y = [1. 3. 4. 6. 9. 7. 8. 4. 3. 8. 10.]; xx = vec(x); yy = vec(y);

yint = interpolate((xx,), yy, Gridded(Linear()));

using Winston

Winston.plot(x,y,"or", 0:0.1:10, map(x->yint[x],0:0.1:10) )

But, Grid it is more intuitive.

tomasaschan commented 8 years ago

In this case, x could be the range 0:.5:5, so you could also use

using Interpolations

itp = interpolate(y, Linear(), OnGrid()) 
sitp =scale(itp, 0:.5:5)

fine_y = map(x->sitp[x], 0:.1:5)
jmarcellopereira commented 8 years ago

Hi, tlycken, thanks for tip ;)

tomasaschan commented 8 years ago

Anytime :) I'll close this issue - feel free to file another one, or (better yet) send an email to the julia-users Google Group, if you need more help!