NonlinearSolve.jl - 'solve' not defined

I am new to Julia, I have been trying to test the NonlinearSolve.jl installation using the Problem Type 1 of “Getting Started with Nonlinear Rootfinding in Julia”, but it always returns the error ’LoadError: UndefVarError: solve not defined’. I am not able to figure out why. I installed the last version of Julia from Microsoft Repository and installed the NonlinearSolve.jl without any warning or error. Could anyone please help me. I have included the test code here.

using NonlinearSolve

f(u, p) = u .* u .- p
u0 = [1.0, 1.0]
p = 2.0
prob = NonlinearProblem(f, u0, p)
sol = solve(prob)

The NonlinearSolve version is v3.10.0

Welcome to the forum!

If you share source code, please enclose it in triple backticks, like ``` for
better readability.

I created a new project:

mkdir nlsolve
cd nlsolve
julia --project="."
using Pkg
pkg"add NonlinearSolve"

put your code into a file with the name test.jl and executed it.

julia --project

julia> include("test.jl")
retcode: Success
u: 2-element Vector{Float64}:

Content of the file test.jl:

using NonlinearSolve
f(u, p) = u .* u .- p
u0 = [1.0, 1.0]
p = 2.0
prob = NonlinearProblem(f, u0, p)
sol = solve(prob)

Seams to work fine for me…

Can you share:

  • the output of the command versioninfo()
  • the output of:
using Pkg


Perhaps this can give us a hint what is the reason of your problem…

The thing that is incredibly strange here is that solve would not be defined after using NonlinearSolve runs successfully. I have a very hard time imagining how his could possibly happen.

1 Like

This is not going to work on Windows.

The first question is where are you running Julia? Did you open the Julia application from the start menu or are you running Julia within another program like Visual Studio Code?
(I suspect a VSCode module issue.)

It works fine on Windows, even with the old style DOS terminal…

1 Like

thank you for your reply. With your instructions the code is working. As stated from Nathan_Boyer I was using Visual Studio Code, so I think is a problem of VSCode configuration. I will study the correct configuration.
The output of the command versioninfo() is:

Julia Version 1.10.2
Commit bd47eca2c8 (2024-03-01 10:14 UTC)
Build Info:
Official release
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: 4 × Intel(R) Core™ i7-5500U CPU @ 2.40GHz
LIBM: libopenlibm
LLVM: libLLVM-15.0.7 (ORCJIT, broadwell)
Threads: 1 default, 0 interactive, 1 GC (on 4 virtual cores)

the output of Pkg.status() is:

Status C:\Users\Giovanni\Julia programs\Project.toml
[8913a72c] NonlinearSolve v3.10.0