I’m trying to run a loop in Pluto, but I’m having a problem with multiple deffinitions, from the way that Pluto passes on variables.
begin
f(x)=x^2-x-20
plot(f,4:.001:12,legend=false)
x=11 # initial value of x # may replace with a @bind later
for i in 1:10
n(x)=x-(f(x)/ForwardDiff.derivative(f,x))# Newton-Rapheson formula
plot!([x,n(x)],[0,f(n(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
x=11
plot!([x,x],[0,f(x)]);vline([5]);hline([0])
end