Using prime "'" in Julia variables

Viewed 165

I have many variables and matrices that I would like to call with a prime, like:

xprime, yprime, rprime and so on.

I believe that I can't use x', y', r' etc. as it is for instance used for matrices transposed.

julia> x' = 5
ERROR: syntax: invalid assignment location "x'" around REPL[2]:1
Stacktrace:
 [1] top-level scope at REPL[2]:1

julia> x = [1,2]
2-element Array{Int64,1}:
 1
 2

julia> x'
1×2 LinearAlgebra.Adjoint{Int64,Array{Int64,1}}:
 1  2

I am opened to any suggestion of a more convenient way than xprime, yprime etc. which is pretty long and ugly I think.

1 Answers

You can use prime:

julia> x′ = 1
1

julia> x′
1

help?> ′
"′" can be typed by \prime<tab>

Notice the difference that I use the ′ (prime), while you tried to use ' (single quote). Using single quote is not allowed in variable name as it invokes adjoint operation on a value preceding it (which you can see in your example).

As explained in help for ′ you can type it in in Julia REPL and in most editors configured to support Julia by typing \prime and pressing Tab.

Related