Posts

Showing posts from November, 2017

Matrix အသံုးျပဳ နည္း

Image
Matrix အသံုးျပဳ နည္း ========= 1. matrix အျဖစ္ two dimensional array ေတြကို သံုးပါ။ ဥပမာ 1 3 5 2 4 6 0 9 8 ဆိုတဲ့ matrix အတြက္ ဒီလို လုပ္ပါ။ int[][] matrix1=new int[3][3]; matrix1[0][0]=1; matrix1[0][1]=3; matrix1[0][2]=5; matrix1[1][0]=2; matrix1[1][1]=4; matrix1[1][2]=6; matrix1[2][0]=0; matrix1[2][1]=9; matrix1[2][2]=8; အလားတူပဲ int[][] matrix2=new int[3][3]; int[][] matrix3=new int[3][3]; ======= 2. matrix3=matrix1+matrix2 အတြက္ for(int row=0; row♥; row++) { for(int col=0; col♥; col++) { matrix3[row][col] = matrix1[row][col] + matrix2[row][col]; } } ======= 3. matrix3=matrix1-matrix2 အတြက္ for(int row=0; row♥; row++) { for(int col=0; col♥; col++) { matrix3[row][col] = matrix1[row][col] - matrix2[row][col]; } } ======= 4. matrix3=matrix1* matrix2 အတြက္ for(int row=0; row♥; row++) { for(int col=0; col♥; col++) { matrix3[row][col] = matrix1[row][col] * matrix2[row][col]; } } ======= 5. matrix3=

String တခုရဲ့ permutation ကို ရွာေပးတဲ့ class

Image
String တခုရဲ့ permutation ကို ရွာေပးတဲ့ class ========= # permutation String တခု၊ ဥပမာ "ABCD" ကို ထည့္ေပးလိုက္ရင္ သူ႔ရဲ့ permutation အတြဲေတြကို ရွာၿပီး Set<String> အျဖစ္ ျပန္ေပးပါတယ္။ ========= public class Permutation{ public static Set<String> find(String str) { Set<String> perm = new HashSet<String>(); //Handling error scenarios if (str == null) { return null; } else if (str.length() == 0) { perm.add(""); return perm; } char initial = str.charAt(0); // first character String rem = str.substring(1); // Full string without first character Set<String> words = permutationFinder(rem); for (String strNew : words) { for (int i = 0;i<=strNew.length();i++){ perm.add(charInsert(strNew, initial, i)); } } return perm; } private static Strin

Matrix multiplication အတြက္ algorithm

Image
Matrix multiplication အတြက္ algorithm ========== # matrix Matrix ၂ခု ျဖစ္တဲ့ A နဲ႔ B က row, column N-by-N ရွိတယ္ ဆိုပါစို႔။ ဒါဆိုရင္ A နဲ႔ B ရဲ့ ေျမွာက္လဒ္ Matrix C ကို ရွာဖို႔ ေအာက္က နည္းလမ္းကို သံုးပါ။ (C=AB) ======== for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) for (int k = 0; k < N; k++) C[i][j] += A[i][k] * B[k][j]; ========

Variable ၂ခုပါ equation ကို ေျဖရွင္းနည္း

Image
Variable ၂ခုပါ equation ကို ေျဖရွင္းနည္း ============ ax + y = c x + by = d (a, b, c, d, x, y ေတြဟာ double value ေတြျဖစ္ပါတယ္။ ) နည္းလမ္း (1) ========== double y1 = (d - c/a) / (b - 1/a); double x1 = (c - y1) / a; နည္းလမ္း (2) ========== double y2 = (c - a*d) / (1 - a*b); double x2 = d - b*y2; ==========

Apache Commons Math library အသံုးျပဳ ျခင္း (1)

Image
Apache Commons Math library အသံုးျပဳ ျခင္း (1) ============== Apache Commons Math library က သခ်ၤာဆိုင္ရာ တြက္ခ်က္မႈေတြ လုပ္ႏိုင္ေအာင္ ဖန္တီးထားတဲ့ဟာ ျဖစ္ပါတယ္။ AIDE မွာ ဒီ lib add ဖို႔ ေအာက္ကအတိုင္း လုပ္ပါ။ ၁။ AIDE Project အသစ္တခု စလိုက္ပါ။ ၂။ build.gradle dependencies မွာ ဒါျဖည့္ပါ။ compile 'org.apache.commons:commons-math3:3.6.1' ၃။ Internet ဖြင့္ၿပီး save လုပ္လိုက္ရင္ lib ကို download ခ်ပါလိမ့္မယ္။ ၿပီးရင္ ဒီ lib ကို သံုးႏိုင္ပါၿပီ။ ========= Apache Commons Math မွာ ပါတဲ့ package ေတြကို ေအာက္မွာ ျပထားပါတယ္။ ကိုယ့္တြက္ခ်က္မႈအတြက္ လိုအပ္မဲ့ package ကို import လုပ္ၿပီး သံုးရပါမယ္။ org.apache.commons.math3.stat – statistics and statistical tests org.apache.commons.math3.distribution – probability distributions org.apache.commons.math3.random – random numbers, strings and data generation org.apache.commons.math3.analysis – root finding, integration, interpolation, polynomials, etc. org.apache.commons.math3.linear – matrices, solving linear systems

