Posts

Showing posts from February, 2017

mathajax

Temperature Conversion between Celsius and Fharenheit

Image
The java code carried out conversion between celsius and Fahrenheit A switch case used to select choice of conversion , C2F (celsius to Fahrenheit) or F2C (Fahrenheit to celsius) and a input temperature value is given to the selected conversion process. Fahrenheit to Celsius Celsius to Fahrenheit This example  shows how to calculate use these temperature conversion formula Given     Fharenheit F = 76 and find celsius C = ?                C  = ( 76 -32)  x  (5/9)                     =  44 x 0.555                C  = 24.442 Given     Celsius C = 24 and find  Fharenheit F =?                F  = (9 x C) / 5   +  32                     =  (9 x 24) / 5  + 32                    =   216 / 5  + 32                   =   43.2   +32                 F  =   75.2 import java.util.Scanner; public class Cel2Fah { public static void main(String[] args) { System.out.println( "Temperature Conversion

Cartesian to Polar & Polar to Cartesian Coordinate

Image
Cartesian / Rectangular to Polar Conversion The java code converts the Cartesian coordinate values (x,y) into polar coordinate values (r,Θ) . The input values for x and y are read from the user using scanner object and these values are converted into corresponding polar coordinate values by following two equations. Polar Coordinate radius Polar Coordinate theta import java.util.Scanner; public class Cartesian2Polar { public static void main(String[] args) { System.out.println( "\nCartesian to Polar Conversion" ); Scanner sc = new Scanner(System.in); System.out.println( "\n Enter x-axis value : " ); int x =sc.nextInt(); System.out.println( "\n Enter y-axis value : " ); int y =sc.nextInt(); double radius = Math.sqrt( Math.pow(x, 2) + Math.pow(y, 2) ); double radiant = Math.atan(y/x); double angle = radiant * (180/Math.P

Vector - magnitude

Image
The java code finds magnitude of a vector which can be 2 Dimension or 3 Dimension or any number of dimension. A java class Vector defined with two member functions to calculate magnitude of a vector in double or integer datatype. As the both member function declared with keyword static,  we can access the member function by class class name.  we do not need to create object to the class. Magnitude of 2D vector Equation Magnitude of N-Dimensional vector Equation Example Calculation This is an example calculation shown below that explains how to find a vector magnitude . A vector,array of elements declared and initialized in java using one dimensional array. int A[] = { 2 ,3 }; // 2D vector A find a magnitude for vector A |A| = sqrt ( A[0]^2 + A[1]^2 ) = sqrt ( 2^2 + 3^2 ); = sqrt ( 4 + 9 ); = sqrt ( 13 ); |A| = 3.605 magnitude

Java 8 Search on Integer Array Dataset using Intstream object

The java program search on dataset using java 8 Instream Arrays based on conditional values The class Data3 defined the following five member function for search on dataset,integer arrays. they are, 1. greater 2. lesser 3. range 4. grtequ (greater than and equal) 5. lerequ(lesser than and equal) and Object of class Data3 is initialized with 20 randomly integers generated from random object with limit range of value [0-1000]. In above all member function, we have used java 8 version of array search by Intstream class in java.util.stream package. greater function The function greater is invoked by object of Data3 with one integer argument and returns list (array) of integer which are greater than given argument value. lesser function The function greater is invoked by object of Data3 with one integer argument and returns list (array) of integer which are lesser than given argument value. ra

Subset on Array of Integers

The java program finds an integer subset by searching on array of integers based on condition and a value. The class Data4 defined the following three member function for search on dataset,integer arrays. they are, 1. greater 2. lesser 3. range and Object of class Data4 is initialized with 20 randomly integers generated from random object with limit range of value [0-1000]. greater function The function greater is invoked by object of Data4 with one integer argument and returns list (array) of integer which are greater than given argument value. lesser function The function greater is invoked by object of Data4 with one integer argument and returns list (array) of integer which are lesser than given argument value. range function The function greater invoked is by object of Data4 with two integer arguments. The second argument is greater than first one. The function returns list of integers which are

Maximum value and Index

The java code find a maximum value and its index from array of data A class Data2 has defined with two member functions named max and maxIndex to find maximum value and its index respectively. A object is created to the class,Data with array of integers which are randomly generated from random object. The random generated integer values limited to 1000. pseudocode of find maximum value Read N integer data set maxvaue = 0 for n=0 to N-1 check data[n] > maxvalue maxvalue = data[n] end for print maxvalue pseudocode of find maximum value index Read N integer data set mindex =0 set maxvaue = 0 for n=0 to N-1 check data[n] > maxvalue maxvalue = data[n] mindex = n end for print mindex package cljavabasics; import java.util.Arrays; import java.util.Random; public class

Minimum value and Index

The java code find a minimum value and its index from array of data A class Data has defined with two member functions named min and minIndex to find minimum value and its index. A object is created to the class Data with array of integers which are randomly generated from random object. The random generated integer values limited to 1000. Data are generated from randomly using java Random class pseudocode of find minimum value Read N integer data set minvaue = MAX for n=0 to N-1 check data[n] < minvalue minvalue = data[n] end for print minvalue pseudocode of find minimum value index Read N integer data set mindex =0 set minvaue = MAX for n=0 to N-1 check data[n] < minvalue minvalue = data[n] mindex = n end for print mindex import java.util.Arrays; import java.util

Chebyshev distance between two points

Image
The java program finds distance between two points using chebyshev distance equation . The points can be a scalar or a vector . 1D distance metric It measures distance between two points by absolute difference between them. Each point has one element. 2-Dimensional distance metric It measures distance between two points (2D vector) by selecting maximum absolute difference on 2D vector element absolute difference. N-Dimensional distance metric It measures distance between two N-Dimensional vector by selecting maximum absolute difference on the two N-D vector element. Example Calculation on 2D vectors This is an example calculation shown below explain how to find the distance between two vectors using Chebyshev distance formula. A vector,array of elements declared and initialized in Java using one dimensional array. int A[] = { 2 ,6 }; // 2D vector A int B[] = { 4,1 }; // 2D vector B max - operators finds greatest val

Metric - Minkowski distance between two points

Image
The java program finds distance between two points using minkowski distance equation . when power is set P=1, minkowski metric results as same as manhattan distance equation and when set P=2, minkowski metric results as same as euclidean distance equation. 1-Dimensional distance It measures the distance between two points . Each point lies on a line and has one element. 2-Dimensional distance It measures the distance between two points. Each point lies on 2D cartesian plane and has 2 elements. N-Dimensional distance It measures the distance between two points and each point has N elements. Example Calculation This is an example calculation shown below explain how to find the distance between two vectors using Minkowski distance formula . A vector,array of elements declared and initialized in java using one dimensional array. int A[] = { 5 ,3 }; // 2D vector A int B[] = { 2,1 }; // 2D vector B int P =3; P th

Metric - Manhattan Distance between two points

Image
The java program finds distance between two points using manhattan distance equation.  The points can be a scalar or vector and the passed to function as arguments can be integer or double datatype. 1D distance between two points It measures distance between two points on a line (1D) by absolute difference between them and the points are scalar value. Two points on 2D cartesian space It measures distance between two points on a plane. The points are vectors and each has two elements. The resulting distance equals sum of the difference of each element on the vectors . Two points on N-Dimensional cartesian space It measures d istance between two points or vectors on N-dimensional space . The points are vectors and each has N elements.The resulting distance equals sum of the difference of each element on the vectors. This is an example calculation shown below explain how to find the distance between two vectors using Manhattan

Distance Metric - Euclidean Distance

Image
The java program finds distance between two points by Euclidean distance metric and the points can be a scalar (single element) or a vector (more than one element). The Euclidean distance between two points is measured based on Pythagoras theorem on right angle triangle. AC 2 = AB 2 + BC 2 AC 2 - area of hypotenous AB 2 – area of base BC 2 – area of perpendicular Euclidean distance= AC = sqrt( AB ^2 +BC ^2 ) Euclidean distance - on 1-D The points x and y are scalar on 1-dimension and each point has one element. It is consider that the points on a measuring scale in case of 1-Dimension. The distance between these two points are measured by the following formula. ID-Euclidean  Euclidean distance - on 2-D The points x and y are vector on 2-dimension and each point has two elements.It is consider that the points on a Cartesian 2-D coordinate graph in case of 2-Di