Hello,
I am setting a polynomial function and a vector (array) that passes the parameters to this function, something like this:
y = v[1]*x + v[2]*x^2 + v[3]*x^3
It would be easier to remember the elements of the vector if the elements were named as in:
y = alpha*x + beta*x^2 + gamma*x^3
When setting the vector, I should remember the sequence of the elements and the same applies when changing an element, as in:
julia> v = [7,2,3]
3-element Vector{Int64}:
7
2
3
julia> v[2] = 5
5
julia> v
3-element Vector{Int64}:
7
5
3
Is it possible to name each element of the vector so that I don’t need to remember the sequence of elements and that I can change the elements by name only? Something like this:
v = [beta=7, alpha=0.5, gamma=3]
v:alpha=5
I see from this post that one can use the package NamedArrays
that set a vector as an array of values and names:
julia> v = NamedArray([5, 7, 3], (["alpha", "beta", "gamma"]))
3-element Named Vector{Int64}
A │
──────┼──
alpha │ 5
beta │ 7
gamma │ 3
But then how are the elements changed?
Another way might be with the package Parsers
:
v = (alpha=5, beta=7, gamma=3)
but this is a tuple that does not allow me to modify the elements.
Is there a simple way, preferably Julia base, to do name a vector and modify its elements by name?
Thank you