楼主: ReneeBK
3129 11

[读者文库]Java Number Cruncher [推广有奖]

  • 1关注
  • 62粉丝

VIP

已卖:4897份资源

学术权威

14%

还不是VIP/贵宾

-

TA的文库  其他...

R资源总汇

Panel Data Analysis

Experimental Design

威望
1
论坛币
49635 个
通用积分
55.7537
学术水平
370 点
热心指数
273 点
信用等级
335 点
经验
57805 点
帖子
4005
精华
21
在线时间
582 小时
注册时间
2005-5-8
最后登录
2023-11-26

楼主
ReneeBK 发表于 2015-6-6 09:23:38 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币


  • Java Number Cruncher: The Java Programmer's Guide to Numerical Computing
  • By: Ronald Mak

  • Publisher: Prentice Hall

  • Pub. Date: October 29, 2002

  • Print ISBN-10: 0-13-046041-9

  • Print ISBN-13: 978-0-13-046041-7

  • Pages in Print Edition: 480

  • Subscriber Rating: [0 Ratings]



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:crunch Number Java CRU UNC Java 读者

本帖被以下文库推荐

沙发
ReneeBK 发表于 2015-6-6 09:24:53
  1. package numbercruncher.program2_2;

  2. /**
  3. * PROGRAM 2-2: Integer Wrapper Classes
  4. *
  5. * Print the values of some of the constants
  6. * defined in the integer wrapper classes.
  7. */
  8. public class IntegerWrapperClasses
  9. {
  10.     public static void main(String args[])
  11.     {
  12.         // Byte
  13.         System.out.println("Byte.MIN_VALUE = " + Byte.MIN_VALUE);
  14.         System.out.println("Byte.MAX_VALUE = " + Byte.MAX_VALUE);
  15.         System.out.println();

  16.         // Short
  17.         System.out.println("Short.MIN_VALUE = " + Short.MIN_VALUE);
  18.         System.out.println("Short.MAX_VALUE = " + Short.MAX_VALUE);
  19.         System.out.println();

  20.         // Character
  21.         System.out.println("Character.MIN_VALUE = " +
  22.                            (int) Character.MIN_VALUE);
复制代码

  1. Output:

  2. Byte.MIN_VALUE = -128
  3. Byte.MAX_VALUE = 127

  4. Short.MIN_VALUE = -32768
  5. Short.MAX_VALUE = 32767

  6. Character.MIN_VALUE = 0
  7. Character.MAX_VALUE = 65535

  8. Integer.MIN_VALUE = -2147483648
  9. Binary: 10000000000000000000000000000000
  10.    Hex: 80000000

  11. Integer.MAX_VALUE = 2147483647
  12. Binary: 1111111111111111111111111111111
  13.    Hex: 7fffffff

  14. Long.MIN_VALUE = -9223372036854775808
  15. Binary: 1000000000000000000000000000000000000000000000000000000000000000
  16.    Hex: 8000000000000000

  17. Long.MAX_VALUE = 9223372036854775807
  18. Binary: 111111111111111111111111111111111111111111111111111111111111111
  19.    Hex: 7fffffffffffffff
复制代码

藤椅
ReneeBK 发表于 2015-6-6 09:25:51

Listing 2-3a. Class IntPower for doing integer exponentiation.

  1. Listing 2-3a. Class IntPower for doing integer exponentiation.

  2. Code View: Scroll / Show All
  3. package numbercruncher.mathutils;

  4. /**
  5. * Raise a double value to an integer power.
  6. */
  7. public final class IntPower
  8. {
  9.     /**
  10.      * Compute and return x^power.
  11.      * @param x
  12.      * @param power the integer power
  13.      * @return x^power
  14.      */
  15.     public static double raise(double x, int exponent)
  16.     {
  17.         if (exponent < 0) return 1/raise(x, -exponent);

  18.         double power = 1;

  19.         // Loop to compute x^exponent.
  20.         while (exponent > 0) {

  21.             // Is the rightmost exponent bit a 1?
  22.             if ((exponent & 1) == 1) power *= x;
复制代码

板凳
ReneeBK 发表于 2015-6-6 09:27:03
  1. Listing 2-3b. A test program for class IntPower.

  2. Code View: Scroll / Show All
  3. package numbercruncher.program2_3;

  4. import numbercruncher.mathutils.IntPower;

  5. /**
  6. * PROGRAM 2-3: Test Class IntPower
  7. *
  8. * Test the IntPower class.
  9. */
  10. public class TestIntPower
  11. {
  12.     public static .void main(String args[])
  13.     {
  14.         System.out.println(IntPower.raise(2, 5)   + " " +
  15.                            Math.pow(2, 5));
  16.         System.out.println(IntPower.raise(2, -5)  + " " +
  17.                            Math.pow(2, -5));
  18.         System.out.println(IntPower.raise(2, 0)   + " " +
  19.                            Math.pow(2, 0));
  20.         System.out.println(IntPower.raise(2.5, 5) + " " +
  21.                            Math.pow(2.5, 5));
  22.         System.out.println();
  23.         System.out.println(IntPower.raise(-2, 5)   + " " +
  24.                            Math.pow(-2, 5));
  25.         System.out.println(IntPower.raise(-2, -5)  + " " +
  26.                            Math.pow(-2, -5));
  27.         System.out.println(IntPower.raise(-2, 0)   + " " +
  28.                            Math.pow(-2, 0));
  29.         System.out.println(IntPower.raise(-2.5, 5) + " " +
  30.                            Math.pow(-2.5, 5));
  31.     }
  32. }


  33.                                           
复制代码

  1. Output:

  2. 32.0 32.0
  3. 0.03125 0.03125
  4. 1.0 1.0
  5. 97.65625 97.65625

  6. -32.0 -32.0
  7. -0.03125 -0.03125
  8. 1.0 1.0
  9. -97.65625 -97.65625
复制代码

报纸
ReneeBK 发表于 2015-6-6 09:28:16
  1. Listing 4-5a. Kahan's Summation Algorithm for the float type.

  2. Code View: Scroll / Show All
  3. package numbercruncher.mathutils;

  4. /**
  5. * Implement Kahan's Summation Algorithm for the float type.
  6. */
  7. public class KahanSummation
  8. {
  9.     /** the current running sum */       private float sum;
  10.     /** the current correction */        private float correction;
  11.     /** the current corrected addend */  private float correctedAddend;

  12.     /**
  13.      * Constructor.
  14.      */
  15.     public KahanSummation() {}

  16.     /**
  17.      * Return the current corrected value of the running sum.
  18.      * @return the running sum's value
  19.      */
  20.     public float value() { return sum + correction; }

  21.     /**
  22.      * Return the corrected value of the current addend.
  23.      * @return the corrected addend value
复制代码

地板
ReneeBK 发表于 2015-6-6 09:29:04
  1. Listing 4-5b. Fraction sums for n = 100,000,000 by the Kahan Summation Algorithm.

  2. Code View: Scroll / Show All
  3. package numbercruncher.program4_5;

  4. import numbercruncher.mathutils.KahanSummation;
  5. import numbercruncher.mathutils.AlignRight;

  6. /**
  7. * PROGRAM 4-5: Fraction Sum 100M by the Kahan Summation Algorithm
  8. *
  9. * Use the Kahan Summation Algorithm to compute
  10. * the sum 1/d + 2/d + 3/d + ... + n/d = d/d
  11. * where:
  12. *     n = 100,000,000
  13. *     d = 1 + 2 + 3 + ... + n = (n/2)(n + 1)
  14. *
  15. * See if the sum is closer to 1.
  16. */
  17. public class FractionSum100MKahan
  18. {
  19.     private static final int GROUPS = 20;
  20.     private static final int MAX    = 100000000;    // 100M

  21.     public static void main(String args[])
  22.     {
  23.         AlignRight ar = new AlignRight();
复制代码

  1. Output:

  2. Code View: Scroll / Show All
  3.         i     Running sum    % ExpDiff>24
  4. -----------------------------------------
  5.   5000000    0.0025000004               0
  6. 10000000     0.010000001               0
  7. 15000000          0.0225               0
  8. 20000000            0.04               0
  9. 25000000          0.0625               0
  10. 30000000            0.09              26
  11. 35000000          0.1225              12
  12. 40000000            0.16              46
  13. 45000000          0.2025              42
  14. 50000000            0.25              36
  15. 55000000          0.3025              64
  16. 60000000      0.35999998              61
  17. 65000000      0.42249998              58
  18. 70000000      0.48999998              54
  19. 75000000          0.5625              72
  20. 80000000            0.64              73
  21. 85000000      0.72249997              72
  22. 90000000            0.81              70
  23. 95000000          0.9025              68
  24. 100000000             1.0              67

  25. % error = 0.0
复制代码

7
ReneeBK 发表于 2015-6-6 09:30:13
  1. Listing 4-9. Computation of e−19.5 using the Taylor series.

  2. Code View: Scroll / Show All
  3. package numbercruncher.program4_9;

  4. import numbercruncher.mathutils.AlignRight;

  5. /**
  6. * PROGRAM 4-9: e to x
  7. *
  8. * Compute e^x using the Taylor series with x = -19.5
  9. * The final value should be approximately 3.4e-9
  10. */
  11. public class EtoX
  12. {
  13.     private static final double x = -19.5;

  14.     public static void main(String args[])
  15.     {
  16.         AlignRight ar = new AlignRight();

  17.         int    k           = 0;
  18.         double numerator   = 1;
  19.         double denominator = 1;
  20.         double sum         = 1;     // running sum
  21.         double prevSum     = 0;     // previous value of running sum

  22.         ar.print("k", 2);
复制代码

  1. Output:

  2. Code View: Scroll / Show All
  3. k               Numerator
  4.                Denominator                Fraction            Running sum
  5. -------------------------------------------------------------------------
  6. 1                   -19.5
  7.                        1.0                   -19.5                  -18.5
  8. 2                  380.25
  9.                        2.0                 190.125                171.625
  10. 3               -7414.875
  11.                        6.0              -1235.8125             -1064.1875
  12. 4             144590.0625
  13.                       24.0            6024.5859375           4960.3984375
  14. ...
  15. 17   -8.522919630788428E21
  16.           3.55687428096E14   -2.3961824224183973E7  -1.2635486167179534E7
  17. 18   1.6619693280037435E23
  18.          6.402373705728E15     2.595864290953264E7   1.3323156742353106E7
  19. 19     -3.2408401896073E24
  20.        1.21645100408832E17   -2.6641765091362443E7  -1.3318608349009337E7
  21. 20    6.319638369734235E25
  22.        2.43290200817664E18    2.5975720964078385E7   1.2657112615069048E7
  23. ...
  24. 49  -1.6281557854172669E63
  25.       6.082818640342675E62      -2.676646932425302     -0.754026189305919
  26. 50   3.1749037815636704E64
  27.      3.0414093201713376E64      1.0438923036458678     0.2898661143399488
复制代码

8
ReneeBK 发表于 2015-6-6 09:31:21
  1. Listing 4-10. Computation of e−19.5 by inverting the result of the Taylor series at x = +19.5.

  2. Code View: Scroll / Show All
  3. package numbercruncher.program4_10;

  4. import numbercruncher.mathutils.AlignRight;

  5. /**
  6. * PROGRAM 4-10: e to x Inverse
  7. *
  8. * Compute e^x at x = -19.5 by using the Taylor series
  9. * with x = 19.5 and then taking the inverse of the result.
  10. * The final value should be approximately 3.4e-9
  11. */
  12. public class EtoXInverse
  13. {
  14.     private static final double x = -19.5;

  15.     public static void main(String args[])
  16.     {
  17.         AlignRight ar = new AlignRight();

  18.         int    k           = 0;
  19.         double numerator   = 1;
  20.         double denominator = 1;
  21.         double sum         = 1;     // running sum
  22.         double prevSum     = 0;     // previous value of running sum
  23.         double xInverse    = -x;
复制代码

  1. Output:

  2. Code View: Scroll / Show All
  3. k               Numerator
  4.                Denominator                Fraction            Running sum
  5. -------------------------------------------------------------------------
  6. 1                    19.5
  7.                        1.0                    19.5                   20.5
  8. 2                  380.25
  9.                        2.0                 190.125                210.625
  10. 3                7414.875
  11.                        6.0               1235.8125              1446.4375
  12. 4             144590.0625
  13.                       24.0            6024.5859375           7471.0234375
  14. ...

  15. 63    1.871459856776355E81
  16.        1.98260831540444E87      9.4393826669419E-7   2.9426756604150844E8
  17. 64    3.649346720713892E82
  18.      1.2688693218588417E89     2.87606190633386E-7   2.9426756604150873E8
  19. 65    7.116226105392089E83
  20.       8.247650592082472E90    8.628185719001579E-8    2.942675660415088E8
  21. 66   1.3876640905514574E85
  22.       5.443449390774431E92   2.5492366897050122E-8    2.942675660415088E8

  23. e^-19.5 = 3.3982678194950715E-9
  24. % error = 1.217062127663519E-14
复制代码

9
ReneeBK 发表于 2015-6-6 09:31:56
  1. Listing 4-11. Computation of e−19.5 by splitting the exponent before using the Taylor series.

  2. Code View: Scroll / Show All
  3. package numbercruncher.program4_11;

  4. import numbercruncher.mathutils.IntPower;
  5. import numbercruncher.mathutils.AlignRight;

  6. /**
  7. * PROGRAM 4-11: e to x with Split Exponent
  8. *
  9. * Compute e^x by splitting the exponent x into its whole and
  10. * fraction components before using the Taylor series.
  11. */
  12. public class EtoXSplit
  13. {
  14.     private static final double x = -19.5;

  15.     private static AlignRight ar = new AlignRight();

  16.     public static void main(String args[])
  17.     {

  18.         double result;

  19.         // Split off the whole part of |x|.
  20.         double xAbs   = Math.abs(x);
  21.         int    xWhole = (int) xAbs;
复制代码

10
ReneeBK 发表于 2015-6-6 09:33:16
  1. Listing 5-0d. The abstract base class for the subclasses that implement root-finding algorithms.

  2. Code View: Scroll / Show All
  3. package numbercruncher.mathutils;

  4. /**
  5. * Abstract base class for the root finder classes.
  6. */
  7. public abstract class RootFinder
  8. {
  9.     /** the function whose roots to find */ protected Function function;
  10.     /** iteration counter */                private   int      n;
  11.     /** maximum number of iterations */     private   int      maxIters;

  12.     /**
  13.      * Constructor.
  14.      * @param function the function whose roots to find
  15.      * @param maxIters the maximum number of iterations
  16.      */
  17.     public RootFinder(Function function, int maxIters)
  18.     {
  19.         this.function = function;
  20.         this.maxIters = maxIters;
  21.     }

  22.     /**
  23.      * Check the interval.
  24.      * @param xMin x-coordinate of the left of the interval
复制代码

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
jg-xs1
拉您进交流群
GMT+8, 2026-1-1 10:39