/* SCCS @(#)NslDiff.java 1.7 --- %% -- %% */ // Copyright: Copyright (c) 1997 University of Southern California Brain Project. // Copyright: This software may be freely copied provided the toplevel // Copyright: COPYRIGHT file is included with each such copy. // Copyright: Email nsl@java.usc.edu. /* * $Log: NslDiff.java,v $ * Revision 1.2 1997/06/13 22:47:10 erhan * 'NslMain takes model name as a parameter, npp:verbatim_on verbatim_off semi-column stuff, NslModule: method to setup display variables ' * * Revision 1.1.1.1 1997/03/12 22:52:20 nsl * new dir structure * * Revision 1.1.1.1 1997/02/08 00:40:40 nsl * Imported the Source directory * */ // // NslDiff.java // ////////////////////////////////////////////////////////////////////// /** * Differentiation methods. Refer to nsl_diff_method.C in NSL2.8 */ package nslj.src.math; import nslj.src.lang.*; import nslj.src.system.NslSystem; public abstract class NslDiff { double _dt = 0.1; //Approximation Delta double _tm = 1.0; //TimeConstant NslSystem system; /** * Constructor: set default parameter of the differentiation * method from the system. * @param sys - system it belongs */ public NslDiff(NslSystem sys) { system=sys; _dt=system.nslGetApproximationDelta(); _tm=system.nslGetApproximationTimeConstant(); } /** * Constructor. * @param dt - default delta or run step size * @param tm - default time constant */ public NslDiff(double dt, double tm) { _dt = dt; _tm = tm; } public void setDelta(double step) { _dt = step; } public void nslSetApproximationDelta(double time) { _dt = time; } public void nslSetApproximationTimeConstant(double time) { _tm = time; } // 0d doubles public abstract double value(double out, double input, double dt, double tm); public double eval(double out, double inputexpr) { return value(out, inputexpr, _dt, _tm); } public double eval(double out, double tm, double inputexpr) { return value(out, inputexpr, _dt, tm); } public double eval(double out, double tm, double dt, double inputexpr) { return value(out, inputexpr, dt, tm); } public double eval(NslModule module, double out, double inputexpr) { return value(out, inputexpr, module.nslGetDelta(), module.nslGetApproximationDelta()); } public double eval(NslModule module, double out, double tm, double inputexpr) { return value(out, inputexpr, module.nslGetDelta(), tm); } // 1d doubles public double[] eval(double[] out, double[] inputexpr) { return eval(out, _tm, _dt, inputexpr); } public double[] eval(double[] out, double tm, double[] inputexpr) { return eval(out, tm, _dt, inputexpr); } public double[] eval(double[] out, double tm, double dt, double[] inputexpr) { int length = out.length; if (length!=inputexpr.length) { System.err.println("NslDiffEuler: different length for LHS("+ length+") and RHS("+inputexpr.length+")"); } int i; for(i=0; i