I am trying to find the roots of an equation using “IntervalRootFinding.jl” package in Pluto.jl notebook. But I am not able to get the roots; could you please check the code?
using IntervalArithmetic, IntervalRootFinding, ForwardDiff
begin
f(x) = a - b * x^2 #Function
∇f = ∇(f) #gradient operator
a = (100..200) #Interval parameters
b = (1..2)
X_int = (0..200) #Interval
rts = roots(f, X_int)
rts_deri = roots(∇f, X_int)
@show rts, rts_deri
end
I think there are just too many roots, the calculation ran for ~20min before I remembered it was still running and interrupted it. Try making only one of a or b an interval and reducing the range of the other until the calculation completes in a reasonable time.
This doesn’t make any sense:
∇f = ∇(f) #gradient operator
f is a function of a scalar value (if you had used .^ and .-, it would accept a vector) and IntervalRootFinding.gradient is only defined for functions of a vector argument. Perhaps you meant to define f as taking a vector or perhaps you meant
Dear @contradict, Thank you for the helpful suggestions. I have checked with what you suggested. But I am still getting nothing. I proceeded with the following code-
begin
f(x) = a - b * x
a = 10
b = (2..3)
X_int = (0..5)
rts = roots(f, X_int)
@show rts
end
Try an even smaller range for b. This returns instantly for me. You don’t need the show at the end, Pluto will print the result of the last evaluation in a cell.
begin
f(x) = a - b * x
a = 10
b = (2.5..3)
X_int = (0..5)
rts = roots(f, X_int)
end