Hi, I’ve been working on a program recently but I can’t find where I went wrong, I need help.
It’s a simple program that makes recurrences.
Here’s my code:
using NLsolve
function systeme!(S,x)
S[1]=f(f(x[1],x[2],x[3],x[4]),g(x[1],x[2],x[3],x[4]))-x[1]
S[2]=g(f(x[1],x[2],x[3],x[4]),g(x[1],x[2],x[3],x[4]))-x[2]
end
function fonction(f,g,k,x,y,a,b)
for i in 1:k
x_temp=x
x=f(x,y,a,b)
y=g(x_temp,y,a,b)
end
xyab=[x,y,a,b]
sol=nlsolve(systeme!,xyab)
return (x,y),sol
end
f(x,y,a,b)=x^2.0+y
g(x,y,a,b)=x-2
fonction(f,g,3.0,1.4142,-0.5858,0.1,0.2)
Here’s what is returned in the REPL with the entire stacktrace:
ERROR: LoadError: MethodError: no method matching f(::Float64, ::Float64)
Closest candidates are:
f(::Any, ::Any, ::Any, ::Any) at c:\Users\Maxime\Desktop\Stage_2021\Julia\testFontction.jl:21
Stacktrace:
[1] systeme!(S::Vector{Float64}, x::Vector{Float64})
@ Main c:\Users\Maxime\Desktop\Stage_2021\Julia\testFontction.jl:4
[2] (::NLSolversBase.var"#fj_finitediff!#21"{typeof(systeme!), FiniteDiff.JacobianCache{Vector{Float64}, Vector{Float64}, Vector{Float64}, UnitRange{Int64}, Nothing, Val{:central}(), Float64}})(F::Vector{Float64}, J:M
atrix{Float64}, x::Vector{Float64})
@ NLSolversBase C:\Users\Maxime\.julia\packages\NLSolversBase\geyh3\src\objective_types\oncedifferentiable.jl:138
[3] value_jacobian!!(obj::OnceDifferentiable{Vector{Float64}, Matrix{Float64}, Vector{Float64}}, F::Vector{Float64}, J::Matrix{Float64}, x::Vector{Float64})
@ NLSolversBase C:\Users\Maxime\.julia\packages\NLSolversBase\geyh3\src\interface.jl:124
[4] value_jacobian!!
@ C:\Users\Maxime\.julia\packages\NLSolversBase\geyh3\src\interface.jl:122 [inlined]
[5] trust_region_(df::OnceDifferentiable{Vector{Float64}, Matrix{Float64}, Vector{Float64}}, initial_x::Vector{Float64}, xtol::Float64, ftol::Float64, iterations::Int64, store_trace::Bool, show_trace::Bool, extended_trace::Bool, factor::Float64, autoscale::Bool, cache::NLsolve.NewtonTrustRegionCache{Vector{Float64}})
@ NLsolve C:\Users\Maxime\.julia\packages\NLsolve\gJL1I\src\solvers\trust_region.jl:119
[6] trust_region (repeats 2 times)
@ C:\Users\Maxime\.julia\packages\NLsolve\gJL1I\src\solvers\trust_region.jl:235 [inlined]
[7] nlsolve(df::OnceDifferentiable{Vector{Float64}, Matrix{Float64}, Vector{Float64}}, initial_x::Vector{Float64}; method::Symbol, xtol::Float64, ftol::Float64, iterations::Int64, store_trace::Bool, show_trace::Bool, extended_trace::Bool, linesearch::Static, linsolve::NLsolve.var"#29#31", factor::Float64, autoscale::Bool, m::Int64, beta::Int64, aa_start::Int64, droptol::Float64)
@ NLsolve C:\Users\Maxime\.julia\packages\NLsolve\gJL1I\src\nlsolve\nlsolve.jl:26
[8] nlsolve(f::Function, initial_x::Vector{Float64}; method::Symbol, autodiff::Symbol, inplace::Bool, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ NLsolve C:\Users\Maxime\.julia\packages\NLsolve\gJL1I\src\nlsolve\nlsolve.jl:52
[9] nlsolve(f::Function, initial_x::Vector{Float64})
@ NLsolve C:\Users\Maxime\.julia\packages\NLsolve\gJL1I\src\nlsolve\nlsolve.jl:46
[10] fonction(f::typeof(f), g::typeof(g), k::Float64, x::Float64, y::Float64, a::Float64, b::Float64)
@ Main c:\Users\Maxime\Desktop\Stage_2021\Julia\testFontction.jl:17
[11] top-level scope
@ c:\Users\Maxime\Desktop\Stage_2021\Julia\testFontction.jl:24
in expression starting at c:\Users\Maxime\Desktop\Stage_2021\Julia\testFontction.jl:24
I’m kinda new to this language and it seems hard for me to understand some errors. Thanks in advance.