-
Your first
testfunction returnsnothing. You should return a value. The secondtestfunction works because you don’t have theprintlnstatement in there, and you’re exploiting the fact that a function without an explicitreturnreturns the result of the last statement. Still, you should have areturn -
If I understand correctly, you have a function ℝ→ℂ. Plotting such a function doesn’t make sense. You can plot the real part, or the imaginary value, or the absolute value (or
abs2). In general, you can only plot a function with a real output value. If your function was ℂ→ℝ, you could have a 3D plot. -
Some minor points:
- Remove the print statements. You don’t want to print something every time the function evaluates
- Consider making your function type stable. Don’t return
0, returnzero(1im)so that it always returns aComplexF64independent of the value oft. -
plotcan do some automatic guessing for the values oftto plug in, but it’s better to give it the values over which you want to plot explicitly:plot(tvals, abs2.(test.(tvals)), …)
1 Like