Apache Commons Math library အသံုးျပဳ ျခင္း (2)

Image
Apache Commons Math library အသံုးျပဳ ျခင္း (2) ============== သုေတသန (Research)၊ စာရင္းအင္း (Statistics) ဆိုင္ရာ တြက္ခ်က္မႈမ်ား ျပဳလုပ္ျခင္း ============== Statistics ဆိုင္ရာ တြက္ခ်က္မႈေတြ ျပဳလုပ္ဖို႔ org.apache.commons.math3.stat package ကို import လုပ္ၿပီး သံုးရပါမယ္။ import org.apache.commons.math3.stat; Mean, Standard Deviation, စတာေတြ တြက္ဖို႔ DescriptiveStatistics object ကို သံုးရပါမယ္။ အရင္ဆံုး data ေတြကို array တခုနဲ႔ ရယူထားပါ။ double[] values = new double[] {65, 51 , 16, 11 , 6519, 191 ,0 , 98, 19854, 1, 32}; ၿပီးရင္ DescriptiveStatistics object တခု ဖန္တီးပါ။ DescriptiveStatistics descriptiveStatistics = new DescriptiveStatistics(); array ထဲက data ေတြကို DescriptiveStatistics object ထဲကို for loop နဲ႔ ပတ္ၿပီး ထည့္ပါ။ for (double v : values) { descriptiveStatistics.addValue(v); } ၿပီးရင္ေတာ့ Stats ဆိုင္ရာ တြက္ခ်က္မႈ ရလဒ္ေတြကို DescriptiveStatistics object ကေန ထုတ္ယူႏိုင္ပါၿပီ။ Mean ရယူဖို႔ double mean = descriptiveStatistics.getMean(); Median ရယ

ဒသမကိန္း (double) တခုကို ဒသမ ေနရာ ဘယ္ႏွစ္လံုးနဲ႔ အနီးဆံုး round တန္ဖိုး ျဖတ္ယူခ်င္ပါတယ္ ဆိုတာမ်ိဳး သံုးဖို႔ method တခု ေရးေပးလိုက္ပါတယ္။

ဒသမကိန္း (double) တခုကို ဒသမ ေနရာ ဘယ္ႏွစ္လံုးနဲ႔ အနီးဆံုး round တန္ဖိုး ျဖတ္ယူခ်င္ပါတယ္ ဆိုတာမ်ိဳး သံုးဖို႔ method တခု ေရးေပးလိုက္ပါတယ္။ ======== public double Round(double num, int decimalPlaces) { double shift = Math.pow(10.0D, decimalPlaces); return (Math.round(num * shift) / shift); } ======== ဥပမာ double mynum=Round(3.14159,3); ဆိုရင္ 3.142 ရပါမယ္။ https://www.facebook.com/groups/185208038700073/

double value တခုကို int ေျပာင္းခ်င္ရင္

double value တခုကို int ေျပာင္းခ်င္ရင္ ========== (int)Math.floor(your_num); 5.779 ဆိုရင္ 5 ရပါမယ္။ (int)Math.ceil(your_num); 5.112 ဆိုရင္ 6 ရပါမယ္။ (int)Math.round(your_num); 5.779 ဆိုရင္ 6 ရပါမယ္။ https://www.facebook.com/groups/185208038700073/

သခ်ၤာ တြက္ခ်က္မႈ ဆိုင္ရာ နည္းလမ္းမ်ား

သခ်ၤာ တြက္ခ်က္မႈ ဆိုင္ရာ နည္းလမ္းမ်ား ===================== ရလာမဲ့ အေျဖေတြရဲ့ data type ကို // comment နဲ႔ ေရးေပးထားပါတယ္။ ၁။ Absolute number ရယူျခင္း double result=Math.abs(double num); double result=Math.abs(-4.5);//result=4.5 double result=Math.abs(int num); double result=Math.abs(-4);//result=4 ၂။ ကိန္း ၂ခုမွာ ပိုႀကီးေသာ ကိန္း ရယူနည္း Math.max(double Number1, double Number2);//double Math.max(int Number1, int Number2);//int ၃။ ကိန္း ၂ခုမွာ ပိုငယ္ေသာ ကိန္း ရယူနည္း Math.min(double Number1, double Number2);//double Math.min(int Number1, int Number2);//int ၄။ Radian ျဖင့္ sine တန္ဖိုး ရယူနည္း Math.sin(double Radians);//double ၅။ Degree ျဖင့္ sine တန္ဖိုး ရယူနည္း double Degrees; Math.sin(Degrees / 180.0D * 3.1415926535897931D);//double ၆။ Radian ျဖင့္ cosine တန္ဖိုး ရယူနည္း Math.cos(double Radians);//double ၇။ Degree ျဖင့္ cosine တန္ဖိုး ရယူနည္း double Degrees; Math.cos(Degrees / 180.0D * 3.1415926535897931D);//double ၈။ Radian ျဖင့္ tangent တန