fsolve - Endogenous, Exogenous variables and Constants

3 views (last 30 days)
Hello,
I have a system of nonlinear equations which I need to solve multiple times with different arguments.
This is the function that will be given to fsolve (7 equations 7 unknowns):
function F = myfun(x)
F=[ - x(1) + Cs + gama*( Km - Ks);
x(2)*(gy - 1) + x(1) + x(3);
- x(2) + ((A*x(7))^alpha)*(Km^(1-alpha)) ;
- alpha*x(2)/x(7) + x(6) ;
( ( varrho*x(1)^((1-varrho)*(1 - sigmac)) ) * ( (1 - x(7))^(varrho*(1-sigmac)-1) ) )
/ ( (1-varrho)*x(1)^((1-varrho)*(1 - sigmac) - 1) * ( (1-x(7))^(varrho*(1-sigmac)) ) ) - x(6);
- x(5) - 1 + delta + ((1-alpha)*x(2)) / Km;
- x(3) + x(4) - (1-delta)*Km;
];
end
1. The first problem that I had was that I cannot leave the Endog. variables (those for which we find solution) with their names such as: I, Y, C. Instead I had to rename them as x(1) ... x(n) and remember which field of the vector x is which variable. This makes the system less readable and more difficult to manipulate. Any advice how to avoid this?
2. It appears that any function in F can have only the Endog. arguments x(n) and even though all the: alpha, beta... are defined and have value in the memory when executed the function needs to take everything as an argument. Perhaps for the greeks which are constants I can just replace their value (which will also decrease the flexibility of the code), but for the other Exogenous variables: Cs, Km, Ks. That is impossible as their values will be updated before every fsolve. If I include them in x(n) that is wrong as they are not arguments and don't need to be solved for.
Is there any way to make fsolve take a system of equations which has its vector of arguments but also constants and exogenous variables for which it takes the current values from the memory?
I know that this can all be done with dynare. But I need to do it in Matlab alone.
Thanks

Answers (0)

Categories

Find more on Systems of Nonlinear Equations in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!