# MethodError: no method matching Lagrange\_Polynomials(::Float64, ::LinRange{Float64}, ::Array{Float64,1})

**URL:** <https://discourse.julialang.org/t/methoderror-no-method-matching-lagrange-polynomials-float64-linrange-float64-array-float64-1/50370>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [November 18, 2020, 9:41am UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-lagrange-polynomials-float64-linrange-float64-array-float64-1/50370 "2020-11-18T09:41:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![veenz98](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/veenz98/32/19529_2.png) [@veenz98](https://discourse.julialang.org/u/veenz98)\
**Post date:** [November 18, 2020, 9:41am UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-lagrange-polynomials-float64-linrange-float64-array-float64-1/50370/1 "2020-11-18T09:41:57Z")

</div>

Hi, I’m new to Julia,  
for this function in main I got an error message:  
MethodError: no method matching LagrangePolynomial(::Float64, ::LinRange{Float64}, ::Array{Float64,1})  
Closest candidates are:  
LagrangePolynomial(::T, !Matched::Array{T,1}, ::Array{T,1}) where T\<:AbstractFloat at In[8]:3

```julia
 using PyPlot

function Lagrange_Polynomials(x::T,vector_x::Vector{T},vector_y::Vector{T}) where T <: AbstractFloat # define an infinitely many large set of functions
n = length(vector_x)
length(vector_y)==n || error("Incompatible vector size")
S = zero(T)
for i ∈ 1:n
     P = one(T)
          for j ∈ 1:n
                   if j != i
                     P*=(x-vector_x[j])/(vector_x[i]-vector_x[j])
                   end #chiude l'if
          end #chiude il ciclo for interno
    S += vector_y[i]*P
end #chiude il ciclo for esterno
 return S

f(x) = 1/sqrt(2π)*exp(-x^2/2);
a=-2; #estremi dell' intervallo
b = 2;
n = 12 #number of interpolating points
vector_x = LinRange(a,b,n); #suddivisione dell' intervallo [a,b] in n punti equispaziati
xinterval = LinRange(a,b,1024); #Una suddivisione più precisa dell' intervallo
ypoly = [Lagrange_Polynomials(x,vector_x,f.(vector_x)) for x in xinterval]
plot(xinterval, ypoly)
plot(xinterval, f.(xinterval), "k");
plot(vector_x, f.(vector_x), "ro");
plt[:legend](["f(x)","interpolation points",L"L_{n-1}(x)"])

```

Please, help me

---

<div class="post-metadata">

**Author:** ![sostock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sostock/32/5546_2.png) [@sostock](https://discourse.julialang.org/u/sostock)\
**Post date:** [November 18, 2020, 1:14pm UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-lagrange-polynomials-float64-linrange-float64-array-float64-1/50370/2 "2020-11-18T13:14:49Z")

</div>

In your definition of the `Lagrange_Polynomials` function, you restricted the second argument to `Vector`. Then you try to pass a `LinRange` as argument. That’s why you get an error. `Vector` and `LinRange` are different types.

The solution would be to relax the restrictions of the argument types of your `Lagrange_Polynomials` function, for example like this:

```julia
function Lagrange_Polynomials(x::T, vector_x::AbstractVector{T}, vector_y::AbstractVector{T}) where T <: AbstractFloat
    ...
end

```

Here, `Vector{T}` was changed to `AbstractVector{T}`, an abstract type which includes ranges.

You could also completely remove the argument type restrictions:

```julia
function Lagrange_Polynomials(x, vector_x, vector_y)
    ...
end

```
