mathlib-commitlog Mailing List for JMathLib - Octave, Matlab clone in java (Page 45)
Status: Beta
Brought to you by:
st_mueller
You can subscribe to this list here.
| 2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(2) |
Jul
(4) |
Aug
(150) |
Sep
|
Oct
|
Nov
|
Dec
(2) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2007 |
Jan
(233) |
Feb
(86) |
Mar
(32) |
Apr
(26) |
May
(73) |
Jun
(45) |
Jul
(23) |
Aug
(23) |
Sep
(5) |
Oct
(80) |
Nov
(11) |
Dec
(11) |
| 2008 |
Jan
|
Feb
|
Mar
(13) |
Apr
(3) |
May
(7) |
Jun
(30) |
Jul
(12) |
Aug
(12) |
Sep
|
Oct
|
Nov
(78) |
Dec
(78) |
| 2009 |
Jan
(214) |
Feb
(79) |
Mar
(20) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Stefan M. <st_...@us...> - 2007-01-12 21:48:34
|
Update of /cvsroot/mathlib/mathlib/Source/MathLib/Functions/Matrix In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv637/Source/MathLib/Functions/Matrix Added Files: abs.java Log Message: --- NEW FILE: abs.java --- package MathLib.Functions.Matrix; import MathLib.Functions.ExternalElementWiseFunction; public class abs extends ExternalElementWiseFunction { public abs() { name = "abs"; } /**Standard functions - absolute value * @param double array * @return the result as a double array */ public double[] evaluateValue(double[] arg) { double[] result = new double[2]; if (arg[IMAG]==0) { result[REAL] = Math.abs(arg[REAL]); result[IMAG] = 0; } else { result[REAL] = Math.sqrt(arg[REAL]*arg[REAL] + arg[IMAG]*arg[IMAG]); result[IMAG] = 0; } return result; } } /* @GROUP matrix @SYNTAX abs(value) @DOC Returns the absolute positive value of value. @NOTES @EXAMPLES abs(-5) = 5 abs(2) = 2 abs(3 + 4I) = 5 */ |
|
From: Stefan M. <st_...@us...> - 2007-01-12 21:38:46
|
Update of /cvsroot/mathlib/mathlib/Source/MathLib/Functions/Matrix In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv28873/Source/MathLib/Functions/Matrix Added Files: exp.java Log Message: --- NEW FILE: exp.java --- package MathLib.Functions.Matrix; import MathLib.Functions.ExternalElementWiseFunction; public class exp extends ExternalElementWiseFunction { public exp() { name = "exp"; } /**Calculates the exponent of a complex number @param arg = the value as an array of double @return the result as an array of double*/ public double[] evaluateValue(double[] arg) { double[] result = new double[2]; double scalar = Math.exp(arg[REAL]); // e^ix = cis x result[REAL] = scalar * Math.cos(arg[IMAG]); result[IMAG] = scalar * Math.sin(arg[IMAG]); return result; } } /* @GROUP general @SYNTAX exp(value) @DOC . @EXAMPLES exp(-5.5) = -5 exp(2.3) = 3 @SEE log, ln */ |
|
From: Stefan M. <st_...@us...> - 2007-01-12 21:35:26
|
Update of /cvsroot/mathlib/mathlib/Source/MathLib/Functions/Trigonometric In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv27564/Source/MathLib/Functions/Trigonometric Added Files: acosh.java Log Message: --- NEW FILE: acosh.java --- package MathLib.Functions.Trigonometric; import MathLib.Functions.ExternalElementWiseFunction; import MathLib.Functions.Matrix.sqrt; import MathLib.Functions.Matrix.log; public class acosh extends ExternalElementWiseFunction { public acosh() { name = "acosh"; } /**Calculates the inverse hyperbolic cosine of a complex number @param arg = the angle as an array of double @return the result as an array of double*/ public double[] evaluateValue(double[] arg) { double result[] = new double[2]; // acosh(z) = log(z + Sqrt(z*z - 1)) double re = arg[REAL]; double im = arg[IMAG]; // _1: z.Times(z).Minus(one) ... result[REAL] = ( (re*re) - (im*im) ) - 1.0; result[IMAG] = ( (re*im) + (im*re) ) - 0.0; // result: _1.Sqrt() ... sqrt sqrtF = new sqrt(); result = sqrtF.evaluateValue(result); // result: z.Plus(result) ... result[REAL] = re + result[REAL]; // ! result[IMAG] = im + result[IMAG]; // ! // _1: result.log() ... log logF = new log(); result = logF.evaluateValue(result); // result: _1 ... return result; } } /* @@GROUP trigonometric @SYNTAX angle = ACOS(value) @DOC Returns the arc cosine of value. @EXAMPLES ACOS(1) = 0 ACOS(0) = 1.5707963267948966 @SEE cos, acosh */ |
|
From: Stefan M. <st_...@us...> - 2007-01-12 21:25:44
|
Update of /cvsroot/mathlib/mathlib/Source/MathLib/Functions/Trigonometric In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv23447/Source/MathLib/Functions/Trigonometric Added Files: coth.java Log Message: --- NEW FILE: coth.java --- package MathLib.Functions.Trigonometric; import MathLib.Functions.ExternalElementWiseFunction; import MathLib.Tokens.NumberToken; public class coth extends ExternalElementWiseFunction { public coth() { name = "coth"; } /**trigonometric functions - calculate the hyperbolic cotangent of this token * @param double value * @return the result as a double array */ public double[] evaluateValue(double[] arg) { NumberToken num = new NumberToken(); tanh tanhF = new tanh(); double[] temp = tanhF.evaluateValue(arg); double[] result = num.divide(new double[]{1,0}, temp); return result; } } /* @GROUP trigonometric @SYNTAX coth(value) @DOC . @NOTES @EXAMPLES . @SEE sec, csc, csch, sech, cot */ |
|
From: Stefan M. <st_...@us...> - 2007-01-12 21:23:59
|
Update of /cvsroot/mathlib/mathlib/Source/MathLib/Functions/Trigonometric In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv22630/Source/MathLib/Functions/Trigonometric Added Files: csch.java Log Message: --- NEW FILE: csch.java --- package MathLib.Functions.Trigonometric; import MathLib.Functions.ExternalElementWiseFunction; import MathLib.Tokens.NumberToken; public class csch extends ExternalElementWiseFunction { public csch() { name = "csch"; } /**trigonometric functions - calculate the cosecant of this token * @param double value * @return the result as a double array */ public double[] evaluateValue(double[] arg) { NumberToken num = new NumberToken(); sinh sinhF = new sinh(); double[] temp = sinhF.evaluateValue(arg); double[] result = num.divide(new double[]{1,0}, temp); return result; } } /* @GROUP trigonometric @SYNTAX cscd(value) @DOC . @NOTES @EXAMPLES . @SEE sec, cot, csch, sech, coth */ |
|
From: Stefan M. <st_...@us...> - 2007-01-12 21:21:58
|
Update of /cvsroot/mathlib/mathlib/Source/MathLib/Functions/Trigonometric In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv21812/Source/MathLib/Functions/Trigonometric Added Files: cot.java Log Message: --- NEW FILE: cot.java --- package MathLib.Functions.Trigonometric; import MathLib.Functions.ExternalElementWiseFunction; import MathLib.Tokens.NumberToken; public class cot extends ExternalElementWiseFunction { public cot() { name = "cot"; } /**trigonometric functions - calculate the cotangent of this token * @param double value * @return the result as a double array */ public double[] evaluateValue(double[] arg) { NumberToken num = new NumberToken(); tan tanFunc = new tan(); double[] temp = tanFunc.evaluateValue(arg); double[] result = num.divide(new double[]{1,0}, temp); return result; } } /* @GROUP trigonometric @SYNTAX cot(value) @DOC . @NOTES @EXAMPLES . @SEE sec, csc, csch, sech, coth */ |
|
From: Stefan M. <st_...@us...> - 2007-01-12 21:19:55
|
Update of /cvsroot/mathlib/mathlib/Source/MathLib/Functions/Trigonometric In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv20952/Source/MathLib/Functions/Trigonometric Added Files: sec.java Log Message: --- NEW FILE: sec.java --- package MathLib.Functions.Trigonometric; import MathLib.Functions.ExternalElementWiseFunction; import MathLib.Tokens.NumberToken; public class sec extends ExternalElementWiseFunction { public sec() { name = "sec"; } /**trigonometric functions - calculate the secans of this token @param double value @return the result as an OperandToken */ public double[] evaluateValue(double[] arg) { NumberToken num = new NumberToken(); cos cosF = new cos(); double[] temp = cosF.evaluateValue(arg); double[] result = num.divide(new double[]{1,0}, temp); return result; } } /* @GROUP trigonometric @SYNTAX sec(value) @DOC . @NOTES @EXAMPLES . @SEE csc, cot, csch, sech, coth */ |
|
From: Stefan M. <st_...@us...> - 2007-01-12 21:17:35
|
Update of /cvsroot/mathlib/mathlib/Source/MathLib/Functions/Trigonometric In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv20092/Source/MathLib/Functions/Trigonometric Added Files: sin.java Log Message: --- NEW FILE: sin.java --- package MathLib.Functions.Trigonometric; import MathLib.Functions.ExternalElementWiseFunction; public class sin extends ExternalElementWiseFunction { public sin() { name = "sin"; } /**Calculates the sine of a complex number * @param arg = the angle as an array of double * @return the result as an array of double * */ public double[] evaluateValue(double[] arg) { double result[] = new double[2]; double scalar; double iz_re, iz_im; double _re1, _im1; double _re2, _im2; // iz: i.Times(z) ... iz_re = -arg[IMAG]; iz_im = arg[REAL]; // _1: iz.exp() ... scalar = Math.exp(iz_re); _re1 = scalar * Math.cos(iz_im); _im1 = scalar * Math.sin(iz_im); // _2: iz.neg().exp() ... scalar = Math.exp(-iz_re); _re2 = scalar * Math.cos(-iz_im); _im2 = scalar * Math.sin(-iz_im); // _1: _1.Minus(_2) ... _re1 = _re1 - _re2; // !!! _im1 = _im1 - _im2; // !!! // result: _1.Div(2*i) ... result[REAL] = 0.5*_im1; result[IMAG] = -0.5*_re1; return result; } } /* @@GROUP trigonometric @SYNTAX answer = sin(angle) @DOC Returns the sine of angle. @EXAMPLES sin(0) = 0 sin(1.5708) = 1 @SEE asin, sinh */ |
|
From: Stefan M. <st_...@us...> - 2007-01-12 21:15:33
|
Update of /cvsroot/mathlib/mathlib/Source/MathLib/Functions In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv19291/Source/MathLib/Functions Modified Files: ExternalElementWiseFunction.java Log Message: code update Index: ExternalElementWiseFunction.java =================================================================== RCS file: /cvsroot/mathlib/mathlib/Source/MathLib/Functions/ExternalElementWiseFunction.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ExternalElementWiseFunction.java 10 Jan 2007 18:49:47 -0000 1.1 --- ExternalElementWiseFunction.java 12 Jan 2007 21:15:29 -0000 1.2 *************** *** 12,16 **** * standard function for evaluation of general external functions * @param operands ! * @retrun */ public OperandToken evaluate(Token[] operands) --- 12,16 ---- * standard function for evaluation of general external functions * @param operands ! * @return */ public OperandToken evaluate(Token[] operands) *************** *** 47,51 **** // all subclasses of this cluss MUST implement the method below abstract public double[] evaluateValue(double[] complex); ! } --- 47,52 ---- // all subclasses of this cluss MUST implement the method below + //abstract public double[] evaluateValue(double[] complex); abstract public double[] evaluateValue(double[] complex); ! } |
|
From: Stefan M. <st_...@us...> - 2007-01-12 21:14:00
|
Update of /cvsroot/mathlib/mathlib/Source/MathLib/Functions/Trigonometric In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv18445/Source/MathLib/Functions/Trigonometric Added Files: cos.java Log Message: --- NEW FILE: cos.java --- package MathLib.Functions.Trigonometric; import MathLib.Functions.ExternalElementWiseFunction; public class cos extends ExternalElementWiseFunction { public cos() { name = "cos"; } /**trigonometric functions - calculate the cosine of this token * @param array of a double value * @return the result as an OperandToken * */ public double[] evaluateValue(double[] arg) { double result[] = new double[2]; double scalar; double iz_re, iz_im; double _re1, _im1; double _re2, _im2; // iz: i.Times(z) ... iz_re = -arg[IMAG]; iz_im = arg[REAL]; // _1: iz.exp() ... scalar = Math.exp(iz_re); _re1 = scalar * Math.cos(iz_im); _im1 = scalar * Math.sin(iz_im); // _2: iz.neg().exp() ... scalar = Math.exp(-iz_re); _re2 = scalar * Math.cos(-iz_im); _im2 = scalar * Math.sin(-iz_im); // _1: _1.Plus(_2) ... _re1 = _re1 + _re2; // !!! _im1 = _im1 + _im2; // !!! // result: _1.scale(0.5) ... result[REAL] = 0.5*_re1; result[IMAG] = -0.5*_im1; return result; } } /* @GROUP trigonometric @SYNTAX cos(angle) @DOC Returns the cosine of angle. @EXAMPLES cos(0) = 1 cos(1.5707963267948966) = 0 @SEE acos, cosh */ |
|
From: Stefan M. <st_...@us...> - 2007-01-12 21:12:29
|
Update of /cvsroot/mathlib/mathlib/Source/MathLib/Functions/Trigonometric In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv18009/Source/MathLib/Functions/Trigonometric Added Files: csc.java Log Message: --- NEW FILE: csc.java --- package MathLib.Functions.Trigonometric; import MathLib.Functions.ExternalElementWiseFunction; import MathLib.Tokens.NumberToken; public class csc extends ExternalElementWiseFunction { public csc() { name = "csc"; } /**trigonometric functions - calculate the cosine of this token @param double value @return the result as an OperandToken */ public double[] evaluateValue(double[] arg) { NumberToken num = new NumberToken(); sin sinFunc = new sin(); double[] temp = sinFunc.evaluateValue(arg); double[] result = num.divide(new double[]{1,0}, temp); return result; } } /* @GROUP trigonometric @SYNTAX csc(value) @DOC . @NOTES @EXAMPLES . @SEE sec, cot, csch, sech, coth */ |
|
From: Stefan M. <st_...@us...> - 2007-01-12 21:07:27
|
Update of /cvsroot/mathlib/mathlib/Source/MathLib/Functions/Matrix In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv15857/Source/MathLib/Functions/Matrix Added Files: floor.java Log Message: --- NEW FILE: floor.java --- package MathLib.Functions.Matrix; import MathLib.Functions.ExternalElementWiseFunction; public class floor extends ExternalElementWiseFunction { public floor() { name = "floor"; } /**Standard functions - rounds the value down @param double array @return the result as an OperandToken */ public double[] evaluateValue(double[] arg) { double[] result = new double[2]; result[REAL] = Math.floor(arg[REAL]); result[IMAG] = Math.floor(arg[IMAG]); return result; } } /* @GROUP matrix @SYNTAX floor(value) @DOC Rounds the value of the first operand down to the nearest integer. @EXAMPLES floor(-5.5) = -6 floor(2.3) = 2 @SEE ceil, round */ |
|
From: Stefan M. <st_...@us...> - 2007-01-12 21:05:13
|
Update of /cvsroot/mathlib/mathlib/Source/MathLib/Functions/Matrix In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv14649/Source/MathLib/Functions/Matrix Added Files: ceil.java Log Message: --- NEW FILE: ceil.java --- package MathLib.Functions.Matrix; import MathLib.Functions.ExternalElementWiseFunction; public class ceil extends ExternalElementWiseFunction { public ceil() { name = "ceil"; } /**Standard functions - rounds the value up @return the result as a double array */ public double[] evaluateValue(double[] arg) { double[] result = new double[2]; result[REAL] = Math.ceil(arg[REAL]); result[IMAG] = Math.ceil(arg[IMAG]); return result; } } /* @GROUP @GROUP general @SYNTAX ceil(value) @DOC Rounds the value of the first operand up to the nearest integer @EXAMPLES ceil(-5.5) = -5 ceil(2.3) = 3 @SEE floor, round */ |
|
From: Stefan M. <st_...@us...> - 2007-01-12 21:03:15
|
Update of /cvsroot/mathlib/mathlib/Source/MathLib/Functions/Matrix In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv14155/Source/MathLib/Functions/Matrix Added Files: sqrt.java Log Message: --- NEW FILE: sqrt.java --- package MathLib.Functions.Matrix; import MathLib.Functions.ExternalElementWiseFunction; public class sqrt extends ExternalElementWiseFunction { public sqrt() { name = "sqrt"; } /**Calculates the sqrt of a complex number @param arg = the value as an array of double @return the result as an array of double*/ public double[] evaluateValue(double[] arg) { // with thanks to Jim Shapiro <jn...@ar...> // adapted from "Numerical Recipies in C" (ISBN 0-521-43108-5) // by William H. Press et al double[] result = new double[2]; double re = arg[REAL]; double im = arg[IMAG]; double temp = Math.pow(re, 2) + Math.pow(im, 2); double mag = Math.sqrt(temp); if (mag > 0.0) { if (re > 0.0) { temp = Math.sqrt(0.5 * (mag + re)); re = temp; im = 0.5 * im / temp; } else { temp = Math.sqrt(0.5 * (mag - re)); if (im < 0.0) { temp = -temp; } re = 0.5 * im / temp; im = temp; } } else { re = 0.0; im = 0.0; } result[REAL] = re; result[IMAG] = im; return result; } } /* @GROUP general @SYNTAX answer = sqrt(value) @DOC Returns the sqrt of a value. @EXAMPLES sqrt(4) = 2 sqrt(9) = 3 @NOTES @SEE angle, abs */ |
|
From: Stefan M. <st_...@us...> - 2007-01-12 21:01:49
|
Update of /cvsroot/mathlib/mathlib/Source/MathLib/Functions/Matrix In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv13326/Source/MathLib/Functions/Matrix Added Files: log.java Log Message: --- NEW FILE: log.java --- package MathLib.Functions.Matrix; import MathLib.Functions.ExternalElementWiseFunction; public class log extends ExternalElementWiseFunction { public log() { name = "log"; } /**Calculates the logarythm of a complex number @param arg = the value as an array of double @return the result as an array of double*/ public double[] evaluateValue(double[] arg) { double[] result = new double[2]; double temp = Math.pow(arg[REAL], 2) + Math.pow(arg[IMAG], 2); temp = Math.sqrt(temp); result[REAL] = Math.log(temp); result[IMAG] = Math.atan2(arg[IMAG], arg[REAL]); return result; } } /* @GROUP matrix @SYNTAX answer = log(value, base) @DOC Returns the logarithm of value to the base base. @EXAMPLES <programlisting> </programlisting> @SEE ln */ |
|
From: Stefan M. <st_...@us...> - 2007-01-12 21:00:44
|
Update of /cvsroot/mathlib/mathlib/Source/MathLib/Functions/Matrix In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv12873/Source/MathLib/Functions/Matrix Added Files: ln.java Log Message: --- NEW FILE: ln.java --- package MathLib.Functions.Matrix; import MathLib.Functions.ExternalElementWiseFunction; public class ln extends ExternalElementWiseFunction { public ln() { name = "ln"; } /**Calculates the logarithm of a complex number @param arg = the value as an array of double @return the result as an array of double*/ public double[] evaluateValue(double[] arg) { double[] result = new double[2]; double temp = Math.pow(arg[REAL], 2) + Math.pow(arg[IMAG], 2); temp = Math.sqrt(temp); result[REAL] = Math.log(temp); result[IMAG] = Math.atan2(arg[IMAG], arg[REAL]); return result; } } /* @GROUP matrix @SYNTAX answer = ln(value) @DOC Returns the natural logarithm of value. @EXAMPLES <programlisting> ln(2) = 0.6931471805599 ln(10) = 2.30258509299 </programlisting> @SEE log */ |
|
From: Stefan M. <st_...@us...> - 2007-01-12 20:59:39
|
Update of /cvsroot/mathlib/mathlib/Source/MathLib/Functions/Matrix In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv12397/Source/MathLib/Functions/Matrix Added Files: round.java Log Message: --- NEW FILE: round.java --- package MathLib.Functions.Matrix; import MathLib.Functions.ExternalElementWiseFunction; public class round extends ExternalElementWiseFunction { public round() { name = "round"; } /**Standard functions - rounds the value to the nearest integer @return the result as an OperandToken*/ public double[] evaluateValue(double[] arg) { double[] result = new double[2]; result[REAL] = Math.rint(arg[REAL]); result[IMAG] = Math.rint(arg[IMAG]); return result; } } /* @GROUP general @SYNTAX answer = round(value) @DOC Rounds a value to the nearest integer. @EXAMPLES round(2.2) = 2 round(5.5) = 6 @SEE ceil, floor */ |
|
From: Stefan M. <st_...@us...> - 2007-01-10 18:51:15
|
Update of /cvsroot/mathlib/mathlib In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv20875 Modified Files: ChangeLog.txt Log Message: Index: ChangeLog.txt =================================================================== RCS file: /cvsroot/mathlib/mathlib/ChangeLog.txt,v retrieving revision 1.143 retrieving revision 1.144 diff -C2 -d -r1.143 -r1.144 *** ChangeLog.txt 9 Jan 2007 19:34:49 -0000 1.143 --- ChangeLog.txt 10 Jan 2007 18:51:08 -0000 1.144 *************** *** 33,36 **** --- 33,40 ---- stefan * + 2007/01/10 + stefan + ExternalElementWiseFunction.java for evaluation of functions which work + the same on all elements of an array (e.g. sin()) + 2007/01/09 stefan * NumberToken.java, zeros.java, ones.java added support for ND-arrays |
|
From: Stefan M. <st_...@us...> - 2007-01-10 18:49:54
|
Update of /cvsroot/mathlib/mathlib/Source/MathLib/Functions In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv20377/Source/MathLib/Functions Modified Files: ExternalFunction.java Added Files: ExternalElementWiseFunction.java Log Message: converted evaluation to ExternalElementWiseFunction --- NEW FILE: ExternalElementWiseFunction.java --- package MathLib.Functions; import MathLib.Tokens.NumberToken; import MathLib.Tokens.OperandToken; import MathLib.Tokens.Token; /**Base class for all external function classes which work element wise*/ abstract public class ExternalElementWiseFunction extends ExternalFunction { /** * standard function for evaluation of general external functions * @param operands * @retrun */ public OperandToken evaluate(Token[] operands) { // function works for one argument only if (getNArgIn(operands)!=1) throwMathLibException(name + " number of arguments < 1"); // works on numbers only if (!(operands[0] instanceof NumberToken)) throwMathLibException(name + " only works on numbers"); // get number token NumberToken numOp = (NumberToken)operands[0]; // get dimension of number token (2dimensional, 3dim, ....) int[] dim = numOp.getSize(); // ceate array of correct size with dimensions "dim" NumberToken num = new NumberToken(dim, null, null); // call element evaluation for all values inside the NumberToken for (int i=0; i< numOp.getNumberOfElements(); i++) { num.setValueComplex(i, evaluateValue( numOp.getValueComplex(i) )); } return num; } // end evaluate // all subclasses of this cluss MUST implement the method below abstract public double[] evaluateValue(double[] complex); } Index: ExternalFunction.java =================================================================== RCS file: /cvsroot/mathlib/mathlib/Source/MathLib/Functions/ExternalFunction.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ExternalFunction.java 14 Nov 2004 19:07:59 -0000 1.7 --- ExternalFunction.java 10 Jan 2007 18:49:47 -0000 1.8 *************** *** 4,7 **** --- 4,14 ---- abstract public class ExternalFunction extends Function { + + /**Index for real values within array*/ + protected static final int REAL = 0; + + /**Index for Imaginary values within array*/ + protected static final int IMAG = 1; + /**Number of paramaters take by the function*/ private int paramCount; |
Update of /cvsroot/mathlib/mathlib/Source/MathLib/Functions/Trigonometric In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv19983/Source/MathLib/Functions/Trigonometric Modified Files: GradToDeg.java RadToGrad.java DegToRad.java GradToRad.java DegToGrad.java RadToDeg.java Log Message: converted evaluation to ExternalElementWiseFunction Index: DegToRad.java =================================================================== RCS file: /cvsroot/mathlib/mathlib/Source/MathLib/Functions/Trigonometric/DegToRad.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DegToRad.java 26 Dec 2006 12:26:39 -0000 1.4 --- DegToRad.java 10 Jan 2007 18:48:59 -0000 1.5 *************** *** 1,37 **** package MathLib.Functions.Trigonometric; ! import MathLib.Tokens.NumberToken; ! import MathLib.Tokens.Token; ! import MathLib.Tokens.OperandToken; ! import MathLib.Functions.ExternalFunction; ! public class DegToRad extends ExternalFunction { ! /**converts value from degrees to radians ! if the parameter is a matrix then all elements get converted ! @param operads[0] = value to convert ! @return the converted value*/ ! public OperandToken evaluate(Token[] operands) ! { ! OperandToken result = new NumberToken(0); ! if(operands[0] != null && operands[0] instanceof NumberToken) ! { ! NumberToken value = ((NumberToken)operands[0]); ! double[][] values = value.getReValues(); ! int sizeY = value.getSizeY(); ! int sizeX = value.getSizeX(); ! double[][] results = new double[sizeY][sizeX]; ! ! for(int yy = 0; yy < sizeY; yy++) ! { ! for(int xx = 0; xx < sizeX; xx++) ! { ! results[yy][xx] = values[yy][xx] * Math.PI / 180; ! } ! } ! result = new NumberToken(results); ! } ! return result; ! } } --- 1,25 ---- package MathLib.Functions.Trigonometric; ! import MathLib.Functions.ExternalElementWiseFunction; ! public class DegToRad extends ExternalElementWiseFunction { ! ! public DegToRad() ! { ! name = "DegToRad"; ! } ! ! /**converts value from degrees to radians ! @param operads[0] = value to convert ! @return the converted value*/ ! public double[] evaluateValue(double[] arg) ! { ! double[] result = new double[2]; ! ! result[REAL] = arg[REAL] * Math.PI / 180; ! ! return result; ! } } Index: GradToDeg.java =================================================================== RCS file: /cvsroot/mathlib/mathlib/Source/MathLib/Functions/Trigonometric/GradToDeg.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** GradToDeg.java 26 Dec 2006 12:26:38 -0000 1.4 --- GradToDeg.java 10 Jan 2007 18:48:59 -0000 1.5 *************** *** 1,37 **** package MathLib.Functions.Trigonometric; ! import MathLib.Tokens.NumberToken; ! import MathLib.Tokens.Token; ! import MathLib.Tokens.OperandToken; ! import MathLib.Functions.ExternalFunction; ! public class GradToDeg extends ExternalFunction { ! /**converts value from gradiants to degrees ! if the parameter is a matrix then all elements get converted ! @param operads[0] = value to convert ! @return the converted value*/ ! public OperandToken evaluate(Token[] operands) ! { ! OperandToken result = new NumberToken(0); ! if(operands[0] != null && operands[0] instanceof NumberToken) ! { ! NumberToken value = ((NumberToken)operands[0]); ! double[][] values = value.getReValues(); ! int sizeY = value.getSizeY(); ! int sizeX = value.getSizeX(); ! double[][] results = new double[sizeY][sizeX]; ! ! for(int yy = 0; yy < sizeY; yy++) ! { ! for(int xx = 0; xx < sizeX; xx++) ! { ! results[yy][xx] = values[yy][xx] * 90 / 100; ! } ! } ! result = new NumberToken(results); ! } ! return result; ! } } --- 1,25 ---- package MathLib.Functions.Trigonometric; ! import MathLib.Functions.ExternalElementWiseFunction; ! public class GradToDeg extends ExternalElementWiseFunction { ! ! public GradToDeg() ! { ! name = "GradToDeg"; ! } ! ! /**converts value from gradiants to degrees ! @param operads[0] = value to convert ! @return the converted value*/ ! public double[] evaluateValue(double[] arg) ! { ! double[] result = new double[2]; ! ! result[REAL] = arg[REAL] * 90 / 100; ! ! return result; ! } } *************** *** 41,51 **** trigonometric @SYNTAX ! degrees=GRADTODEG(gradients) @DOC converts the angle from gradients to degrees. @NOTES @EXAMPLES ! GRADTODEG(200) = 180 ! GRADTODEG(100) = 100 @SEE gradtodeg, degtograd, radtograd, degtorad, radtodeg --- 29,39 ---- trigonometric @SYNTAX ! degrees = gradtodeg(gradients) @DOC converts the angle from gradients to degrees. @NOTES @EXAMPLES ! gradtodeg(200) = 180 ! gradtodeg(100) = 100 @SEE gradtodeg, degtograd, radtograd, degtorad, radtodeg Index: RadToGrad.java =================================================================== RCS file: /cvsroot/mathlib/mathlib/Source/MathLib/Functions/Trigonometric/RadToGrad.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RadToGrad.java 26 Dec 2006 12:26:38 -0000 1.4 --- RadToGrad.java 10 Jan 2007 18:48:59 -0000 1.5 *************** *** 1,37 **** package MathLib.Functions.Trigonometric; ! import MathLib.Tokens.NumberToken; ! import MathLib.Tokens.Token; ! import MathLib.Tokens.OperandToken; ! import MathLib.Functions.ExternalFunction; ! public class RadToGrad extends ExternalFunction { ! /**converts value from radians to gradients ! if the parameter is a matrix then all elements get converted ! @param operads[0] = value to convert ! @return the converted value*/ ! public OperandToken evaluate(Token[] operands) ! { ! OperandToken result = new NumberToken(0); ! if(operands[0] != null && operands[0] instanceof NumberToken) ! { ! NumberToken value = ((NumberToken)operands[0]); ! double[][] values = value.getReValues(); ! int sizeY = value.getSizeY(); ! int sizeX = value.getSizeX(); ! double[][] results = new double[sizeY][sizeX]; ! ! for(int yy = 0; yy < sizeY; yy++) ! { ! for(int xx = 0; xx < sizeX; xx++) ! { ! results[yy][xx] = values[yy][xx] * 200 / Math.PI; ! } ! } ! result = new NumberToken(results); ! } ! return result; ! } } --- 1,25 ---- package MathLib.Functions.Trigonometric; ! import MathLib.Functions.ExternalElementWiseFunction; ! public class RadToGrad extends ExternalElementWiseFunction { ! ! public RadToGrad() ! { ! name = "RadToGrad"; ! } ! ! /**converts value from radians to gradients ! @param operads[0] = value to convert ! @return the converted value*/ ! public double[] evaluateValue(double[] arg) ! { ! double[] result = new double[2]; ! ! result[REAL] = arg[REAL] * 200 / Math.PI; ! ! return result; ! } } *************** *** 41,51 **** trigonometric @SYNTAX ! gradients = RADTOGRAD(radians) @DOC converts the angle from radians to gradients. @NOTES @EXAMPLES ! RADTOGRAD(3.141592653589793) = 200 ! RADTOGRAD(1.5707963267948966) = 100 @SEE degtograd, radtograd, degtorad, radtodeg --- 29,39 ---- trigonometric @SYNTAX ! gradients = radtograd(radians) @DOC converts the angle from radians to gradients. @NOTES @EXAMPLES ! radtograd(3.141592653589793) = 200 ! radtograd(1.570796326794896) = 100 @SEE degtograd, radtograd, degtorad, radtodeg Index: DegToGrad.java =================================================================== RCS file: /cvsroot/mathlib/mathlib/Source/MathLib/Functions/Trigonometric/DegToGrad.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DegToGrad.java 26 Dec 2006 12:26:40 -0000 1.4 --- DegToGrad.java 10 Jan 2007 18:48:59 -0000 1.5 *************** *** 1,35 **** package MathLib.Functions.Trigonometric; ! import MathLib.Tokens.NumberToken; ! import MathLib.Tokens.Token; ! import MathLib.Tokens.OperandToken; ! import MathLib.Functions.ExternalFunction; ! public class DegToGrad extends ExternalFunction { /**converts value from degrees to gradients if the parameter is a matrix then all elements get converted @param operads[0] = value to convert @return the converted value*/ ! public OperandToken evaluate(Token[] operands) ! { ! OperandToken result = new NumberToken(0); ! if(operands[0] != null && operands[0] instanceof NumberToken) ! { ! NumberToken value = ((NumberToken)operands[0]); ! double[][] values = value.getReValues(); ! int sizeY = value.getSizeY(); ! int sizeX = value.getSizeX(); ! double[][] results = new double[sizeY][sizeX]; ! ! for(int yy = 0; yy < sizeY; yy++) ! { ! for(int xx = 0; xx < sizeX; xx++) ! { ! results[yy][xx] = values[yy][xx] * 100 / 90; ! } ! } ! result = new NumberToken(results); ! } return result; } --- 1,24 ---- package MathLib.Functions.Trigonometric; ! import MathLib.Functions.ExternalElementWiseFunction; ! public class DegToGrad extends ExternalElementWiseFunction { + + public DegToGrad() + { + name = "DegToGrad"; + } + /**converts value from degrees to gradients if the parameter is a matrix then all elements get converted @param operads[0] = value to convert @return the converted value*/ ! public double[] evaluateValue(double[] arg) ! { ! double[] result = new double[2]; ! ! result[REAL] = arg[REAL] * 100 / 90; ! return result; } *************** *** 41,51 **** trigonometric @SYNTAX ! gradients = DEGTOGRAD(degrees) @DOC converts the angle from degrees to gradients. @NOTES @EXAMPLES ! DEGTOGRAD(180) = 200 ! DEGTOGRAD(90) = 100 @SEE gradtodeg, degtograd, radtograd, degtorad, radtodeg --- 30,40 ---- trigonometric @SYNTAX ! gradients = degtograd(degrees) @DOC converts the angle from degrees to gradients. @NOTES @EXAMPLES ! degtograd(180) = 200 ! degtograd(90) = 100 @SEE gradtodeg, degtograd, radtograd, degtorad, radtodeg Index: RadToDeg.java =================================================================== RCS file: /cvsroot/mathlib/mathlib/Source/MathLib/Functions/Trigonometric/RadToDeg.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RadToDeg.java 26 Dec 2006 12:26:41 -0000 1.4 --- RadToDeg.java 10 Jan 2007 18:48:59 -0000 1.5 *************** *** 1,37 **** package MathLib.Functions.Trigonometric; ! import MathLib.Tokens.NumberToken; ! import MathLib.Tokens.Token; ! import MathLib.Tokens.OperandToken; ! import MathLib.Functions.ExternalFunction; ! public class RadToDeg extends ExternalFunction { ! /**converts value from radians to degrees ! if the parameter is a matrix then all elements get converted ! @param operads[0] = value to convert ! @return the converted value*/ ! public OperandToken evaluate(Token[] operands) ! { ! OperandToken result = new NumberToken(0); ! if(operands[0] != null && operands[0] instanceof NumberToken) ! { ! NumberToken value = ((NumberToken)operands[0]); ! double[][] values = value.getReValues(); ! int sizeY = value.getSizeY(); ! int sizeX = value.getSizeX(); ! double[][] results = new double[sizeY][sizeX]; ! ! for(int yy = 0; yy < sizeY; yy++) ! { ! for(int xx = 0; xx < sizeX; xx++) ! { ! results[yy][xx] = values[yy][xx] * 180 / Math.PI; ! } ! } ! result = new NumberToken(results); ! } ! return result; ! } } --- 1,26 ---- package MathLib.Functions.Trigonometric; ! import MathLib.Functions.ExternalElementWiseFunction; ! public class RadToDeg extends ExternalElementWiseFunction { ! ! public RadToDeg() ! { ! name = "RadToDeg"; ! } ! ! /**converts value from radians to degrees ! @param operands[0] = value to convert ! @return the converted value*/ ! public double[] evaluateValue(double[] arg) ! { ! double[] result = new double[2]; ! ! result[REAL] = arg[REAL] * 180 / Math.PI; ! ! return result; ! } ! } *************** *** 40,50 **** trigonometric @SYNTAX ! degrees = RADTODEG(radians) @DOC converts the angle from radians to degrees. @NOTES @EXAMPLES ! RADTODEG(3.141592653589793) = 180 ! RADTODEG(1.5707963267948966) = 90 @SEE gradtodeg, degtograd, radtograd, degtorad, radtodeg --- 29,39 ---- trigonometric @SYNTAX ! degrees = radtodeg(radians) @DOC converts the angle from radians to degrees. @NOTES @EXAMPLES ! radtodeg(3.141592653589793) = 180 ! radtodeg(1.5707963267948966) = 90 @SEE gradtodeg, degtograd, radtograd, degtorad, radtodeg Index: GradToRad.java =================================================================== RCS file: /cvsroot/mathlib/mathlib/Source/MathLib/Functions/Trigonometric/GradToRad.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** GradToRad.java 26 Dec 2006 12:26:40 -0000 1.4 --- GradToRad.java 10 Jan 2007 18:48:59 -0000 1.5 *************** *** 1,37 **** package MathLib.Functions.Trigonometric; ! import MathLib.Tokens.NumberToken; ! import MathLib.Tokens.Token; ! import MathLib.Tokens.OperandToken; ! import MathLib.Functions.ExternalFunction; ! public class GradToRad extends ExternalFunction { ! /**converts value from gradients to radians ! if the parameter is a matrix then all elements get converted ! @param operads[0] = value to convert ! @return the converted value*/ ! public OperandToken evaluate(Token[] operands) ! { ! OperandToken result = new NumberToken(0); ! if(operands[0] != null && operands[0] instanceof NumberToken) ! { ! NumberToken value = ((NumberToken)operands[0]); ! double[][] values = value.getReValues(); ! int sizeY = value.getSizeY(); ! int sizeX = value.getSizeX(); ! double[][] results = new double[sizeY][sizeX]; ! ! for(int yy = 0; yy < sizeY; yy++) ! { ! for(int xx = 0; xx < sizeX; xx++) ! { ! results[yy][xx] = values[yy][xx] * Math.PI / 200; ! } ! } ! result = new NumberToken(results); ! } ! return result; ! } } --- 1,25 ---- package MathLib.Functions.Trigonometric; ! import MathLib.Functions.ExternalElementWiseFunction; ! public class GradToRad extends ExternalElementWiseFunction { ! ! public GradToRad() ! { ! name = "GradToRad"; ! } ! ! /**converts value from gradients to radians ! @param operands[0] = value to convert ! @return the converted value*/ ! public double[] evaluateValue(double[] arg) ! { ! double[] result = new double[2]; ! ! result[REAL] = arg[REAL] * Math.PI / 200; ! ! return result; ! } } *************** *** 41,51 **** trigonometric @SYNTAX ! radians = GRADTORAD(gradients) @DOC converts the angle from gradients to radians. @NOTES @EXAMPLES ! GRADTORAD(200) = 3.141592653589793 ! GRADTORAD(100) = 1.5707963267948966 @SEE gradtodeg, degtograd, radtograd, degtorad, radtodeg --- 29,39 ---- trigonometric @SYNTAX ! radians = gradtorad(gradients) @DOC converts the angle from gradients to radians. @NOTES @EXAMPLES ! gradtorad(200) = 3.141592653589793 ! gradtorad(100) = 1.5707963267948966 @SEE gradtodeg, degtograd, radtograd, degtorad, radtodeg |
|
From: Stefan M. <st_...@us...> - 2007-01-10 18:43:20
|
Update of /cvsroot/mathlib/mathlib/Source/MathLib/Tools/TestSuite/Functions/Trigonometric In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv17735/Source/MathLib/Tools/TestSuite/Functions/Trigonometric Modified Files: testDegToGrad.java Log Message: Index: testDegToGrad.java =================================================================== RCS file: /cvsroot/mathlib/mathlib/Source/MathLib/Tools/TestSuite/Functions/Trigonometric/testDegToGrad.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** testDegToGrad.java 31 Oct 2004 09:03:45 -0000 1.1 --- testDegToGrad.java 10 Jan 2007 18:43:10 -0000 1.2 *************** *** 21,34 **** } ! public void testAbs01() { ! ml.executeExpression("a=abs(1);"); ! assertTrue(1 == ml.getScalarValueRe("a")); ! } ! public void testAbs02() { ! ml.executeExpression("a=abs(-3);"); ! assertTrue(3 == ml.getScalarValueRe("a")); } } --- 21,53 ---- } ! public void testDegToGrad01() { ! ml.executeExpression("a=degtograd(90);"); ! assertTrue(Math.abs(100 - ml.getScalarValueRe("a")) < 0.001); } + public void testDegToRad01() { + ml.executeExpression("a=degtorad(180);"); + assertTrue(Math.abs(Math.PI - ml.getScalarValueRe("a")) < 0.001); + } + public void testGradToDeg01() { + ml.executeExpression("a=gradtodeg(100);"); + assertTrue(Math.abs(90 - ml.getScalarValueRe("a")) < 0.001); + } + + public void testGradToRad01() { + ml.executeExpression("a=gradtorad(200);"); + assertTrue(Math.abs(Math.PI - ml.getScalarValueRe("a")) < 0.001); + } + + public void testRadToDeg01() { + ml.executeExpression("a=radtodeg(3.14159);"); + assertTrue(Math.abs(180 - ml.getScalarValueRe("a")) < 0.01); + } + + public void testRadToGrad01() { + ml.executeExpression("a=radtograd(3.14159);"); + assertTrue(Math.abs(200 - ml.getScalarValueRe("a")) < 0.01); + } } |
|
From: Stefan M. <st_...@us...> - 2007-01-09 19:34:52
|
Update of /cvsroot/mathlib/mathlib In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv13465 Modified Files: ChangeLog.txt Log Message: Index: ChangeLog.txt =================================================================== RCS file: /cvsroot/mathlib/mathlib/ChangeLog.txt,v retrieving revision 1.142 retrieving revision 1.143 diff -C2 -d -r1.142 -r1.143 *** ChangeLog.txt 8 Jan 2007 18:50:27 -0000 1.142 --- ChangeLog.txt 9 Jan 2007 19:34:49 -0000 1.143 *************** *** 25,30 **** Updated functions: ! col.m, diag.java, ndims.java, imag.java, rand.java, real.java, row.m, ! size.java, tic.java --- 25,30 ---- Updated functions: ! col.m, diag.java, ndims.java, imag.java, ones.java, rand.java, real.java, ! row.m, size.java, tic.java, whos.java, zeros.java *************** *** 33,36 **** --- 33,39 ---- stefan * + 2007/01/09 + stefan * NumberToken.java, zeros.java, ones.java added support for ND-arrays + 2007/01/08 stefan * NumberToken.java, CellArrayToken.java, DataToken.java, ndims.java, |
|
From: Stefan M. <st_...@us...> - 2007-01-09 19:08:12
|
Update of /cvsroot/mathlib/mathlib/Source/MathLib/Functions/General In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv1556/Source/MathLib/Functions/General Modified Files: rand.java Log Message: added support for ND-arrays Index: rand.java =================================================================== RCS file: /cvsroot/mathlib/mathlib/Source/MathLib/Functions/General/rand.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** rand.java 8 Jan 2007 18:59:05 -0000 1.12 --- rand.java 9 Jan 2007 19:08:06 -0000 1.13 *************** *** 30,34 **** // get requested dimension ! dim[i] = (int)((NumberToken)operands[i]).getValueRe(0); } --- 30,38 ---- // get requested dimension ! dim[i] = (int)((NumberToken)operands[i]).getValueRe(); ! ! if (dim[i]<0) ! throwMathLibException("rand: dimension <0"); ! } |
|
From: Stefan M. <st_...@us...> - 2007-01-09 19:08:11
|
Update of /cvsroot/mathlib/mathlib/Source/MathLib/Functions/Matrix In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv1556/Source/MathLib/Functions/Matrix Modified Files: zeros.java ones.java Log Message: added support for ND-arrays Index: ones.java =================================================================== RCS file: /cvsroot/mathlib/mathlib/Source/MathLib/Functions/Matrix/ones.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ones.java 26 Dec 2006 12:25:07 -0000 1.5 --- ones.java 9 Jan 2007 19:08:06 -0000 1.6 *************** *** 15,53 **** { ! int columns; ! int rows; ! ! // at least one operands (e.g. ones(n) ) ! if (operands.length < 1) return null; ! if (operands[0] == null) return null; ! if (!(operands[0] instanceof NumberToken)) return null; ! ! rows = (int)(((NumberToken)operands[0]).getReValues())[0][0]; ! columns = rows; ! ! // two operands (e.g. ones(n,m) ) ! if (operands.length == 2) ! { ! if (operands[1] == null) return null; ! if (!(operands[1] instanceof NumberToken)) return null; ! columns = (int)((NumberToken)operands[1]).getReValues()[0][0]; ! } ! ! // only positive indices ! if ((rows <= 0) || (columns <= 0)) return null; ! // create matrix ! double[][] values = new double[rows][columns]; ! for (int yi=0; yi<=(rows-1) ; yi++) ! { ! for (int xi=0; xi<=(columns-1) ; xi++) ! { ! values[yi][xi] = 1.0; ! } ! } ! return new NumberToken(values); ! } // end eval } --- 15,62 ---- { ! // at least one operand ! if (getNArgIn(operands) < 1) ! throwMathLibException("ones: number of arguments <1 "); ! ! // number of arguments ! int n = getNArgIn(operands); ! ! // set up dimension array ! int[] dim = new int[n]; ! ! // only NumberTokens accepted ! // each token is one dimension ! for (int i=0; i<n; i++) ! { ! if (!(operands[i] instanceof NumberToken)) ! throwMathLibException("ones: arguments must be numbers"); ! ! // get requested dimension ! dim[i] = (int)((NumberToken)operands[i]).getValueRe(); ! if (dim[i]<0) ! throwMathLibException("ones: dimension <0"); ! } ! ! // special case for rand(k) -> rand(k,k) ! if (dim.length==1) ! { ! int d = dim[0]; ! dim = new int[]{d,d}; ! } ! ! // ceate array of correct size with dimensions "dim" ! NumberToken num = new NumberToken(dim, null, null); ! ! // create "1" value for all values of num ! for (int i=0; i< num.getNumberOfElements(); i++) ! { ! num.setValue(i, 1, 0); ! } ! ! return num; ! } // end eval } *************** *** 57,60 **** --- 66,70 ---- @SYNTAX ones(sizex, sizey) + ones(n,m,k,...) @DOC Returns a matrix of ones. Index: zeros.java =================================================================== RCS file: /cvsroot/mathlib/mathlib/Source/MathLib/Functions/Matrix/zeros.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** zeros.java 30 Dec 2006 18:07:10 -0000 1.8 --- zeros.java 9 Jan 2007 19:08:06 -0000 1.9 *************** *** 15,52 **** { - int columns; - int rows; - // at least one operands (e.g. zeros(n) ) if (getNArgIn(operands)<1) throwMathLibException("zeros: number of arguments < 1"); ! if (!(operands[0] instanceof NumberToken)) ! throwMathLibException("zeros: works only on numbers"); ! ! rows = (int)(((NumberToken)operands[0]).getReValues())[0][0]; ! columns = rows; ! ! // two operands (e.g. zeros(n,m) ) ! if (getNArgIn(operands)==2) ! { ! if (!(operands[1] instanceof NumberToken)) return null; ! ! columns = (int)((NumberToken)operands[1]).getReValues()[0][0]; ! } ! ! // only positive indices ! if ((rows <= 0) || (columns <= 0)) return null; ! ! // create matrix ! double[][] values = new double[rows][columns]; ! for (int yi=0; yi<=(rows-1) ; yi++) ! { ! for (int xi=0; xi<=(columns-1) ; xi++) ! { ! values[yi][xi] = 0.0; ! } ! } ! return new NumberToken(values); } // end eval --- 15,60 ---- { // at least one operands (e.g. zeros(n) ) if (getNArgIn(operands)<1) throwMathLibException("zeros: number of arguments < 1"); ! // number of arguments ! int n = getNArgIn(operands); ! ! // set up dimension array ! int[] dim = new int[n]; ! ! // only NumberTokens accepted ! // each token is one dimension ! for (int i=0; i<n; i++) ! { ! if (!(operands[i] instanceof NumberToken)) ! throwMathLibException("zeros: arguments must be numbers"); ! ! // get requested dimension ! dim[i] = (int)((NumberToken)operands[i]).getValueRe(); ! ! if (dim[i]<0) ! throwMathLibException("zeros: dimension <0"); ! } ! ! // special case for rand(k) -> rand(k,k) ! if (dim.length==1) ! { ! int d = dim[0]; ! dim = new int[]{d,d}; ! } ! ! // ceate array of correct size with dimensions "dim" ! NumberToken num = new NumberToken(dim, null, null); ! ! // create random value for all values of num ! for (int i=0; i< num.getNumberOfElements(); i++) ! { ! num.setValue(i, 0, 0); ! } ! ! return num; ! } // end eval *************** *** 57,61 **** matrix @SYNTAX ! answer = zeros(sizey, [sizex]) @DOC Returns a matrix filled with zeros. --- 65,70 ---- matrix @SYNTAX ! zeros(sizey, [sizex]) ! zeros(n,m,k,l...) @DOC Returns a matrix filled with zeros. *************** *** 63,68 **** @EXAMPLES <programlisting> ! ZEROS(2,2) = [0,0;0,0] ! ZEROS(2,3) = [0,0,0;0,0,0] </programlisting> @SEE --- 72,77 ---- @EXAMPLES <programlisting> ! zeros(2,2) = [0,0;0,0] ! zeros(2,3) = [0,0,0;0,0,0] </programlisting> @SEE |
|
From: Stefan M. <st_...@us...> - 2007-01-09 18:58:57
|
Update of /cvsroot/mathlib/mathlib/Source/MathLib/Tokens In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv29655/Source/MathLib/Tokens Modified Files: DataToken.java NumberToken.java Log Message: better support for ND-NumberToken Index: NumberToken.java =================================================================== RCS file: /cvsroot/mathlib/mathlib/Source/MathLib/Tokens/NumberToken.java,v retrieving revision 1.98 retrieving revision 1.99 diff -C2 -d -r1.98 -r1.99 *** NumberToken.java 8 Jan 2007 19:09:20 -0000 1.98 --- NumberToken.java 9 Jan 2007 18:58:51 -0000 1.99 *************** *** 529,535 **** { int n = yx2n(y,x); ! return values[n]; } /** --- 529,544 ---- { int n = yx2n(y,x); ! return getValueComplex(n); } + /** + * + * @param n + * @return + */ + public double[] getValueComplex(int n) + { + return values[n]; + } /** *************** *** 784,798 **** NumberToken nArg = ((NumberToken)arg); - int argSizeX = nArg.getSizeX(); - int argSizeY = nArg.getSizeY(); - - NumberToken result = new NumberToken(); // Check dimensions of matrices ! if((sizeX == argSizeX) && (sizeY == argSizeY)) { ! // Add (n*m) + (n*m) ErrorLogger.debugLine("NumberToken: add (n*m) + (n*m)"); ! result.setSize(sizeY, sizeX); for(int n = 0; n < noElem; n++) --- 793,804 ---- NumberToken nArg = ((NumberToken)arg); // Check dimensions of matrices ! if(checkEqualDimensions(sizeA, nArg.sizeA)) { ! // Add (n*m) + (n*m) or ! // same dimensions (n,m,r)==(n,m,r) ErrorLogger.debugLine("NumberToken: add (n*m) + (n*m)"); ! NumberToken result = new NumberToken(sizeA, null, null); for(int n = 0; n < noElem; n++) *************** *** 806,814 **** return result; } ! else if((sizeX==1) && (sizeY==1)) { // 1 + [3,4,5] ErrorLogger.debugLine("NumberToken: add (1*1) + (n*m)"); ! result.setSize(argSizeY, argSizeX); for(int n = 0; n < nArg.getNumberOfElements(); n++) --- 812,820 ---- return result; } ! else if(isScalar()) { // 1 + [3,4,5] ErrorLogger.debugLine("NumberToken: add (1*1) + (n*m)"); ! NumberToken result = new NumberToken(nArg.sizeA, null, null); for(int n = 0; n < nArg.getNumberOfElements(); n++) *************** *** 822,830 **** return result; } ! else if((argSizeX==1) && (argSizeY==1)) { // [3,4,5] +1 ErrorLogger.debugLine("NumberToken: add (n,m) + (1,1)"); ! result.setSize(sizeY, sizeX); for(int n = 0; n < noElem; n++) --- 828,836 ---- return result; } ! else if(nArg.isScalar()) { // [3,4,5] +1 ErrorLogger.debugLine("NumberToken: add (n,m) + (1,1)"); ! NumberToken result = new NumberToken(sizeA, null, null); for(int n = 0; n < noElem; n++) *************** *** 855,869 **** NumberToken nArg = ((NumberToken)arg); - int argSizeX = nArg.getSizeX(); - int argSizeY = nArg.getSizeY(); - - NumberToken result = new NumberToken(); //Check dimensions of matrices ! if((sizeX == argSizeX) && (sizeY == argSizeY)) { ! // Sub (n*m) - (n*m) ErrorLogger.debugLine("NumberToken: sub (n*m) - (n*m)"); ! result.setSize(argSizeY, argSizeX); for(int n = 0; n < noElem; n++) --- 861,872 ---- NumberToken nArg = ((NumberToken)arg); //Check dimensions of matrices ! if( checkEqualDimensions(this.sizeA, nArg.sizeA) ) { ! // Sub (n*m) - (n*m) or ! // multidimensional (n*m*r) - (n*m*r) ErrorLogger.debugLine("NumberToken: sub (n*m) - (n*m)"); ! NumberToken result = new NumberToken(sizeA, null, null); for(int n = 0; n < noElem; n++) *************** *** 876,884 **** return result; } ! else if((sizeX == 1) && (sizeY == 1)) { // 1 - [2,3,4] ErrorLogger.debugLine("NumberToken: sub (1*1) - (n*m)"); ! result.setSize(argSizeY, argSizeX); for(int n = 0; n < nArg.getNumberOfElements(); n++) --- 879,887 ---- return result; } ! else if( isScalar() ) { // 1 - [2,3,4] ErrorLogger.debugLine("NumberToken: sub (1*1) - (n*m)"); ! NumberToken result = new NumberToken(nArg.sizeA, null, null); for(int n = 0; n < nArg.getNumberOfElements(); n++) *************** *** 891,899 **** return result; } ! else if((argSizeX == 1) && (argSizeY == 1)) { // [3,4,5] - 5 ErrorLogger.debugLine("NumberToken: sub (n*m) - (1*1)"); ! result.setSize(sizeY, sizeX); for(int n = 0; n < noElem; n++) --- 894,902 ---- return result; } ! else if( nArg.isScalar() ) { // [3,4,5] - 5 ErrorLogger.debugLine("NumberToken: sub (n*m) - (1*1)"); ! NumberToken result = new NumberToken(sizeA, null, null); for(int n = 0; n < noElem; n++) *************** *** 909,913 **** { // Matrices have unequal size: (n*m) != (o*p) ! ErrorLogger.debugLine("NumberToken: sub matrices of unequal size"); return null; } --- 912,916 ---- { // Matrices have unequal size: (n*m) != (o*p) ! Errors.throwMathLibException("NumberToken: sub matrices of unequal size"); return null; } *************** *** 924,927 **** --- 927,931 ---- // get operand data and size + NumberToken nArg = (NumberToken)arg; double[][] argValuesRe = ((NumberToken)arg).getValuesRe(); double[][] argValuesIm = ((NumberToken)arg).getValuesIm(); *************** *** 929,933 **** int argSizeY = ((NumberToken)arg).getSizeY(); ! if ((sizeX==1) && (sizeY==1)) { // e.g. 4.^[1,2,3;4,5,6] --- 933,937 ---- int argSizeY = ((NumberToken)arg).getSizeY(); ! if ( this.isScalar() ) { // e.g. 4.^[1,2,3;4,5,6] *************** *** 940,943 **** --- 944,948 ---- for (int x=0; x<argSizeX; x++) { + double re = Math.log(getValueAbs(0, 0)); double im = getValueArg(0, 0); *************** *** 955,959 **** return new NumberToken(results); } ! else if ((argSizeX==1) && (argSizeY==1)) { // e.g. [1,2,3;4,5,6].^2 --- 960,964 ---- return new NumberToken(results); } ! else if ( nArg.isScalar() ) { // e.g. [1,2,3;4,5,6].^2 *************** *** 981,985 **** return new NumberToken(results); } ! else if ((sizeX==argSizeX) && (sizeY==argSizeY)) { // e.g. [1,2,3;4,5,6].^[3,4,5;6,7,8] --- 986,990 ---- return new NumberToken(results); } ! else if ( checkEqualDimensions(this.sizeA, nArg.sizeA) ) { // e.g. [1,2,3;4,5,6].^[3,4,5;6,7,8] *************** *** 1025,1028 **** --- 1030,1034 ---- // get operand data and size + NumberToken nArg = (NumberToken)arg; double[][] argValuesRe = ((NumberToken)arg).getValuesRe(); double[][] argValuesIm = ((NumberToken)arg).getValuesIm(); *************** *** 1030,1034 **** int argSizeY = ((NumberToken)arg).getSizeY(); ! if ((sizeX==1) && (sizeY==1) && (argSizeX==1) && (argSizeY==1)) { // e.g. 4.^5 --- 1036,1040 ---- int argSizeY = ((NumberToken)arg).getSizeY(); ! if (this.isScalar() && (argSizeX==1) && (argSizeY==1)) { // e.g. 4.^5 *************** *** 1077,1080 **** --- 1083,1087 ---- Errors.throwMathLibException("NumberToken: multiply: no number"); + NumberToken nArg = (NumberToken)arg; NumberToken argValues = ((NumberToken)arg); int argSizeX = ((NumberToken)arg).getSizeX(); *************** *** 1082,1086 **** /* Check if arg is a scalar */ ! if((argSizeX == 1) && (argSizeY == 1)) { // Multiply (n*m) = (n*m) * scalar --- 1089,1093 ---- /* Check if arg is a scalar */ ! if( nArg.isScalar() ) { // Multiply (n*m) = (n*m) * scalar *************** *** 1104,1108 **** return new NumberToken(results); } ! else if((sizeX == 1) && (sizeY == 1)) { /* the NumberToken of this class is a scalar */ --- 1111,1115 ---- return new NumberToken(results); } ! else if( this.isScalar() ) { /* the NumberToken of this class is a scalar */ *************** *** 1114,1118 **** return arg.multiply(this); } ! else if (sizeX == argSizeY) { /* Multiply (n*o) = (n*m) * (m*o) */ --- 1121,1125 ---- return arg.multiply(this); } ! else if (sizeX == argSizeY && (sizeA.length==2)) { /* Multiply (n*o) = (n*m) * (m*o) */ *************** *** 1142,1146 **** { /* dimensions do not match */ ! ErrorLogger.debugLine("NumberToken: multiply: dimensions don't match"); return null; } --- 1149,1153 ---- { /* dimensions do not match */ ! Errors.throwMathLibException("NumberToken: multiply: dimensions don't match"); return null; } *************** *** 1172,1176 **** // Check if arg is a scalar ! if((argSizeX == 1) && (argSizeY == 1)) { // Divide (n*m) = (n*m) / scalar --- 1179,1183 ---- // Check if arg is a scalar ! if( nArg.isScalar() ) { // Divide (n*m) = (n*m) / scalar *************** *** 1191,1195 **** return result; } ! else if((sizeX == 1) && (sizeY == 1)) { // the NumberToken of this class is a scalar --- 1198,1202 ---- return result; } ! else if( this.isScalar() ) { // the NumberToken of this class is a scalar *************** *** 1209,1213 **** else { ! ErrorLogger.debugLine("NumberToken: divide: dimensions don't match"); return null; } --- 1216,1220 ---- else { ! Errors.throwMathLibException("NumberToken: divide: dimensions don't match"); return null; } *************** *** 1287,1344 **** NumberToken nArg = ((NumberToken)arg); - double[][] argValues = nArg.getValuesRe(); - double[][] argValuesImg = nArg.getValuesIm(); - int argSizeX = nArg.getSizeX(); - int argSizeY = nArg.getSizeY(); ! if ((sizeX == argSizeX) && (sizeY == argSizeY)) { // scalar multiplication (n*m) = (n*m) .* (n*m) ErrorLogger.debugLine("NumberToken: multiply (n*m) .* (n*m)"); ! double[][][] results = new double[sizeY][sizeX][2]; ! ! for (int yy=0; yy<sizeY; yy++) { ! for (int xx=0; xx<sizeX; xx++) ! { ! int n = yx2n(yy,xx); ! double[] argVal = nArg.getValueComplex(yy, xx); ! results[yy][xx] = multiply(values[n], argVal); ! } } ! return new NumberToken(results); } ! else if ((argSizeX==1) && (argSizeY==1)) { // scalar multiplication (n*m) .* (1*1) ErrorLogger.debugLine("NumberToken: multiply (n*m) .* (1*1)"); ! double[][][] results = new double[sizeY][sizeX][2]; ! ! for (int yy=0; yy<sizeY; yy++) { ! for (int xx=0; xx<sizeX; xx++) ! { ! int n = yx2n(yy,xx); ! double[] argVal = nArg.getValueComplex(0, 0); ! results[yy][xx] = multiply(values[n], argVal); ! } } ! return new NumberToken(results); } ! else if ((sizeX == 1) && (sizeY == 1)) { // scalar multiplication (1*1) .* (n*m) ErrorLogger.debugLine("NumberToken: multiply (1*1) .* (n*m)"); ! double[][][] results = new double[argSizeY][argSizeX][2]; ! for (int y=0; y<argSizeY; y++) { ! for (int x=0; x<argSizeX; x++) ! { ! double[] val = getValueComplex(0, 0); ! results[y][x] = multiply(val, nArg.getValueComplex(y,x)); ! } } ! return new NumberToken(results); } else --- 1294,1336 ---- NumberToken nArg = ((NumberToken)arg); ! if ( checkEqualDimensions(this.sizeA, nArg.sizeA) ) { // scalar multiplication (n*m) = (n*m) .* (n*m) ErrorLogger.debugLine("NumberToken: multiply (n*m) .* (n*m)"); ! NumberToken result = new NumberToken(sizeA, null, null); ! ! for (int n=0; n<noElem; n++) { ! double[] argVal = nArg.getValueComplex(n); ! result.setValueComplex(n, multiply(values[n], argVal) ); } ! return result; } ! else if ( nArg.isScalar() ) { // scalar multiplication (n*m) .* (1*1) ErrorLogger.debugLine("NumberToken: multiply (n*m) .* (1*1)"); ! NumberToken result = new NumberToken(sizeA, null, null); ! ! for (int n=0; n<noElem; n++) { ! double[] argVal = nArg.getValueComplex(0); ! result.setValueComplex(n, multiply(values[n], argVal) ); } ! return result; } ! else if ( this.isScalar() ) { // scalar multiplication (1*1) .* (n*m) ErrorLogger.debugLine("NumberToken: multiply (1*1) .* (n*m)"); ! NumberToken result = new NumberToken(nArg.sizeA, null, null); ! for (int n=0; n<nArg.noElem; n++) { ! double[] argVal = nArg.getValueComplex(n); ! result.setValueComplex(n, multiply(values[0], argVal) ); } ! return result; } else *************** *** 1385,1389 **** return new NumberToken(results); } ! else if ((argSizeX==1) && (argSizeY==1)) { // divide multiplication (n*m) ./ (1,1) --- 1377,1381 ---- return new NumberToken(results); } ! else if ( nArg.isScalar() ) { // divide multiplication (n*m) ./ (1,1) *************** *** 1402,1406 **** return new NumberToken(results); } ! else if ((sizeX==1) && (sizeY==1)) { // divide multiplication (n*m) ./ (1,1) --- 1394,1398 ---- return new NumberToken(results); } ! else if ( this.isScalar() ) { // divide multiplication (n*m) ./ (1,1) *************** *** 1437,1441 **** NumberToken nArg = ((NumberToken)arg); ! NumberToken num = new NumberToken(nArg.getReValues()); //return num.divide(new NumberToken(values)); --- 1429,1433 ---- NumberToken nArg = ((NumberToken)arg); ! NumberToken num = new NumberToken(nArg.getReValues()); //return num.divide(new NumberToken(values)); *************** *** 1453,1457 **** NumberToken nArg = ((NumberToken)arg); ! NumberToken num = new NumberToken(nArg.getReValues()); //return num.scalarDivide(new NumberToken(values)); --- 1445,1449 ---- NumberToken nArg = ((NumberToken)arg); ! NumberToken num = new NumberToken(nArg.getReValues()); //return num.scalarDivide(new NumberToken(values)); *************** *** 2149,2160 **** { // real numbers only ! for (int yy=0; yy<sizeY; yy++) ! { ! for (int xx=0; xx<sizeX; xx++) ! { ! int n = yx2n(yy,xx); ! results[yy][xx][REAL] = java.lang.Math.abs(values[n][REAL]); ! } ! } } else --- 2141,2151 ---- { // real numbers only ! NumberToken result = new NumberToken(sizeA, null, null); ! ! for(int n = 0; n < noElem; n++) ! { ! result.setValue(n, Math.abs(getValueRe(n)), 0 ); ! } ! return result; } else *************** *** 2231,2237 **** for(int n = 0; n < noElem; n++) { ! result.setValue(n, ! -getValueRe(n) , ! -getValueIm(n) ); } return result; --- 2222,2226 ---- for(int n = 0; n < noElem; n++) { ! result.setValue(n, -getValueRe(n), -getValueIm(n) ); } return result; *************** *** 2256,2260 **** double arg2 = ((NumberToken)arg).getValueRe(0); ! double result = java.lang.Math.max(values[0][REAL], arg2); return new NumberToken(result); } --- 2245,2249 ---- double arg2 = ((NumberToken)arg).getValueRe(0); ! double result = Math.max(values[0][REAL], arg2); return new NumberToken(result); } *************** *** 2268,2272 **** for(int n = 0; n < noElem; n++) { ! double amount = java.lang.Math.rint(getValueRe(n)); result.setValue(n, factorial(amount) , --- 2257,2261 ---- for(int n = 0; n < noElem; n++) { ! double amount = Math.rint(getValueRe(n)); result.setValue(n, factorial(amount) , *************** *** 2313,2323 **** public boolean isNull() { ! boolean result = true; ! for (int n=0; n<noElem && result; n++) { if( (getValueRe(n)!=0) || (getValueIm(n)!=0) ) ! result = false; } ! return result; } --- 2302,2312 ---- public boolean isNull() { ! ! for (int n=0; n<noElem; n++) { if( (getValueRe(n)!=0) || (getValueIm(n)!=0) ) ! return false; } ! return true; } *************** *** 2333,2340 **** public boolean isScalar() { ! if ((sizeX==1) && (sizeY==1)) ! return true; ! else ! return false; } --- 2322,2335 ---- public boolean isScalar() { ! ! for (int i=0; i<sizeA.length; i++) ! { ! // in case one entry in the size-array is unequal 1 it ! // is not a scalar any more ! if (sizeA[i]!=1) ! return false; ! } ! ! return true; } Index: DataToken.java =================================================================== RCS file: /cvsroot/mathlib/mathlib/Source/MathLib/Tokens/DataToken.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** DataToken.java 8 Jan 2007 16:20:44 -0000 1.16 --- DataToken.java 9 Jan 2007 18:58:51 -0000 1.17 *************** *** 64,67 **** --- 64,85 ---- } + + public boolean checkEqualDimensions(int[] size1, int[] size2) + { + + if ((size1==null) || (size2==null)) + return false; + + if (size1.length != size2.length) + return false; + + for (int i=0; i<size1.length; i++) + { + if (size1[i]!=size2[i]) + return false; + } + + return true; + } //abstract |