Hi everyone. I have a simple doubt about whether is possible to have an index number inside a function in a for loop. The ilustrative example below makes my doubt clearer.
I have an affine function
f(x) = 2x - a and I want to find the root for distinct values of a. In this case, is it possible to use the
fzero function inside a loop?
I understand why the error occurs but I do not know how to fix it. I have a similar code in Fortran and I am trying to convert it to Julia.
Thanks a lot!
a = [1 3 5] function main(x) 2*x - a[i] end # function guess = 5 for i in 1:3 y = fzero(main, guess) println(y) end # for UndefVarError: j not defined