List of usage examples for java.lang Math cos
@HotSpotIntrinsicCandidate public static double cos(double a)
From source file:MainClass.java
public static void main(String args[]) { double radians = 0.45 * Math.PI / 180; System.out.println("cos = " + Math.cos(radians)); }
From source file:Main.java
public static void main(String[] args) { double x = 45.0; double y = 180.0; // convert them to radians x = Math.toRadians(x);// ww w. j a v a 2 s . co m y = Math.toRadians(y); // calculate their cosine System.out.println("Math.cos(" + x + ")=" + Math.cos(x)); System.out.println("Math.cos(" + y + ")=" + Math.cos(y)); }
From source file:MathTest.java
public static void main(String args[]) { int angles[] = { 0, 30, 45, 60, 90, 180 }; for (int i = 0, n = angles.length; i < n; i++) { double rad = Math.toRadians(angles[i]); System.out.println("Angle: " + angles[i]); System.out.println(" Sine : " + Math.sin(rad)); System.out.println(" Cosine : " + Math.cos(rad)); System.out.println(" Tangent: " + Math.tan(rad)); }//from w w w . j a v a2s . co m }
From source file:MainClass.java
public static void main(String args[]) { System.out.printf("Math.abs( 23.7 ) = %f\n", Math.abs(23.7)); System.out.printf("Math.abs( 0.0 ) = %f\n", Math.abs(0.0)); System.out.printf("Math.abs( -23.7 ) = %f\n", Math.abs(-23.7)); System.out.printf("Math.ceil( 9.2 ) = %f\n", Math.ceil(9.2)); System.out.printf("Math.ceil( -9.8 ) = %f\n", Math.ceil(-9.8)); System.out.printf("Math.cos( 0.0 ) = %f\n", Math.cos(0.0)); System.out.printf("Math.exp( 1.0 ) = %f\n", Math.exp(1.0)); System.out.printf("Math.exp( 2.0 ) = %f\n", Math.exp(2.0)); System.out.printf("Math.floor( 9.2 ) = %f\n", Math.floor(9.2)); System.out.printf("Math.floor( -9.8 ) = %f\n", Math.floor(-9.8)); System.out.printf("Math.log( Math.E ) = %f\n", Math.log(Math.E)); System.out.printf("Math.log( Math.E * Math.E ) = %f\n", Math.log(Math.E * Math.E)); System.out.printf("Math.max( 2.3, 12.7 ) = %f\n", Math.max(2.3, 12.7)); System.out.printf("Math.max( -2.3, -12.7 ) = %f\n", Math.max(-2.3, -12.7)); System.out.printf("Math.min( 2.3, 12.7 ) = %f\n", Math.min(2.3, 12.7)); System.out.printf("Math.min( -2.3, -12.7 ) = %f\n", Math.min(-2.3, -12.7)); System.out.printf("Math.pow( 2.0, 7.0 ) = %f\n", Math.pow(2.0, 7.0)); System.out.printf("Math.pow( 9.0, 0.5 ) = %f\n", Math.pow(9.0, 0.5)); System.out.printf("Math.sin( 0.0 ) = %f\n", Math.sin(0.0)); System.out.printf("Math.sqrt( 900.0 ) = %f\n", Math.sqrt(900.0)); System.out.printf("Math.sqrt( 9.0 ) = %f\n", Math.sqrt(9.0)); System.out.printf("Math.tan( 0.0 ) = %f\n", Math.tan(0.0)); }
From source file:Main.java
public static void main(String[] args) { final int width = 512; final int height = 512; BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR); Graphics g = img.getGraphics(); g.setColor(Color.black);//from w ww . jav a2 s . c o m g.fillRect(0, 0, width, height); g.setColor(Color.white); final double A = 8; final double B = 0.5; final double N = 4; final double scale = 128; final double zoom = 50; final double step = 1 / scale; Point last = null; final Point origin = new Point(width / 2, height / 2); for (double t = 0; t <= 2 * Math.PI; t += step) { final double r = zoom * polarFunction(t, A, B, N); final int x = (int) Math.round(r * Math.cos(t)); final int y = (int) Math.round(r * Math.sin(t)); Point next = new Point(x, y); if (last != null) { g.drawLine(origin.x + last.x, origin.y + last.y, origin.x + next.x, origin.y + next.y); } last = next; } JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(new JLabel(new ImageIcon(img))); frame.pack(); frame.setVisible(true); }
From source file:edu.packt.neuralnet.som.Kohonen1DTest.java
public static void main(String[] args) { RandomNumberGenerator.seed = 0;//from w ww. jav a 2 s . c om int numberOfInputs = 2; int numberOfNeurons = 20; int numberOfPoints = 1000; double[][] rndDataSet = RandomNumberGenerator.GenerateMatrixBetween(numberOfPoints, numberOfInputs, -100.0, 100.0); for (int i = 0; i < numberOfPoints; i++) { rndDataSet[i][0] = i; rndDataSet[i][0] += RandomNumberGenerator.GenerateNext(); rndDataSet[i][1] = Math.cos(i / 100.0) * 1000; rndDataSet[i][1] += RandomNumberGenerator.GenerateNext() * 400; } Kohonen kn1 = new Kohonen(numberOfInputs, numberOfNeurons, new UniformInitialization(0.0, 1000.0), 1); NeuralDataSet neuralDataSet = new NeuralDataSet(rndDataSet, 2); CompetitiveLearning complrn = new CompetitiveLearning(kn1, neuralDataSet, LearningAlgorithm.LearningMode.ONLINE); complrn.show2DData = true; complrn.printTraining = true; complrn.setLearningRate(0.3); complrn.setMaxEpochs(10000); complrn.setReferenceEpoch(3000); try { String[] seriesNames = { "Training Data" }; Paint[] seriesColor = { Color.WHITE }; Chart chart = new Chart("Training", rndDataSet, seriesNames, 0, seriesColor, Chart.SeriesType.DOTS); ChartFrame frame = new ChartFrame("Training", chart.scatterPlot("X", "Y")); frame.pack(); frame.setVisible(true); complrn.setPlot2DFrame(frame); complrn.showPlot2DData(); System.in.read(); complrn.train(); } catch (Exception ne) { } }
From source file:edu.packt.neuralnet.som.Kohonen2DTest.java
public static void main(String[] args) { RandomNumberGenerator.seed = System.currentTimeMillis(); int numberOfInputs = 2; int neuronsGridX = 12; int neuronsGridY = 12; int numberOfPoints = 1000; double[][] rndDataSet; rndDataSet = RandomNumberGenerator.GenerateMatrixGaussian(numberOfPoints, numberOfInputs, 100.0, 1.0); //rndDataSet = RandomNumberGenerator.GenerateMatrixBetween(numberOfPoints, numberOfInputs, 100.0, 110.0); for (int i = 0; i < numberOfPoints; i++) { rndDataSet[i][0] *= Math.sin(i); rndDataSet[i][0] += RandomNumberGenerator.GenerateNext() * 50; rndDataSet[i][1] *= Math.cos(i); rndDataSet[i][1] += RandomNumberGenerator.GenerateNext() * 50; }/*from w w w . j a v a 2s. co m*/ // for (int i=0;i<numberOfPoints;i++){ // rndDataSet[i][0]=i; // rndDataSet[i][0]+=RandomNumberGenerator.GenerateNext(); // rndDataSet[i][1]=Math.cos(i/100.0); // rndDataSet[i][1]+=RandomNumberGenerator.GenerateNext()*5; // } Kohonen kn2 = new Kohonen(numberOfInputs, neuronsGridX, neuronsGridY, new GaussianInitialization(500.0, 20.0)); NeuralDataSet neuralDataSet = new NeuralDataSet(rndDataSet, 2); CompetitiveLearning complrn = new CompetitiveLearning(kn2, neuralDataSet, LearningAlgorithm.LearningMode.ONLINE); complrn.show2DData = true; complrn.printTraining = true; complrn.setLearningRate(0.5); complrn.setMaxEpochs(1000); complrn.setReferenceEpoch(300); complrn.sleep = -1; try { String[] seriesNames = { "Training Data" }; Paint[] seriesColor = { Color.WHITE }; Chart chart = new Chart("Training", rndDataSet, seriesNames, 0, seriesColor, Chart.SeriesType.DOTS); ChartFrame frame = new ChartFrame("Training", chart.scatterPlot("X", "Y")); frame.pack(); frame.setVisible(true); // //System.in.read(); complrn.setPlot2DFrame(frame); complrn.showPlot2DData(); //System.in.read(); complrn.train(); } catch (Exception ne) { } }
From source file:TrigonometricDemo.java
public static void main(String[] args) { double degrees = 45.0; double radians = Math.toRadians(degrees); System.out.format("The value of pi is %.4f%n", Math.PI); System.out.format("The sine of %.1f degrees is %.4f%n", degrees, Math.sin(radians)); System.out.format("The cosine of %.1f degrees is %.4f%n", degrees, Math.cos(radians)); System.out.format("The tangent of %.1f degrees is %.4f%n", degrees, Math.tan(radians)); System.out.format("The arcsine of %.4f is %.4f degrees %n", Math.sin(radians), Math.toDegrees(Math.asin(Math.sin(radians)))); System.out.format("The arccosine of %.4f is %.4f degrees %n", Math.cos(radians), Math.toDegrees(Math.acos(Math.cos(radians)))); System.out.format("The arctangent of %.4f is %.4f degrees %n", Math.tan(radians), Math.toDegrees(Math.atan(Math.tan(radians)))); }
From source file:Rotate45Degrees.java
public static void main(String[] args) { final Display display = new Display(); final Image image = new Image(display, 110, 60); GC gc = new GC(image); Font font = new Font(display, "Times", 30, SWT.BOLD); gc.setFont(font);/*from www.ja va 2 s. c o m*/ gc.setBackground(display.getSystemColor(SWT.COLOR_RED)); gc.fillRectangle(0, 0, 110, 60); gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); gc.drawText("SWT", 10, 10, true); font.dispose(); gc.dispose(); final Rectangle rect = image.getBounds(); Shell shell = new Shell(display); shell.setText("Matrix Tranformations"); shell.setLayout(new FillLayout()); final Canvas canvas = new Canvas(shell, SWT.DOUBLE_BUFFERED); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { GC gc = e.gc; gc.setAdvanced(true); if (!gc.getAdvanced()) { gc.drawText("Advanced graphics not supported", 30, 30, true); return; } // Original image int x = 30, y = 30; gc.drawImage(image, x, y); x += rect.width + 30; Transform transform = new Transform(display); // Rotate by 45 degrees //float cos45 = (float)Math.cos(45); float cos45 = (float) Math.cos(Math.PI / 4); //float sin45 = (float)Math.sin(45); float sin45 = (float) Math.sin(Math.PI / 4); transform.setElements(cos45, sin45, -sin45, cos45, 0, 0); gc.setTransform(transform); gc.drawImage(image, 350, 100); transform.dispose(); } }); shell.setSize(350, 550); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } image.dispose(); display.dispose(); }
From source file:TrigonometricDemo.java
public static void main(String[] args) { double degrees = 45.0; double radians = Math.toRadians(degrees); System.out.println("The value of pi is " + Math.PI); System.out.println("The sine of " + degrees + " is " + Math.sin(radians)); System.out.println("The cosine of " + degrees + " is " + Math.cos(radians)); System.out.println("The tangent of " + degrees + " is " + Math.tan(radians)); System.out.println("The arc sine of " + Math.sin(radians) + " is " + Math.toDegrees(Math.asin(Math.sin(radians))) + " degrees"); System.out.println("The arc cosine of " + Math.cos(radians) + " is " + Math.toDegrees(Math.acos(Math.cos(radians))) + " degrees"); System.out.println("The arc tangent of " + Math.tan(radians) + " is " + Math.toDegrees(Math.atan(Math.tan(radians))) + " degrees"); }