Skip to content

Not finding a zero for a fairly simple problem #187

Closed
@elbert5770

Description

@elbert5770

This doesn't find the zero at u = 0.070720181679945, using either a bounded or unbounded method. Is this a problem with the setup or is it more fundamental?

using NonlinearSolve
using Plots

f(u) = 0.5/1.5*log.(u./(1.0.-u)) .- 2.0*u .+1.0

uspan = (0.02, 0.1) # brackets
probB = IntervalNonlinearProblem(f, uspan)
sol = solve(probB, Falsi())
@show sol.u

u0 = 0.06
p = 2.0
probN = NonlinearProblem(f, u0, p)
solver = solve(probN, NewtonRaphson(), reltol = 1e-9)
@show solver.u

@show f(0.070720181679945)

c = collect(0.01:0.001:0.99)
plot(c,f(c))

And the output is:

sol.u = 0.10000000000000002
solver.u = 0.5
f(0.070720181679945) = 6.661338147750939e-16

Here's MATLAB code that gives the correct answer using both a bounded and unbounded method:

function test
u = linspace(0.01,0.99);
for i = 1:length(u)
   y(i) = f(u(i));
end
%plot(u,y)
x0 = [0.02 0.1]
z1 = fzero(@f,x0)
z2 = fzero(@f,0.06)

function y = f(u)
y = 0.5/1.5*log(u./(1.0 - u)) - 2.0 .*u + 1.0;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions