Because yn is pointing to an anonymous function called β#11β which you then put in the column A. Are you by chance copying and pasting Matlab code? The syntax, while close, are not compatible. Hereβs how the Julia code should look like.
t= 0:50
function yn(t) ## now the name of the function is yn()
d = .05
n = .01
g = .015
s = .3
k = 6
t*(d+n+g+s)
end
Youβll see that I have defined a function called yn which accepts one argument called t. Iβve put all your local variables inside the function itself (Julia likes it when everything is inside a function). Iβve also got rid of the expression ((y-k)+I*t) since I donβt know what I and y are and replaced it with my own expression for illustration.
You can now evaluate this function as follows: yn(t) where t = 1:15 although this returns a lazy evaluator so you may need to collect the results⦠i.e. myresults = collect(yn(t)). Then you can assign this to a dataframe DataFrame(A = myresults, B = t).
Alternatively, given that you probably donβt have a lot of experience yet, Iβd just do it more simply with a for loop
myresults = zeros(Float64, 15)
for t = 1:15
myresults[t] = yn(t) # evaluate the function at every time instead of a range like 1:15
end
DataFrame(A = myresults, B = 1:15)
BTW: please provide a working example, which one can improve. In your example y and I are not defined, so I can only guess what you want to do.
I see that yn is a function. You probably want to have in df the result of yn. So you have to call it when you define df. Maybe you intend something like that:
yn(t, y, k, I) = (y-k) .+ I .* t # definition of yn, probably you need some broadcasting in it, it returns a vector
t = 0:50
df = DataFrame(A=yn(t, 1, 6, 100:150), B=t) # now you call yn
julia> first(df, 6)
6Γ2 DataFrame
β Row β A β B β
β β Int64 β Int64 β
βββββββΌββββββββΌββββββββ€
β 1 β -5 β 0 β
β 2 β 96 β 1 β
β 3 β 199 β 2 β
β 4 β 304 β 3 β
β 5 β 411 β 4 β
β 6 β 520 β 5 β
Thankβs that solved the issue. Only thing is it says yn is used, so I needed a new variable. Is there a way to remove a variable assignment in console?
you need to read a bit more regarding function declaration, mapping a function, before just putting things that runs in REPL and hope it does what you imagined. A quick one line way of doing what you want would be: