This code generator supplies MATLAB code for solution of an algebraic equation system with fsolve. Critical operations are relaxed, by the following procedure: log(x) and 1/x are written with as log(x+epsilon) and 1/(x+epsilon). The system is first solved with ZERO set to 1E-9 and in a second run with ZERO = 0.
Required Environment
Required Solver
- fsolve (preinstalled wiath MATLAB)
User Options
- TolFun: MATLAB’s option to set the convergence criterion for fsolve. For more information refer to MATLAB’s documentation
- MaxIter: MATLAB’s option to set the maximum number of iterations for fsolve. For more information refer to MATLAB’s documentation.
- MaxFunEvals: MATLAB’s option to set the maximum number of function evaluations of the algebraic system by fsolve. For more information refer to MATLAB’s documentation.
- Reuse Jacobian: If this option is set to “yes”, MOSAIC reuses the derivatives from a previous run. The user has to decided if something has changed and if it is necessary to regenerate the derivatives. The generation of the derivatives of course takes some time.
- Reuse Jacobian Pattern: If yes, MOSAIC reuses the old Jacobian pattern from a previous code generation
Usage for Simulation
- Open an NLE Evaluation in MOSAIC
- Set the variable specs to obtain a degree of freedom of zero.
- Select the Predefined Language Specification “MATLAB NLE”.
- Choose the Code Generator and Solver Properties in accordance with the User Options above.
- Press Generate Code.
- Copy everything from the View Code tab and paste it to a new m-file inside MATLAB’s IDE.
- Save the new m-file
- Press run inside MATLAB’s IDE.
- After completion the results appear in MATLAB’s command line window.
- Copy the lines containing the variable names and their final values and paste them into the Import tab of MOSAIC’s evaluation environment.
- Select the Predefined Language Specification “MATLAB NLE” and press Import.
- The results will automatically update the Initial values in the Variable Specification tab and can be saved for future use by pressing Save As.