# Error when defining an array as a function argument

**URL:** https://discourse.julialang.org/t/error-when-defining-an-array-as-a-function-argument/22179
**Category:** General Usage
**Tags:** question
**Created:** [March 22, 2019, 5:02am UTC](https://discourse.julialang.org/t/error-when-defining-an-array-as-a-function-argument/22179 "2019-03-22T05:02:28Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![11111](https://avatars.discourse-cdn.com/v4/letter/1/73ab20/32.png) [@11111](https://discourse.julialang.org/u/11111)
#### Post date: [March 22, 2019, 5:02am UTC](https://discourse.julialang.org/t/error-when-defining-an-array-as-a-function-argument/22179/1 "2019-03-22T05:02:28Z")

</div>

I wrote the following code and an error occurred in the function part.  
I think that the number of elements of the array is correct, but I do not know why the error occurs.

```julia
function jacobi(x::Matrix{Float64},A::Matrix{Float64},b::Matrix{Float64})
    n=size(x,1)
    x_new=copy(x)  
    sum=zeros(n)
    b_sum=0
    for i in 1:n
        b_sum+=(abs(b[i]^2))^0.5
    end
    count=0
    if count==0
        for i in 1:n
            for j in 1:n
                if i!=j
                    sum[i]+=A[i,j]*x[j]
                end
            end
            x_new[i]=(b[i]-sum[i])/A[i,i]
        end
        
        nrm=zeros(n)
        nrm=x_new-x
        nrm_sum=0
        for i in 1:n
            nrm_sum+=(abs(nrm[i])^2)^0.5
        end
        if nrm_sum<5e-1
            count=1
        end
    end
end

A=[3 1 1; 1 3 1; 1 1 3]
b=[0,4,6]
x=zeros(3)

jacobi(x,A,b)

```

So, please tell me what is wrong.

```julia
ERROR: LoadError: MethodError: no method matching jacobi(::Array{Float64,1}, ::Array{Int64,2}, ::Array{Int64,1})Stacktrace:
 [1] top-level scope at none:0

```

---

<div class="post-metadata">

### Author: ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)
#### Post date: [March 22, 2019, 5:34am UTC](https://discourse.julialang.org/t/error-when-defining-an-array-as-a-function-argument/22179/2 "2019-03-22T05:34:58Z")

</div>

> [@11111](#):
>
> ```julia
> A=[3 1 1; 1 3 1; 1 1 3]
> b=[0,4,6] 
> x=zeros(3)
> 
> ```

your matrix is a matrix of integers while your function accepts floating point numbers only. this code is a little bit more generic:

```julia
function jacobi(x::Array{<:Real},A::Array{<:Real},b::Array{<:Real})
...

```

besides, this works fine too:

```julia
function jacobi(x,A,b)
...

```

julia will recognize the types at the moment you feed some numbers to that function

if you only want floating numbers, you can:  
a) convert the numbers to Float64 before putting those inside the function:

```julia
convert.(Float64,[2,3]) # the point in this case is to broadcast 
#the operation to the entire array

```

b) write those numbers as floats:

```julia
#notice the points
A=[3. 1. 1.; 1. 3. 1.; 1. 1. 3.]
b=[0.,4.,6.] 
x=zeros(3) #this already produces an array of float64

```
