Apache Commons Math Library simple and practical

Source: Internet
Author: User

Packagetest.ffm83.commons.math;importorg.apache.commons.math3.linear.array2drowrealmatrix; Import org.apache.commons.math3.linear.LUDecomposition; Importorg.apache.commons.math3.linear.RealMatrix; Importorg.apache.commons.math3.stat.descriptive.moment.GeometricMean; Importorg.apache.commons.math3.stat.descriptive.moment.Kurtosis; Importorg.apache.commons.math3.stat.descriptive.moment.Mean; importorg.apache.commons.math3.stat.descriptive.moment.Skewness; Importorg.apache.commons.math3.stat.descriptive.moment.StandardDeviation; Importorg.apache.commons.math3.stat.descriptive.moment.Variance; Import Org.apache.commons.math3.stat.descriptive.rank.Max; Importorg.apache.commons.math3.stat.descriptive.rank.Min; Importorg.apache.commons.math3.stat.descriptive.rank.Percentile; Importorg.apache.commons.math3.stat.descriptive.summary.Product; Importorg.apache.commons.math3.stat.descriptive.summary.Sum;  Importorg.apache.commons.math3.stat.descriptive.summary.SumOfSquares;/** * Easy to use Commons Math method * @author Fan Fangming*/ Public classMathusage { Public Static voidMain (string[] args) {Double[] values =New Double[] {0.33,1.33,0.27333,0.3,0.501,                 0.444,0.44,0.34496,0.33,0.3,0.292,0.667 }; Min min=NewMin (); Max Max=NewMax (); Mean Mean=NewMean ();//arithmetic mean valueProduct Product =NewProduct ();//ProductSum sum =NewSum (); Variance Variance=NewVariance ();//VarianceSystem. out. println ("min:"+min.evaluate (values)); System. out. println ("Max:"+max.evaluate (values)); System. out. println ("mean:"+mean.evaluate (values)); System. out. println ("Product:"+product.evaluate (values)); System. out. println ("sum:"+sum.evaluate (values)); System. out. println ("Variance:"+variance.evaluate (values)); Percentile percentile= Newpercentile ();//percentile number of percentilesGeometricmean Geomean = Newgeometricmean ();//geometric averages, n-times arithmetic roots of a continuous product of n positive numbers are called the geometric averages of the n numbers .Skewness skewness =NewSkewness ();//skewness ();Kurtosis Kurtosis =NewKurtosis ();//Kurtosis, peak degreeSumofsquares sumofsquares = Newsumofsquares ();//Sum of squaresStandarddeviation standarddeviation =NewStandarddeviation ();//Standard deviationSystem. out. println ("Percentilevalue:"+ Percentile.evaluate (values,80.0)); System. out. println ("Geometricmean:"+geomean.evaluate (values)); System. out. println ("skewness:"+skewness.evaluate (values)); System. out. println ("kurtosis:"+kurtosis.evaluate (values)); System. out. println ("Sumofsquares:"+sumofsquares.evaluate (values)); System. out. println ("standarddeviation:"+standarddeviation.evaluate (values)); System. out. println ("-------------------------------------"); //Create a real matrix with Rowsand three columns        Double[] Matrixdata ={{1d,2d,3d},{2d,5d,3d}}; Realmatrix m=Newarray2drowrealmatrix (Matrixdata); System. out. println (m); //One more with three rows, Twocolumns        Double[] MatrixData2 ={ {1d,2d},{2d,5d}, {1d, 7d}}; Realmatrix N=Newarray2drowrealmatrix (MATRIXDATA2); //Note:the constructor copies the input double[][] array. //Now multiply m by nRealmatrix p =m.multiply (n); System. out. println ("P:"+p); System. out. println (P.getrowdimension ());//2System. out. println (P.getcolumndimension ());//2//Invert p, using LudecompositionRealmatrix Pinverse =newludecomposition (P). Getsolver (). Getinverse (); System. out. println (Pinverse); The result of the operation is as follows: min:0.27333Max:1.33mean:0.46269083333333333Product:2.3429343978460972E-5sum:5.552289999999999Variance:0.08757300031742428 thePercentile value:0.5674000000000001geometric mean:0.4112886050879374skewness:2.670095445623868kurtosis:7.718241303328169Sumofsquares:3.5322966905000004standarddeviation:0.2959273564870681-------------------------------------array2drowrealmatrix{{1.0,2.0,3.0},{2.0,5.0,3.0}}p:array2drowrealmatrix{{8.0,33.0},{15.0,50.0}}22array2drowrealmatrix{{-0.5263157895,0.3473684211},{0.1578947368,-0.0842105263}} 

Apache Commons Math Library simple and practical

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.