We will write two functions in Julia to demonstrate how they work.
The first function is
sumdiff
, which will sum up of differences between two vectors
# this bit is all a comment / string.
"""
`sumdiff`
=========
computes the sum of differences between two vectors
without creating a third vector in the middle.
Functions
---------
- `sumdiff(x,y)` Computes the sum of x-y where x and y are vectors
Example
-------
~~~~
x = [1 2 3]
y = [3 2 1]
@show sumdiff(x,y)
~~~~
"""
function sumdiff(x,y)
end
?sumdiff
x = [1 2 3]
y = [3 2 1]
@show sumdiff(x,y)
sum(x-y)
sumdiff([1,2,3,4,5,7,8,9],[1 2 3 4 5])
function diagsolve(A,b)
for i=1:length(b)
x[i] = b[i] / A[i]
end
end
A = diagm([2,3,4.])
b = [1. 1. 1.]
diagsolve(A,b)