Find zero of a nonlinear equation using Julia

1.3k Views Asked by At

After a process usyng the SymPy in Julia, I generated a system of nonlinear equations. For the sake of simplicity, I am going to put an approximation here for the case of just a non-linear equation. What I get is something like this equation:

R = (p) -> -5.0488*p + p^2.81 - 3.38/( p^(-1.0) )^2.0

I can plot the R function

using Plots
plot(R, 0,8)

We can see that the R function has two zeros: p = 0 and 5.850< p < 8.75. I would like to find the positive zero. For this, I tryed the nlsolve function but with error:

using NLsolve
nlsolve(R , 5.8)

MethodError: no method matching nlsolve(::var"#1337#1338", ::Float64)
Closest candidates are:
nlsolve(::Any, ::Any, !Matched::AbstractArray; inplace, kwargs...)

First, Where am I going wrong with the nlsolve function?

If possible, I will appreciate a solution using SymPy package in Julia.

1

There are 1 best solutions below

2
On BEST ANSWER

This question has been answered on the Julia discourse here: https://discourse.julialang.org/t/find-zero-of-a-nonlinear-equation-using-julia/61974

It's always helpful to cross-reference when asking on multiple platforms.

For reference, the solution was

using NLSolve

function R(F,p) #p is a vector too, not a number
    F[1] = -5.0488*p[1] + p[1]^2.81 - 3.38/( p[1]^(-1.0) )^2.0
end

nlsolve(R , [5.8])