How to calculate non linear function

Never really used Roots.jl before but this should work for you?

julia> using Roots

julia> f(x, p=0.0) = x-sin(x) - p
f (generic function with 2 methods)

julia> Z = ZeroProblem(f, 0.01) # 0.01 is an arbitrary start value
ZeroProblem{typeof(f), Float64}(f, 0.01)

julia> @time solve(Z, p=0.1)
  0.614689 seconds (6.49 M allocations: 312.507 MiB, 21.92% gc time, 99.99% compilation time)
0.8537501566408657

julia> @time solve(Z, p=0.2)
  0.000012 seconds (1 allocation: 16 bytes)
1.083691880314489

julia> @time solve(Z, p=0.3)
  0.000011 seconds (1 allocation: 16 bytes)
1.2485154675427026

julia> @time solve(Z, p=0.4)
  0.000011 seconds (1 allocation: 16 bytes)
1.3822841337179512
1 Like