'print a function with plots in julia

I'm currently trying to print the following function in my plot and I'm not allowed to use any imports or other libraries:

using Plots
  
amplitude = 1

frequenz_E = 329.63
frequenz_G_SHARP = 415.30
frequenz_B = 493.88

k(t) = amplitude * sin * (2 * pi * frequenz_E * t)

p = plot(0:0.005:0.001, k , label="E = 329.63 Hz", title="Triade sound wave", xlabel="t (seconds)", ylabel="y(t)")

display(p)

I do want to start at 0 and then increase the value by 0.005 up to 0.01.

Now if I want to print the function, I do get the following error:

include("/home/user/Applied_Mathmatics/Assignment_01/templates/waves.jl")
ERROR: LoadError: MethodError: no method matching *(::Int64, ::typeof(sin))
Closest candidates are:
  *(::Any, ::Any, ::Any, ::Any...) at operators.jl:529
  *(::ChainRulesCore.NotImplemented, ::Any) at /home/user/.julia/packages/ChainRulesCore/8NXnp/src/tangent_arithmetic.jl:37
  *(::ChainRulesCore.ZeroTangent, ::Any) at /home/user/.julia/packages/ChainRulesCore/8NXnp/src/tangent_arithmetic.jl:104

How can I work around the error and just print the function?

The output should look like this (I did not implement all functions yet):

enter image description here



Solution 1:[1]

As the error states, you cannot multiply a function with an Integer. You should write

k(t) = amplitude * sin(2 * pi * frequenz_E * t)

And by the way the range 0:0.005:0.001 is just one element, i.e., 0.. You can try that by

julia> collect(0:0.005:0.001)
1-element Vector{Float64}:
 0.0

In Julia the middle element is the step and the third element is the end of the range. Thus something like 0:0.001:0.005 makes more sense.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Oskar