Is there a way to create a line segment in plots?

```
f(x)=2x
plot(f);vline!([f(3), f(4)])
```

How would I get the lines to go from the y origin to f(x) only?

Is there a way to create a line segment in plots?

```
f(x)=2x
plot(f);vline!([f(3), f(4)])
```

How would I get the lines to go from the y origin to f(x) only?

Use the plot command, passing in separately the x and y coordinates of the points on the line(s).

```
vline!([f(3)],0:f(3))
```

something like that?

No, as I said, use the `plot`

command.

`plot([x1, x2], [y1, y2])`

ok, I see, x sequence, then y sequence)

```
f(x)=x^2
plot(f,-1:.001:6)
x=5
for i in 1:10
n(x)=x-(f(x)/ForwardDiff.derivative(f,x))
Plots.plot!([n(x),n(x)],[0,f(x)])
end
```

It won’t create verticle lines (which I was able to create with numbers before)

when I run this, it won’t show verticle line, (which I have done with straight numbers

What does it display?

nothing, no error, and no lines

For loops do not return anything. You need to either give the plot a name and look at the value of that variable, or do plot!() at the end.

I did use a quotation mark, I think I need a recursive deffinition of x, or n(x), for it to go towards 0

I’m trying to do Newton’s method

You are not updating x in your loop.,

```
for i in 1:10
n(x)=x-(f(x)/ForwardDiff.derivative(f,x))
Plots.plot!([n(x),n(x)],[0,f(x)])
x=x-1
end
```

```
for i in 1:10
n(x)=x-(f(x)/ForwardDiff.derivative(f,x))
Plots.plot!([n(x),n(x)],[0,f(n(x))])
x=n(x)
end
```

And then you need `plot!()`

at the end after the `for`

loop, as I already said?