1 ## Copyright (C) 2006,2007,2008 Carlo de Falco
3 ## This file is part of:
4 ## OCS - A Circuit Simulator for Octave
6 ## OCS is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation.
10 ## This program is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ## GNU General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program (see the file LICENSE); if not,
17 ## see <http://www.gnu.org/licenses/>.
19 ## author: Carlo de Falco <cdf _AT_ users.sourceforge.net>
22 ## @deftypefn{Function File} {[@var{out}, @var{niter}]} = nls_stationary @
23 ## (@var{instruct},@var{x},@var{tol},@var{maxit})
24 ## Compute the stationary state solution @var{out} of the system described
27 ## @var{x} is the initial guess used by the Newton-Raphson algorithm implemented in
28 ## @code{nls_newton_raphson}, while @var{tol} and @var{maxit} are the corresponding
31 ## The optional output @var{niter} returns the number of Newton iterations
32 ## needed to reach convergence.
34 ## @seealso{nls_newton_raphson}
37 function [out, varargout] = nls_stationary(outstruct,x,tol,maxit)
40 ## FIXME: add input check!
42 error("nls_stationary: wrong number of input parameters.");
45 [A0,B,C] = asm_initialize_system(outstruct,x);
46 JAC = @(x) TSTSTATFUNJAC(outstruct,x,B);
47 RES = @(x) TSTSTATFUNRES(outstruct,x,B,C);
48 UPD = @(x) TSTSTATUP(outstruct,x);
49 [out,ii,resnrm] = nls_newton_raphson(x,RES,JAC,tol,maxit,0,UPD);
57 ## Jacobian for steady state problems
58 function lhs = TSTSTATFUNJAC(outstruct,x,B,Jac,res)
61 [A1,Jac,res] = asm_build_system(outstruct,x,0);
66 ## Residual for steady state problem
67 function rhs = TSTSTATFUNRES(outstruct,x,B,C,Jac,res)
70 [A1,Jac,res] = asm_build_system(outstruct,x,0);
72 rhs = (res + C + B*x);
75 ## Update for transient problem
76 function update = TSTSTATUP(outstruct,x)
78 [A1,Jac,res] = asm_build_system(outstruct,x,0);