# How to plot Newton's method

**URL:** <https://discourse.julialang.org/t/how-to-plot-newtons-method/51160>\
**Category:** Optimization (Mathematical)\
**Tags:** question, plotting, math\
**Created:** [December 3, 2020, 12:59am UTC](https://discourse.julialang.org/t/how-to-plot-newtons-method/51160 "2020-12-03T00:59:22Z")\
**Posts on this page:** 6\
**Page:** 3

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [February 22, 2021, 11:31pm UTC](https://discourse.julialang.org/t/how-to-plot-newtons-method/51160/41 "2021-02-22T23:31:30Z")

</div>

It doesn’t look like Newton’s Method, looks more like Lipp’s Method.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [February 22, 2021, 11:34pm UTC](https://discourse.julialang.org/t/how-to-plot-newtons-method/51160/42 "2021-02-22T23:34:24Z")

</div>

Why do you say it doesn’t look like the Newton method, and what is Lipp’s method?

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [February 22, 2021, 11:45pm UTC](https://discourse.julialang.org/t/how-to-plot-newtons-method/51160/43 "2021-02-22T23:45:21Z")

</div>

The way it jumps back and forth, it does use a tangent though, and it’s still using a curve.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [February 22, 2021, 11:59pm UTC](https://discourse.julialang.org/t/how-to-plot-newtons-method/51160/44 "2021-02-22T23:59:22Z")

</div>

@j_verzani very nice interactive code using Makie, looks like Newton method to me. And curves display beyond the canvas!

Some snapshots below for the function:  
`function newton(f=x-> (x/2)^3 - x, x0=1, a=-4, b=4, n=20)`:

 ![Newton1](https://global.discourse-cdn.com/julialang/original/3X/c/a/ca6fead1f4f714e1f13e10be81211d1f252af476.png)  
 ![Newton2](https://global.discourse-cdn.com/julialang/original/3X/e/4/e4fc08d2d08c571f647f3be6b219dae1663d3049.png)  
 ![Newton3](https://global.discourse-cdn.com/julialang/original/3X/7/8/7867c511f4b42b49ef1ea9ed2291a658d29b101b.png)

_PS: display could be improved further, by showing the zero solution found, etc._

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [February 23, 2021, 12:03am UTC](https://discourse.julialang.org/t/how-to-plot-newtons-method/51160/45 "2021-02-23T00:03:41Z")

</div>

ok, I think it depends on the starting poin. It does work good. I was just trying to start with something simpler. I will definatly look it over, and see what all there is for options.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [February 23, 2021, 3:29am UTC](https://discourse.julialang.org/t/how-to-plot-newtons-method/51160/46 "2021-02-23T03:29:14Z")

</div>

I did a simpler version with Plots.jl

```julia
function ralpheson(x)
	f(x)=x^2-sqrt(3)
	plot(f,0:.001:3.3,legend=false)
	plot!([x,x],[0,f(x)])
	for i in 1:45
		n(x)=x-(f(x)/ForwardDiff.derivative(f,x))# Newton-Rapheson formula
		plot!([n(x),x],[0,f((x))],legend=false)
		plot!([n(x),n(x)],[0,f(n(x))],legend=false)# plots each itteration
		x=n(x)# recursion is used to reset x
	end
	plot!()
end

```

I think I’m going to figure out how to use @bind, to make it interactive.

[Previous page](https://discourse.julialang.org/t/how-to-plot-newtons-method/51160.md?page=2)
