5

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.

Fam
  • 507
  • 2
  • 8
  • 1
    I think this is data type issue. With reference to the package repo, I think you are using this `function nlsolve(f, initial_x::AbstractArray; kwargs..)` here the first variable is a function which is `R` for you while the second variable it accepts is supposed to be `Array` while you are supplying a `Float64` number. Try giving input as an type-array. Hopefully, this helps!!! – Mohammad Saad May 28 '21 at 04:38
  • I tried this and kept giving the error: nlsolve (R, [5.8]) – Fam May 28 '21 at 05:08
  • To stay completely in sympy, there is nsolve. Without trying, I’d guess the julia version will be more performance, though perhaps negligibly so. – jverzani May 29 '21 at 00:44

1 Answers1

2

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])
Nils Gudat
  • 13,222
  • 3
  • 39
  • 60
  • Yes, it was me. I posted this question after asking it here. How do you cross-reference? Do I have to edit my question and place the link? – Fam May 28 '21 at 14:05
  • Just in the way I did - post a link to the other place you've asked the question! – Nils Gudat Jun 03 '21 at 09:48