# ERROR: LoadError: MethodError: no method matching +(::Array{Float64,1}, ::Int64) For element-wise addition, use broadcasting with dot syntax: array .+ scalar

**URL:** https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-array-float64-1-int64-for-element-wise-addition-use-broadcasting-with-dot-syntax-array-scalar/67075
**Category:** New to Julia
**Tags:** question
**Created:** [August 26, 2021, 11:46pm UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-array-float64-1-int64-for-element-wise-addition-use-broadcasting-with-dot-syntax-array-scalar/67075 "2021-08-26T23:46:59Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![setegn\_alemu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/setegn_alemu/32/28607_2.png) [@setegn\_alemu](https://discourse.julialang.org/u/setegn_alemu)
#### Post date: [August 26, 2021, 11:46pm UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-array-float64-1-int64-for-element-wise-addition-use-broadcasting-with-dot-syntax-array-scalar/67075/1 "2021-08-26T23:46:59Z")

</div>

Write the function `periodic` which takes as its input the vector `t` , vector `c` which contains the vector of coefficents ccc in the order as above, the integers `d_poly` and `d_periodic` corresponding to the order of the polynomial and periodic expansions, and the period `T` , and returns the following:

I simply want to create a period function ( polynomial plus cosine and sine function ).

function poly\_periodic(  
t::AbstractVector,  
c::AbstractVector,  
d\_poly::Integer,  
d\_periodic::Integer,  
T::Number  
)

```
m = length(t)
y = zeros(m)

# Step 1: Extact polynomial and periodic coefficients
 c_poly = c[1:d_poly]

c_periodic = c[length(c_poly+1):end]
@assert length(c_periodic) == 2 * d_periodic "Number of periodic coeffs does not match 2 * d_periodic"

# Step 2: Compute the polynomial part 
for i in 0:d_poly
   y .+= c_poly[i+1]*t.^i
end

# Step 3: Compute the periodic part
for i in 1:d_periodic
    y .+= c_periodic[2*i-1]*cos.(2*i*pi*t/T) # cosine term

    y .+= c_periodic[2*i]*sin.(2*i*pi*t/T ) # sine term
end

return y

```

end  
The error message is belowERROR: LoadError: MethodError: no method matching +(::Array{Float64,1}, ::Int64)  
For element-wise addition, use broadcasting with dot syntax: array .+ scalar  
Closest candidates are:  
+(::Any, ::Any, !Matched::Any, !Matched::Any…) at operators.jl:538  
+(!Matched::Complex{Bool}, ::Real) at complex.jl:301  
+(!Matched::BigFloat, ::Union{Int16, Int32, Int64, Int8}) at mpfr.jl:378  
…

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [August 27, 2021, 12:14am UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-array-float64-1-int64-for-element-wise-addition-use-broadcasting-with-dot-syntax-array-scalar/67075/2 "2021-08-27T00:14:03Z")

</div>

what’s not clear about the error message?

---

<div class="post-metadata">

### Author: ![setegn\_alemu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/setegn_alemu/32/28607_2.png) [@setegn\_alemu](https://discourse.julialang.org/u/setegn_alemu)
#### Post date: [August 27, 2021, 12:20am UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-array-float64-1-int64-for-element-wise-addition-use-broadcasting-with-dot-syntax-array-scalar/67075/3 "2021-08-27T00:20:09Z")

</div>

Thanks Jling, I am new to Julia. I got difficulty in which part of my code I need to edit.

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [August 27, 2021, 12:34am UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-array-float64-1-int64-for-element-wise-addition-use-broadcasting-with-dot-syntax-array-scalar/67075/4 "2021-08-27T00:34:52Z")

</div>

> [@setegn\_alemu](#):
>
> ```julia
> c_periodic = c[length(c_poly+1):end]
> 
> ```

This is the error. I think you want `length(c_poly)+1` here?

(You also won’t get ideal performance from this style of code, but that’s a separate issue.)

---

<div class="post-metadata">

### Author: ![setegn\_alemu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/setegn_alemu/32/28607_2.png) [@setegn\_alemu](https://discourse.julialang.org/u/setegn_alemu)
#### Post date: [August 27, 2021, 12:39am UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-array-float64-1-int64-for-element-wise-addition-use-broadcasting-with-dot-syntax-array-scalar/67075/5 "2021-08-27T00:39:41Z")

</div>

Many thanks, for your good spot. It worked.
