Suppose i wanted to write a fun y = x^2+1

and wanted to plot in scatter. So how can i plot this in Julia?

i tried this method but didn’t work

y(x) = x^2+1

x = 1:10

scatter(x,y(x))

Suppose i wanted to write a fun y = x^2+1

and wanted to plot in scatter. So how can i plot this in Julia?

i tried this method but didn’t work

y(x) = x^2+1

x = 1:10

scatter(x,y(x))

Try `scatter(x,y.(x))`

dots after function names (`.`

) make functions broadcast (be applied element-wise)

5 Likes

In this case (using `Plots`

)

```
f(x) = x^2 + 1
scatter(f, x)
```

should also work.

I understand you wanted to do a scatter plot, but if you just want to plot a function using Plots, `plot(x->x^2 + 1)`

works as well. I’ve been told that this will work in Makie soon.