# Defining a function using the output of another function

**URL:** <https://discourse.julialang.org/t/defining-a-function-using-the-output-of-another-function/39589>\
**Category:** General Usage\
**Tags:** question, diffeq, metaprogramming\
**Created:** [May 16, 2020, 3:35pm UTC](https://discourse.julialang.org/t/defining-a-function-using-the-output-of-another-function/39589 "2020-05-16T15:35:30Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![yha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yha/32/3502_2.png) [@yha](https://discourse.julialang.org/u/yha)\
**Post date:** [May 16, 2020, 4:00pm UTC](https://discourse.julialang.org/t/defining-a-function-using-the-output-of-another-function/39589/2 "2020-05-16T16:00:24Z")

</div>

I’m not sure if I understood the problem correctly, but perhaps just pass the coefficients and offsets as parameters? Something like

```julia
function dy(y, δx, coeffs, offsets)
    N = length(y)
    dy = zeros(N)
    for j in eachindex(y)
        denom = 32*δx # and something else near the edges?
        dy[j] = sum(y[j+i]*c for (i,c) in zip(offsets,coeffs) if j+i in eachindex(y)) / denom
    end
    dy
end

```

(I’m not sure what that denominator is for and where the numbers 32,8,2 come from).  
You might want to take a look at `ImageFiltering.jl`, and specifically `ImageFiltering.imfilter`. It does exactly what it seems you are trying to do, except maybe near the edges (since I’m not sure what is going on near the edges in your code).

---

_[View the full topic](https://discourse.julialang.org/t/defining-a-function-using-the-output-of-another-function/39589)._
