I am trying to implement *GDQ* method in Julia. Writing code in an imperative schema is a straightforward practice but I feel stuck in rewriting it with functional idioms below is the part of code which I am hanged in. Is it possible to rewrite it in functional schema in an efficient way?

Imperative code:

```
function coeff_1(points)
m1_ = m1(points)
a_ij(i, j) = m1_[i]/(points[i] - points[j])/m1_[j]
count = length(points)
result = zeros((count, count))
for i = 1:count
for j = 1:count
if (i != j)
result[i, j] = a_ij(i, j)
result[i, i] -= result[i, j]
end
end
end
result
end
```

Incomplete functional functional implementation:

```
function coeff_1_functional(points)
m1_ = m1(points)
a_ij(i, j) = m1_[i]/(points[i] - points[j])/m1_[j]
count = length(points)
result = [a_ij(i, j) for i = 1:count, j = 1:count]
# the below part is where I stuck, It is both imperative and inefficient
for i = 1:count
result[i, i] = -sum(result[i, :])
end
result
end
```

With Regards