Why your Julia program won't work
Based on
advice from Prof. Andy Yagle
Possibly in order of likelihood of this being the problem:
-
You forgot to type
using Plots
(or some other package).
An error message like
plot not defined
likely means this.
-
You omitted the "." in
t .- 3
or
a .* b
Look for error messages like these:
ERROR: MethodError: no method matching -(::UnitRange{Int64}, ::Int64)
ERROR: MethodError: no method matching *(::UnitRange{Int64}, ::UnitRange{Int64})
-
You think x is a column vector, but it actually is a matrix.
x = [1 -3 2]
produces a 1 × 3 matrix,
not a vector.
You must use
x = [1, -3, 2]
or
x = [1; -3; 2]
to get a vector.
Use size(x) to check the dimensions.
-
You used
t = LinRange(0,1,100)
instead of
t = 0:0.01:1
or vice versa.
Don't see the difference?
Try it.
The first one generates 100 values
that are not spaced by 0.01.
The second generates 101 values separated by 0.01.
-
You made a typing mistake somewhere in your program.
You mistyped x for X, or vice-versa (Julia is case-sensitive).
You simply mistyped a weird variable name, like
dft_chop.
-
You forgot to save your modified code before rerunning it.
Or you saved it in the wrong directory (you'd be surprised how often).
Or you need to restart Julia to erase previous values.
-
Your program conditionals or loop structure is messed up somehow.
Something is messing up your
for-end; if-else-break-end; while-end.
Or you may have forgotten that # begins a comment statement in Julia.
-
You forgot the most basic rule of all of computer programming:
A computer will always do exactly what you tell it to do.
But that may not be what you had in mind!
-
You can't load a file because
you put the file in a different folder/directory
than where Julia is running.
To find out where Julia is running,
type this at the REPL prompt:
pwd()
(which is short for "print working directory",
which is also a linux/mac command line function).
To see what files are in that directory,
type this at the Julia REPL:
readdir()
If that list is too long to find your file,
i.e., if it includes ⋮,
then type this to see all the files:
for f in readdir(); println(f); end
If you don't see your file in that list,
then you must have put it somewhere else!