# I have doubts about using Pots.jl

**URL:** <https://discourse.julialang.org/t/i-have-doubts-about-using-pots-jl/47252>\
**Category:** General Usage\
**Tags:** question, package, plotting\
**Created:** [September 25, 2020, 9:33am UTC](https://discourse.julialang.org/t/i-have-doubts-about-using-pots-jl/47252 "2020-09-25T09:33:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![adeil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adeil/32/16564_2.png) [@adeil](https://discourse.julialang.org/u/adeil)\
**Post date:** [September 25, 2020, 9:33am UTC](https://discourse.julialang.org/t/i-have-doubts-about-using-pots-jl/47252/1 "2020-09-25T09:33:08Z")

</div>

I’m trying to plot this function x = 0.2 \* cos (2 \* t + π) but there is something wrong with the definition of t.

"

using Pkg  
Pkg.add(“Plots”)  
using Plots

t=range(0,stop=10, length=100) #0:0.01:2_π  
y = 0.2_cos.(2\*t+π)

plot(t, y, label=“cos(x)”)  
plot!(xlab=“t(s)”, ylab=“x(m)”)

"

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [September 25, 2020, 9:38am UTC](https://discourse.julialang.org/t/i-have-doubts-about-using-pots-jl/47252/2 "2020-09-25T09:38:23Z")

</div>

Yeah, it’s a typo. `lenght` is spelled `length`.

You also don’t need to `Pkg.add("Plots")` once you already have plots. After running that command once (ever) you only need `using Plots`

---

<div class="post-metadata">

**Author:** ![adeil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adeil/32/16564_2.png) [@adeil](https://discourse.julialang.org/u/adeil)\
**Post date:** [September 25, 2020, 9:50am UTC](https://discourse.julialang.org/t/i-have-doubts-about-using-pots-jl/47252/3 "2020-09-25T09:50:43Z")

</div>

Thank you very much, but I already made the changes and it still doesn’t work. I changed the expression of t to 0: 0.01: 10 and it didn’t work either.

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [September 25, 2020, 9:54am UTC](https://discourse.julialang.org/t/i-have-doubts-about-using-pots-jl/47252/4 "2020-09-25T09:54:15Z")

</div>

> [@adeil](#):
>
> _y = 0.2_ cos.(2\*t+π)

should be

```julia
y = 0.2 .* cos.(2 .* t .+ π )

```

or equivalently

```julia
y = @. 0.2 * cos(2t + π)

```

Anyway the point is this has nothing to do with the Plot.jl package. I suggest you take a look at the julia manual to sort out syntactical issues.

By the way, I am using ` and ``` to `quote` my code so it’s nice to read 🙂

---

<div class="post-metadata">

**Author:** ![adeil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adeil/32/16564_2.png) [@adeil](https://discourse.julialang.org/u/adeil)\
**Post date:** [September 25, 2020, 9:59am UTC](https://discourse.julialang.org/t/i-have-doubts-about-using-pots-jl/47252/5 "2020-09-25T09:59:29Z")

</div>

It worked! Apologies if it looked like I was blaming the package. I’m new to Julia and in the community maybe I chose the wrong tags. Thank you very much for your help.

---

<div class="post-metadata">

**Author:** ![Seif\_Shebl](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Post date:** [September 25, 2020, 10:11am UTC](https://discourse.julialang.org/t/i-have-doubts-about-using-pots-jl/47252/6 "2020-09-25T10:11:50Z")

</div>

> [@adeil](#):
>
> _y = 0.2_ cos.(2\*t+π)

Here, you need a `.+` when adding a scalar to a vector, like `0.2cos.(2t .+ π)`, or as suggested by @tomerarnon, use `@. 0.2cos(2t + π)`. Also note, there is no space after function names `cos (` or between `0.2 cos`. Finally, `range` can be written shorter as below.

```julia
using Plots

t = range(0, 10, length=100) # 0:0.01:2π
y = 0.2cos.(2t .+ π)

plot(t, y, label="cos(x)")
plot!(xlab="Time (s)", ylab="Distance (m)")

```

---

<div class="post-metadata">

**Author:** ![adeil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adeil/32/16564_2.png) [@adeil](https://discourse.julialang.org/u/adeil)\
**Post date:** [September 25, 2020, 10:19am UTC](https://discourse.julialang.org/t/i-have-doubts-about-using-pots-jl/47252/7 "2020-09-25T10:19:44Z")

</div>

> [@Seif\_Shebl](#):
>
> Here, you need a `.+` when adding a scalar to a vector, like `0.2cos.(2t .+ π)` , or as suggested by @tomerarnon, use `@. 0.2cos(2t + π)` . Also note, there is no space after function names `cos (` or between `0.2 cos` . Finally, `range` can be written shorter as below.

Are these points included 0.2cos. (2t. + π) due to Broadcasting? And  
can you explain to me the use of this macro @. 0.2cos (2t + π)?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 25, 2020, 10:41am UTC](https://discourse.julialang.org/t/i-have-doubts-about-using-pots-jl/47252/8 "2020-09-25T10:41:31Z")

</div>

> [@adeil](#):
>
> And  
> can you explain to me the use of this macro @. 0.2cos (2t + π)?

`@.` inserts a dot between all operators and function calls. If you are new to Julia, using the help system will be useful. Just start julia and enter `?@.` and press enter.
