# Domain issue when working with nlsolve

**URL:** <https://discourse.julialang.org/t/domain-issue-when-working-with-nlsolve/98193>\
**Category:** New to Julia\
**Tags:** question, optimization, modelling\
**Created:** [May 2, 2023, 12:23pm UTC](https://discourse.julialang.org/t/domain-issue-when-working-with-nlsolve/98193 "2023-05-02T12:23:28Z")\
**Posts on this page:** 1\
**Showing post:** 16

<div class="post-metadata">

**Author:** ![cdestael](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cdestael/32/46700_2.png) [@cdestael](https://discourse.julialang.org/u/cdestael)\
**Post date:** [May 3, 2023, 10:24pm UTC](https://discourse.julialang.org/t/domain-issue-when-working-with-nlsolve/98193/16 "2023-05-03T22:24:46Z")

</div>

Thanks a lot for the followup, @DanDeepPhase!! I’m not having much success with `const ^ = NaNMath.pow` either (see error below). However now I’ve edited the code to use `max(var,0)` as a workaround (based on this post: [DifferentialEquations.jl, Error: Exponentiation yielding a complex result requires a complex argument - #6 by Gregers](https://discourse.julialang.org/t/differentialequations-jl-error-exponentiation-yielding-a-complex-result-requires-a-complex-argument/44935/6)).

```julia
ERROR: cannot assign a value to variable Base.^ from module Main
Stacktrace:
 [1] top-level scope
   @ ~/Dropbox/CORINNE_BU_RA/Julia/calibration/1_calibrate_fe_US.jl:5

```

Updated function:

```julia
function sys_tHE_AB!(F, Z_AB, k_e, fe, Fe, ρ, δ, μ, σ, μj, σj, j) # k_e: (1000, 10, 11) fe: (11, 11) Fe: (11, 11)
    
    ρ = 0.05 # rate of time preference
    δ = 0.05 # exogenous death rate (here also endogenous exit)
    μ=matread("parameters.mat")["mu"]
    σ=matread("parameters.mat")["sigma"]
    μj = μ[j]
    σj = σ[j]
    β = sqrt(2*(ρ + δ)/(σj^2) + (μj/(σj^2) - 1/2)^2) - (μj/(σj^2) - 1/2)
    α = -sqrt(2*(ρ + δ)/(σj^2) + (μj/(σj^2) - 1/2)^2) - (μj/(σj^2) - 1/2)
    disc = ρ + δ - μj

    F[1] = Z_AB[3]*max(Z_AB[1],0)^α + k_e*Z_AB[1]/disc - fe/disc - Fe - Z_AB[4]*max(Z_AB[1],0)^β
    F[2] = Z_AB[3]*max(Z_AB[2],0)^α + k_e*Z_AB[2]/disc - fe/disc - Z_AB[4]*max(Z_AB[2],0)^β
    F[3] = α*Z_AB[3]*max(Z_AB[1],0)^(α-1) + k_e/disc - β*Z_AB[4]*max(Z_AB[1],0)^(β-1)
    F[4] = α*Z_AB[3]*max(Z_AB[2],0)^(α-1) + k_e/disc - β*Z_AB[4]*max(Z_AB[2],0)^(β-1)

    N = [F[1] F[2] F[3] F[4]] 

end

```

---

_[View the full topic](https://discourse.julialang.org/t/domain-issue-when-working-with-nlsolve/98193)._
