-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbisection.jl
More file actions
33 lines (25 loc) · 824 Bytes
/
bisection.jl
File metadata and controls
33 lines (25 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module bisection
function exptan(xl::Number, xr::Number; absvalue::Number=1e-5, iterations::Number=1000)
local xc
local fc
for j = 1:iterations # j cuts the interval
xc = (xl + xr) / 2; # calculate the midpoint
fc = exp.(xc) - tan(xc) # calculate function
if fc > 0
xl = xc; # move left boundary
else
xr = xc; # move right boundary
end
if abs(fc) < absvalue
break # quit the loop
end
end
xc, fc # return value of root and function
end
using Plots # load Plots
plotly() # use plotly as backend
x=-4:0.1:3
y=exp.(x) - tan.(x)
plot(x, y, show=true)
print(exptan(-4, -2.8, absvalue=1e-5))
end # modul bisection