Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc Example #230

Closed
iwelch opened this issue Sep 17, 2018 · 2 comments
Closed

Doc Example #230

iwelch opened this issue Sep 17, 2018 · 2 comments

Comments

@iwelch
Copy link

iwelch commented Sep 17, 2018

I am trying to get the doc example to work:

f(x,y) = log(x+y)
xs = 1:0.2:5
ys = 2:0.1:5
A = [f(x+y) for x in xs, y in ys]

# linear interpolation
interp_linear = LinearInterpolation((xs, ys), A)

I think the first error is that you mean f(x,y) instead of f(x+y).

but even then,

julia> A = [f(x,y) for x in xs, y in ys]
5×4 Array{Float64,2}:
 1.09861  1.38629  1.60944  1.79176
 1.38629  1.60944  1.79176  1.94591
 1.60944  1.79176  1.94591  2.07944
 1.79176  1.94591  2.07944  2.19722
 1.94591  2.07944  2.19722  2.30259

julia> interp_linear = LinearInterpolation((xs, ys), A)
ERROR: MethodError: no method matching LinearInterpolation(::Tuple{UnitRange{Int64},StepRange{Int64,Int64}}, ::Array{Float64,2})
Closest candidates are:
  LinearInterpolation(::T<:AbstractRange, ::Any; extrapolation_bc) where T<:AbstractRange at /Users/ivo/.julia/packages/Interpolations/qyX2d/src/convenience-constructors.jl:3
  LinearInterpolation(::T<:AbstractArray, ::Any; extrapolation_bc) where T<:AbstractArray at /Users/ivo/.julia/packages/Interpolations/qyX2d/src/convenience-constructors.jl:4
  LinearInterpolation(::Tuple{Vararg{T<:AbstractRange,N}}, ::Any; extrapolation_bc) where {N, T<:AbstractRange} at /Users/ivo/.julia/packages/Interpolations/qyX2d/src/convenience-constructors.jl:8
  ...
Stacktrace:
 [1] top-level scope at none:0

ultimately, I want to find out whether I can manipulate an irregular (x,y,z) data set into a contour plot (which can accept irregular x and y, but needs a function for z, rather than a value).

@timholy
Copy link
Member

timholy commented Sep 19, 2018

Modulo the comma in f, your example works for me. But I don't think you actually showed what you're trying: note the UnitRange in the signature of the MethodError.

@timholy
Copy link
Member

timholy commented Sep 27, 2018

I made a guess about what you were actually trying to do and committed a fix in #241. Feel free to reopen if this doesn't fix your underlying problem.

@timholy timholy closed this as completed Sep 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants