On 17/11/2024 12:37, Alecos Papadopoulos wrote:
3. fzero issues: with the fzero function (where i provided only a
single 0.01 initial value), the limitation I see is that we cannot
constraint the value of the argmin (and I need it to be in (0,1) for
example).
The best solution in many cases is to map the constrained variable to an
unconstrained one via an invertible transformation: in the example below
I use the logistic function to find a root within there (0,1) interval,
but of course you have lots of alternatives:
<hansl>
set verbose off
clear
function scalar f(scalar z)
x = logistic(z)
### function whose solutions are 1/3 and 2
return (x-1/3)*(x-2)
end function
z_init = {-100, 100}
sol = fzero(f(z), z_init)
x = logistic(sol)
print sol x
</hansl>
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------