I’m facing an issue with NLSolve. I have two interacting functions that are working well, and I need to adapt them. Let me briefly summarize how the functions are currently set up and what I’m aiming to achieve.

Firstly, I have a function that calculates the government deficit:

```
function deficit(t)
tax_h, tax_l = t[1], t[2]
# Lots of calculations
dif_tax = (ep_h * wp_h * tax_h - (eg_h * wg_h)) + (ep_l * wp_l * tax_l - (eg_l * wg_l))
F = [dif_tax]
return F
end
```

Then, I’m using another function that incorporates the `deficit`

function within it, like this:

```
function solvemodeltax(chute_param, chute_th, chute_tl)
chute_t = [chute_th, chute_tl]
taxopt = nlsolve(x -> deficit(x), chute_t).zero
tax_h = taxopt[1]
tax_l = taxopt[2]
# Lots of calculations
return output
end
```

And this is working fine. However, I’m aiming to perform a counterfactual exercise where the government needs to balance the budget for each specific sector (noting that H represents high skill and L represents low skill). Consequently, I’ve modified the code as follows

```
function deficit_separatesector(t)
tax_h, tax_l = t[1], t[2]
# Lots of calculations
dif_taxh = ep_h * wp_h * tax_h - (eg_h * wg_h)
dif_taxl = ep_l * wp_l * tax_l - (eg_l * wg_l)
F = [dif_taxh, dif_taxl]
return F
end
```

In this case, the return is no longer a one-element array, but a two-element collection representing the deficit for each type of worker. Consequently, I adapted the solving function as follows (with a focus on the relevant parts):

```
function solvemodeltax_v2(chute_param, chute_th, chute_tl)
chute_t = [chute_th, chute_tl]
taxopt = nlsolve(x -> deficit_separatesector(x, kappa_h=kappa_h, kappa_l=kappa_l, b_h=b_h, b_l=b_l, y_h=y_h), chute_t).zero
tax_h = taxopt[1]
tax_l = taxopt[2]
# Lots of calculations
return output
end
```

In this last part, this final NLSolve is where the code encounters issues. The dimensions seem correct, and everything else appears fine, but I’m uncertain why it’s unable to find a solution. Is this an error within the code or a theoretical problem? Is there anything I can do to improve it?

From my perspective, it should work since the deficits are interlinked, suggesting that it’s possible (due to function continuity) to find a rate that optimally combines both sectors.

Note: I haven’t provided the entire function details, only the main aspects, as they are quite extensive. I believe this should give you an understanding of my point and the challenges.