# Functions of continuous variables

**URL:** <https://discourse.julialang.org/t/functions-of-continuous-variables/56986>\
**Category:** New to Julia\
**Created:** [March 12, 2021, 12:00am UTC](https://discourse.julialang.org/t/functions-of-continuous-variables/56986 "2021-03-12T00:00:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![leopdsf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leopdsf/32/31008_2.png) [@leopdsf](https://discourse.julialang.org/u/leopdsf)\
**Post date:** [March 12, 2021, 12:00am UTC](https://discourse.julialang.org/t/functions-of-continuous-variables/56986/1 "2021-03-12T00:00:34Z")

</div>

Hello, there!  
I want to plot a function p(s) \times s, being s \in \mathbb{R}. My code is:

```julia
Pkg.add("Plots")
using Plots

p(s) = s/2 * exp(-s^2/4)

plot(s,p(s))

```

The problem is that when I run it, I got the following error message:

```julia
>undefVarError: s is not defined.

```

How do I define s as a real variable? In Julia, it is not unnecessary to define the type of a variable?

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [March 12, 2021, 12:05am UTC](https://discourse.julialang.org/t/functions-of-continuous-variables/56986/2 "2021-03-12T00:05:57Z")

</div>

Welcome!

You don’t have to define the _type_ of a variable, but you still have to define its value somehow. Otherwise `s` is just a label with no meaning at all.

However, in your case `Plots.jl` already knows how to plot a scalar-valued function, and all you have to do is pass in the function itself:

```julia
plot(p)

```

![out](https://global.discourse-cdn.com/julialang/original/3X/0/f/0ff3aaf980c75d8e1f6e4751050c53dfc8b2a41b.png)

You can also plot an anonymous function:

```julia
plot(s -> s/2 * exp(-s^2/4))

```

---

<div class="post-metadata">

**Author:** ![leopdsf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leopdsf/32/31008_2.png) [@leopdsf](https://discourse.julialang.org/u/leopdsf)\
**Post date:** [March 12, 2021, 12:09am UTC](https://discourse.julialang.org/t/functions-of-continuous-variables/56986/3 "2021-03-12T00:09:05Z")

</div>

Thank you very much!
